Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Calculation Class Reference
Inheritance diagram for Calculation:
AbstractModel DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, Config $taxConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory $classesFactory, \Magento\Tax\Model\ResourceModel\Calculation $resource, CustomerAccountManagement $customerAccountManagement, CustomerGroupManagement $customerGroupManagement, CustomerGroupRepository $customerGroupRepository, CustomerRepository $customerRepository, PriceCurrencyInterface $priceCurrency, SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder, TaxClassRepositoryInterface $taxClassRepository, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getDefaultCustomerTaxClass ($store=null)
 
 deleteByRuleId ($ruleId)
 
 getRates ($ruleId)
 
 getCustomerTaxClasses ($ruleId)
 
 getProductTaxClasses ($ruleId)
 
 getRate ($request)
 
 getStoreRate ($request, $store=null)
 
 getDefaultRateRequest ($store=null, $customerId=null)
 
 getRateRequest ( $shippingAddress=null, $billingAddress=null, $customerTaxClass=null, $store=null, $customerId=null)
 
 getAppliedRates ($request)
 
 reproduceProcess ($rates)
 
 calcTaxAmount ($price, $taxRate, $priceIncludeTax=false, $round=true)
 
 round ($price)
 
 getTaxRates ($billingAddress, $shippingAddress, $customerTaxClassId)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const CALC_TAX_BEFORE_DISCOUNT_ON_EXCL = '0_0'
 
const CALC_TAX_BEFORE_DISCOUNT_ON_INCL = '0_1'
 
const CALC_TAX_AFTER_DISCOUNT_ON_EXCL = '1_0'
 
const CALC_TAX_AFTER_DISCOUNT_ON_INCL = '1_1'
 
const CALC_UNIT_BASE = 'UNIT_BASE_CALCULATION'
 
const CALC_ROW_BASE = 'ROW_BASE_CALCULATION'
 
const CALC_TOTAL_BASE = 'TOTAL_BASE_CALCULATION'
 

Protected Member Functions

 _construct ()
 
 _formCalculationProcess ()
 
 _getRequestCacheKey ($request)
 
 getRateOriginRequest ($store=null)
 
 _isCrossBorderTradeEnabled ($store=null)
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_rates = []
 
 $_ctc = []
 
 $_ptc = []
 
 $_rateCache = []
 
 $_rateCalculationProcess = []
 
 $_customer
 
 $_defaultCustomerTaxClass
 
 $_scopeConfig
 
 $_storeManager
 
 $_customerSession
 
 $_customerFactory
 
 $_classesFactory
 
 $_config
 
 $customerAccountManagement
 
 $customerGroupManagement
 
 $customerGroupRepository
 
 $customerRepository
 
 $priceCurrency
 
 $filterBuilder
 
 $searchCriteriaBuilder
 
 $taxClassRepository
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Tax Calculation Model @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 27 of file Calculation.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
Config  $taxConfig,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Customer\Model\CustomerFactory  $customerFactory,
\Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory  $classesFactory,
\Magento\Tax\Model\ResourceModel\Calculation  $resource,
CustomerAccountManagement  $customerAccountManagement,
CustomerGroupManagement  $customerGroupManagement,
CustomerGroupRepository  $customerGroupRepository,
CustomerRepository  $customerRepository,
PriceCurrencyInterface  $priceCurrency,
SearchCriteriaBuilder  $searchCriteriaBuilder,
FilterBuilder  $filterBuilder,
TaxClassRepositoryInterface  $taxClassRepository,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
Config$taxConfig
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Customer\Model\Session$customerSession
\Magento\Customer\Model\CustomerFactory$customerFactory
\Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory$classesFactory
\Magento\Tax\Model\ResourceModel\Calculation$resource
CustomerAccountManagement$customerAccountManagement
CustomerGroupManagement$customerGroupManagement
CustomerGroupRepository$customerGroupRepository
CustomerRepository$customerRepository
PriceCurrencyInterface$priceCurrency
SearchCriteriaBuilder$searchCriteriaBuilder
FilterBuilder$filterBuilder
TaxClassRepositoryInterface$taxClassRepository
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 213 of file Calculation.php.

