Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CalculatorFactory.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Customer\Api\Data\AddressInterface as CustomerAddress;
10 
12 {
16  const CALC_UNIT_BASE = 'UNIT_BASE_CALCULATION';
17 
21  const CALC_ROW_BASE = 'ROW_BASE_CALCULATION';
22 
26  const CALC_TOTAL_BASE = 'TOTAL_BASE_CALCULATION';
27 
31  protected $objectManager;
32 
38  public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
39  {
40  $this->objectManager = $objectManager;
41  }
42 
55  public function create(
56  $type,
57  $storeId,
58  CustomerAddress $billingAddress = null,
59  CustomerAddress $shippingAddress = null,
60  $customerTaxClassId = null,
61  $customerId = null
62  ) {
63  switch ($type) {
65  $className = \Magento\Tax\Model\Calculation\UnitBaseCalculator::class;
66  break;
68  $className = \Magento\Tax\Model\Calculation\RowBaseCalculator::class;
69  break;
71  $className = \Magento\Tax\Model\Calculation\TotalBaseCalculator::class;
72  break;
73  default:
74  throw new \InvalidArgumentException('Unknown calculation type: ' . $type);
75  }
77  $calculator = $this->objectManager->create($className, ['storeId' => $storeId]);
78  if (null != $shippingAddress) {
79  $calculator->setShippingAddress($shippingAddress);
80  }
81  if (null != $billingAddress) {
82  $calculator->setBillingAddress($billingAddress);
83  }
84  if (null != $customerTaxClassId) {
85  $calculator->setCustomerTaxClassId($customerTaxClassId);
86  }
87  if (null != $customerId) {
88  $calculator->setCustomerId($customerId);
89  }
90  return $calculator;
91  }
92 }
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$type
Definition: item.phtml:13
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31