233  {
234  $this->_scopeConfig = $scopeConfig;
235  $this->_config = $taxConfig;
236  $this->_storeManager = $storeManager;
237  $this->_customerSession = $customerSession;
238  $this->_customerFactory = $customerFactory;
239  $this->_classesFactory = $classesFactory;
240  $this->customerAccountManagement = $customerAccountManagement;
241  $this->customerGroupManagement = $customerGroupManagement;
242  $this->customerGroupRepository = $customerGroupRepository;
243  $this->customerRepository = $customerRepository;
244  $this->priceCurrency = $priceCurrency;
245  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
246  $this->filterBuilder = $filterBuilder;
247  $this->taxClassRepository = $taxClassRepository;
248  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
249  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 254 of file Calculation.php.

255  {
256  $this->_init(\Magento\Tax\Model\ResourceModel\Calculation::class);
257  }

◆ _formCalculationProcess()

_formCalculationProcess ( )
protected

Aggregate tax calculation data to array

Returns
array

Definition at line 334 of file Calculation.php.

335  {
336  $title = $this->getRateTitle();
337  $value = $this->getRateValue();
338  $id = $this->getRateId();
339 
340  $rate = ['code' => $title, 'title' => $title, 'percent' => $value, 'position' => 1, 'priority' => 1];
341 
342  $process = [];
343  $process['percent'] = $value;
344  $process['id'] = "{$id}-{$value}";
345  $process['rates'][] = $rate;
346 
347  return [$process];
348  }
$title
Definition: default.phtml:14
$id
Definition: fieldset.phtml:14
$value
Definition: gender.phtml:16

◆ _getRequestCacheKey()

_getRequestCacheKey (   $request)
protected

Get cache key value for specific tax rate request

Parameters
\Magento\Framework\DataObject$request
Returns
string

Definition at line 387 of file Calculation.php.

388  {
389  $store = $request->getStore();
390  $key = '';
391  if ($store instanceof \Magento\Store\Model\Store) {
392  $key = $store->getId() . '|';
393  } elseif (is_numeric($store)) {
394  $key = $store . '|';
395  }
396  $key .= $request->getProductClassId() . '|'
397  . $request->getCustomerClassId() . '|'
398  . $request->getCountryId() . '|'
399  . $request->getRegionId() . '|'
400  . $request->getPostcode();
401  return $key;
402  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ _isCrossBorderTradeEnabled()

_isCrossBorderTradeEnabled (   $store = null)
protected

Return whether cross border trade is enabled or not

Parameters
null | int | string | Store$store
Returns
bool

Definition at line 477 of file Calculation.php.

478  {
479  return (bool)$this->_config->crossBorderTradeEnabled($store);
480  }

◆ calcTaxAmount()

calcTaxAmount (   $price,
  $taxRate,
  $priceIncludeTax = false,
  $round = true 
)

Calculate rated tax amount based on price and tax rate. If you are using price including tax $priceIncludeTax should be true.

Parameters
float$price
float$taxRate
boolean$priceIncludeTax
boolean$round
Returns
float

Definition at line 661 of file Calculation.php.

662  {
663  $taxRate = $taxRate / 100;
664 
665  if ($priceIncludeTax) {
666  $amount = $price * (1 - 1 / (1 + $taxRate));
667  } else {
668  $amount = $price * $taxRate;
669  }
670 
671  if ($round) {
672  return $this->round($amount);
673  }
674 
675  return $amount;
676  }
$price
$amount
Definition: order.php:14
$taxRate
Definition: tax_rule.php:12

◆ deleteByRuleId()

deleteByRuleId (   $ruleId)

Delete calculation settings by rule id

Parameters
int$ruleId
Returns
$this

Definition at line 281 of file Calculation.php.

282  {
283  $this->_getResource()->deleteByRuleId($ruleId);
284  return $this;
285  }

◆ getAppliedRates()

getAppliedRates (   $request)

Get information about tax rates applied to request

Parameters
\Magento\Framework\DataObject$request
Returns
array

Definition at line 627 of file Calculation.php.

628  {
629  if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
630  return [];
631  }
632 
633  $cacheKey = $this->_getRequestCacheKey($request);
634  if (!isset($this->_rateCalculationProcess[$cacheKey])) {
635  $this->_rateCalculationProcess[$cacheKey] = $this->_getResource()->getCalculationProcess($request);
636  }
637  return $this->_rateCalculationProcess[$cacheKey];
638  }

◆ getCustomerTaxClasses()

getCustomerTaxClasses (   $ruleId)

Get allowed customer tax classes by rule id

Parameters
int$ruleId
Returns
array

Definition at line 307 of file Calculation.php.

308  {
309  if (!isset($this->_ctc[$ruleId])) {
310  $this->_ctc[$ruleId] = $this->_getResource()->getCalculationsById('customer_tax_class_id', $ruleId);
311  }
312  return $this->_ctc[$ruleId];
313  }

◆ getDefaultCustomerTaxClass()

getDefaultCustomerTaxClass (   $store = null)

Fetch default customer tax class

Parameters
null | Store | string | int$store
Returns
int

Definition at line 265 of file Calculation.php.

266  {
267  if ($this->_defaultCustomerTaxClass === null) {
268  //Not catching the exception here since default group is expected
269  $defaultCustomerGroup = $this->customerGroupManagement->getDefaultGroup($store);
270  $this->_defaultCustomerTaxClass = $defaultCustomerGroup->getTaxClassId();
271  }
273  }

◆ getDefaultRateRequest()

getDefaultRateRequest (   $store = null,
  $customerId = null 
)

Return the default rate request. It can be either based on store address or customer address

Parameters
null | int | string | Store$store
int$customerId
Returns
\Magento\Framework\DataObject

Definition at line 461 of file Calculation.php.

462  {
463  if ($this->_isCrossBorderTradeEnabled($store)) {
464  //If cross border trade is enabled, we will use customer tax rate as store tax rate
465  return $this->getRateRequest(null, null, null, $store, $customerId);
466  } else {
467  return $this->getRateOriginRequest($store);
468  }
469  }
getRateRequest( $shippingAddress=null, $billingAddress=null, $customerTaxClass=null, $store=null, $customerId=null)
_isCrossBorderTradeEnabled($store=null)

◆ getProductTaxClasses()

getProductTaxClasses (   $ruleId)

Get allowed product tax classes by rule id

Parameters
int$ruleId
Returns
array

Definition at line 321 of file Calculation.php.

322  {
323  if (!isset($this->_ptc[$ruleId])) {
324  $this->_ptc[$ruleId] = $this->getResource()->getCalculationsById('product_tax_class_id', $ruleId);
325  }
326  return $this->_ptc[$ruleId];
327  }

◆ getRate()

getRate (   $request)

Get calculation tax rate by specific request

Parameters
\Magento\Framework\DataObject$request
Returns
float

Definition at line 356 of file Calculation.php.

357  {
358  if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
359  return 0;
360  }
361 
362  $cacheKey = $this->_getRequestCacheKey($request);
363  if (!isset($this->_rateCache[$cacheKey])) {
364  $this->unsRateValue();
365  $this->unsCalculationProcess();
366  $this->unsEventModuleId();
367  $this->_eventManager->dispatch('tax_rate_data_fetch', ['request' => $request, 'sender' => $this]);
368  if (!$this->hasRateValue()) {
369  $rateInfo = $this->_getResource()->getRateInfo($request);
370  $this->setCalculationProcess($rateInfo['process']);
371  $this->setRateValue($rateInfo['value']);
372  } else {
373  $this->setCalculationProcess($this->_formCalculationProcess());
374  }
375  $this->_rateCache[$cacheKey] = $this->getRateValue();
376  $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
377  }
378  return $this->_rateCache[$cacheKey];
379  }

◆ getRateOriginRequest()

getRateOriginRequest (   $store = null)
protected

Get request object for getting tax rate based on store shipping original address

Parameters
null | string | bool | int | Store$store
Returns
\Magento\Framework\DataObject

Definition at line 425 of file Calculation.php.

426  {
427  $request = new \Magento\Framework\DataObject();
428  $request->setCountryId(
429  $this->_scopeConfig->getValue(
430  \Magento\Shipping\Model\Config::XML_PATH_ORIGIN_COUNTRY_ID,
432  $store
433  )
434  )->setRegionId(
435  $this->_scopeConfig->getValue(
436  \Magento\Shipping\Model\Config::XML_PATH_ORIGIN_REGION_ID,
438  $store
439  )
440  )->setPostcode(
441  $this->_scopeConfig->getValue(
442  \Magento\Shipping\Model\Config::XML_PATH_ORIGIN_POSTCODE,
444  $store
445  )
446  )->setCustomerClassId(
448  )->setStore(
449  $store
450  );
451  return $request;
452  }
getDefaultCustomerTaxClass($store=null)

◆ getRateRequest()

getRateRequest (   $shippingAddress = null,
  $billingAddress = null,
  $customerTaxClass = null,
  $store = null,
  $customerId = null 
)

Get request object with information necessary for getting tax rate

Request object contain: country_id (->getCountryId()) region_id (->getRegionId()) postcode (->getPostcode()) customer_class_id (->getCustomerClassId()) store (->getStore())

Parameters
null | bool | \Magento\Framework\DataObject | CustomerAddress$shippingAddress
null | bool | \Magento\Framework\DataObject | CustomerAddress$billingAddress
null | int$customerTaxClass
null | int | \Magento\Store\Model\Store$store
int$customerId
Returns
\Magento\Framework\DataObject @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 502 of file Calculation.php.

508  {
509  if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
510  return $this->getRateOriginRequest($store);
511  }
512  $address = new \Magento\Framework\DataObject();
513  $basedOn = $this->_scopeConfig->getValue(
516  $store
517  );
518 
519  if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing'
520  ) {
521  $basedOn = 'default';
522  } else {
523  if (($billingAddress === null || !$billingAddress->getCountryId())
524  && $basedOn == 'billing'
525  || ($shippingAddress === null || !$shippingAddress->getCountryId())
526  && $basedOn == 'shipping'
527  ) {
528  if ($customerId) {
529  //fallback to default address for registered customer
530  try {
531  $defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId);
532  } catch (NoSuchEntityException $e) {
533  }
534 
535  try {
536  $defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId);
537  } catch (NoSuchEntityException $e) {
538  }
539 
540  if ($basedOn == 'billing' && isset($defaultBilling) && $defaultBilling->getCountryId()) {
541  $billingAddress = $defaultBilling;
542  } elseif ($basedOn == 'shipping' && isset($defaultShipping) && $defaultShipping->getCountryId()) {
543  $shippingAddress = $defaultShipping;
544  } else {
545  $basedOn = 'default';
546  }
547  } else {
548  //fallback for guest
549  if ($basedOn == 'billing' && is_object($shippingAddress) && $shippingAddress->getCountryId()) {
551  } elseif ($basedOn == 'shipping' && is_object($billingAddress) && $billingAddress->getCountryId()) {
553  } else {
554  $basedOn = 'default';
555  }
556  }
557  }
558  }
559 
560  switch ($basedOn) {
561  case 'billing':
563  break;
564  case 'shipping':
566  break;
567  case 'origin':
569  break;
570  case 'default':
571  $address->setCountryId(
572  $this->_scopeConfig->getValue(
575  $store
576  )
577  )->setRegionId(
578  $this->_scopeConfig->getValue(
581  $store
582  )
583  )->setPostcode(
584  $this->_scopeConfig->getValue(
587  $store
588  )
589  );
590  break;
591  default:
592  break;
593  }
594 
595  if ($customerTaxClass === null || $customerTaxClass === false) {
596  if ($customerId) {
597  $customerData = $this->customerRepository->getById($customerId);
598  $customerTaxClass = $this->customerGroupRepository
599  ->getById($customerData->getGroupId())
600  ->getTaxClassId();
601  } else {
602  $customerTaxClass = $this->customerGroupManagement->getNotLoggedInGroup()->getTaxClassId();
603  }
604  }
605 
606  $request = new \Magento\Framework\DataObject();
607  //TODO: Address is not completely refactored to use Data objects
608  if ($address->getRegion() instanceof AddressRegion) {
609  $regionId = $address->getRegion()->getRegionId();
610  } else {
611  $regionId = $address->getRegionId();
612  }
613  $request->setCountryId($address->getCountryId())
614  ->setRegionId($regionId)
615  ->setPostcode($address->getPostcode())
616  ->setStore($store)
617  ->setCustomerClassId($customerTaxClass);
618  return $request;
619  }
$customerData
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$billingAddress
Definition: order.php:25
const CONFIG_XML_PATH_DEFAULT_POSTCODE
Definition: Config.php:55
const CONFIG_XML_PATH_DEFAULT_REGION
Definition: Config.php:53
$shippingAddress
Definition: order.php:40
$address
Definition: customer.php:38
$customerTaxClass
Definition: tax_rule.php:9
const CONFIG_XML_PATH_DEFAULT_COUNTRY
Definition: Config.php:51
const CONFIG_XML_PATH_BASED_ON
Definition: Config.php:38

◆ getRates()

getRates (   $ruleId)

Get calculation rates by rule id

Parameters
int$ruleId
Returns
array

Definition at line 293 of file Calculation.php.

294  {
295  if (!isset($this->_rates[$ruleId])) {
296  $this->_rates[$ruleId] = $this->_getResource()->getCalculationsById('tax_calculation_rate_id', $ruleId);
297  }
298  return $this->_rates[$ruleId];
299  }

◆ getStoreRate()

getStoreRate (   $request,
  $store = null 
)

Get tax rate based on store shipping origin address settings This rate can be used for conversion store price including tax to store price excluding tax

Parameters
\Magento\Framework\DataObject$request
null | string | bool | int | Store$store
Returns
float

Definition at line 413 of file Calculation.php.

414  {
415  $storeRequest = $this->getRateOriginRequest($store)->setProductClassId($request->getProductClassId());
416  return $this->getRate($storeRequest);
417  }

◆ getTaxRates()

getTaxRates (   $billingAddress,
  $shippingAddress,
  $customerTaxClassId 
)
Parameters
array$billingAddress
array$shippingAddress
int$customerTaxClassId
Returns
array

Definition at line 695 of file Calculation.php.

696  {
697  $billingAddressObj = null;
698  $shippingAddressObj = null;
699  if (!empty($billingAddress)) {
700  $billingAddressObj = new \Magento\Framework\DataObject($billingAddress);
701  }
702  if (!empty($shippingAddress)) {
703  $shippingAddressObj = new \Magento\Framework\DataObject($shippingAddress);
704  }
705  $rateRequest = $this->getRateRequest($shippingAddressObj, $billingAddressObj, $customerTaxClassId);
706 
707  $searchCriteria = $this->searchCriteriaBuilder->addFilters(
708  [$this->filterBuilder->setField(ClassModel::KEY_TYPE)
710  ->create()]
711  )->create();
712  $ids = $this->taxClassRepository->getList($searchCriteria)->getItems();
713 
714  $productRates = [];
715  $idKeys = array_keys($ids);
716  foreach ($idKeys as $idKey) {
717  $rateRequest->setProductClassId($idKey);
718  $rate = $this->getRate($rateRequest);
719  $productRates[$idKey] = $rate;
720  }
721  return $productRates;
722  }
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$searchCriteria
getRateRequest( $shippingAddress=null, $billingAddress=null, $customerTaxClass=null, $store=null, $customerId=null)

◆ reproduceProcess()

reproduceProcess (   $rates)

Gets the calculation process

Parameters
array$rates
Returns
array

Definition at line 646 of file Calculation.php.

647  {
648  return $this->getResource()->getCalculationProcess(null, $rates);
649  }
$rates
Definition: tax.phtml:35

◆ round()

round (   $price)

Round tax amount

Parameters
float$price
Returns
float

Definition at line 684 of file Calculation.php.

685  {
686  return $this->priceCurrency->round($price);
687  }
$price

Field Documentation

◆ $_classesFactory

$_classesFactory
protected

Definition at line 136 of file Calculation.php.

◆ $_config

$_config
protected

Definition at line 143 of file Calculation.php.

◆ $_ctc

$_ctc = []
protected

Definition at line 76 of file Calculation.php.

◆ $_customer

$_customer
protected

Definition at line 104 of file Calculation.php.

◆ $_customerFactory

$_customerFactory
protected

Definition at line 131 of file Calculation.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 126 of file Calculation.php.

◆ $_defaultCustomerTaxClass

$_defaultCustomerTaxClass
protected

Definition at line 109 of file Calculation.php.

◆ $_ptc

$_ptc = []
protected

Definition at line 83 of file Calculation.php.

◆ $_rateCache

$_rateCache = []
protected

Definition at line 90 of file Calculation.php.

◆ $_rateCalculationProcess

$_rateCalculationProcess = []
protected

Definition at line 97 of file Calculation.php.

◆ $_rates

$_rates = []
protected

Definition at line 69 of file Calculation.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 116 of file Calculation.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 121 of file Calculation.php.

◆ $customerAccountManagement

$customerAccountManagement
protected

Definition at line 148 of file Calculation.php.

◆ $customerGroupManagement

$customerGroupManagement
protected

Definition at line 153 of file Calculation.php.

◆ $customerGroupRepository

$customerGroupRepository
protected

Definition at line 158 of file Calculation.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 163 of file Calculation.php.

◆ $filterBuilder

$filterBuilder
protected

Definition at line 175 of file Calculation.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 168 of file Calculation.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 182 of file Calculation.php.

◆ $taxClassRepository

$taxClassRepository
protected

Definition at line 189 of file Calculation.php.

◆ CALC_ROW_BASE

const CALC_ROW_BASE = 'ROW_BASE_CALCULATION'

Identifier constant for row based calculation

Definition at line 57 of file Calculation.php.

◆ CALC_TAX_AFTER_DISCOUNT_ON_EXCL

const CALC_TAX_AFTER_DISCOUNT_ON_EXCL = '1_0'

Identifier constant for Tax calculation after discount excluding TAX

Definition at line 42 of file Calculation.php.

◆ CALC_TAX_AFTER_DISCOUNT_ON_INCL

const CALC_TAX_AFTER_DISCOUNT_ON_INCL = '1_1'

Identifier constant for Tax calculation after discount including TAX

Definition at line 47 of file Calculation.php.

◆ CALC_TAX_BEFORE_DISCOUNT_ON_EXCL

const CALC_TAX_BEFORE_DISCOUNT_ON_EXCL = '0_0'

Identifier constant for Tax calculation before discount excluding TAX

Definition at line 32 of file Calculation.php.

◆ CALC_TAX_BEFORE_DISCOUNT_ON_INCL

const CALC_TAX_BEFORE_DISCOUNT_ON_INCL = '0_1'

Identifier constant for Tax calculation before discount including TAX

Definition at line 37 of file Calculation.php.

◆ CALC_TOTAL_BASE

const CALC_TOTAL_BASE = 'TOTAL_BASE_CALCULATION'

Identifier constant for total based calculation

Definition at line 62 of file Calculation.php.

◆ CALC_UNIT_BASE

const CALC_UNIT_BASE = 'UNIT_BASE_CALCULATION'

Identifier constant for unit based calculation

Definition at line 52 of file Calculation.php.


The documentation for this class was generated from the following file: