13 use Magento\Tax\Api\Data\TaxDetailsInterfaceFactory;
14 use Magento\Tax\Api\Data\TaxDetailsItemInterfaceFactory;
80 private $parentToChildren;
121 $this->calculationTool = $calculation;
135 \
Magento\Tax\Api\Data\QuoteDetailsInterface $quoteDetails,
140 $storeId = $this->storeManager->getStore()->getStoreId();
151 $items = $quoteDetails->getItems();
153 return $this->taxDetailsDataObjectFactory->create()
156 ->setDiscountTaxCompensationAmount(0.0)
157 ->setAppliedTaxes([])
160 $this->computeRelationships(
$items);
162 $calculator = $this->calculatorFactory->create(
163 $this->config->getAlgorithm(
$storeId),
165 $quoteDetails->getBillingAddress(),
166 $quoteDetails->getShippingAddress(),
167 $this->taxClassManagement->getTaxClassId($quoteDetails->getCustomerTaxClassKey(),
'customer'),
168 $quoteDetails->getCustomerId()
171 $processedItems = [];
173 foreach ($this->keyedItems as
$item) {
174 if (isset($this->parentToChildren[
$item->getCode()])) {
175 $processedChildren = [];
176 foreach ($this->parentToChildren[
$item->getCode()] as $child) {
177 $processedItem = $this->
processItem($child, $calculator, $round);
179 $processedItems[$processedItem->getCode()] = $processedItem;
180 $processedChildren[] = $processedItem;
183 $processedItem->setCode(
$item->getCode());
184 $processedItem->setType(
$item->getType());
186 $processedItem = $this->
processItem($item, $calculator, $round);
189 $processedItems[$processedItem->getCode()] = $processedItem;
192 $taxDetailsDataObject = $this->taxDetailsDataObjectFactory->create();
193 $this->dataObjectHelper->populateWithArray(
194 $taxDetailsDataObject,
196 \
Magento\Tax\Api\Data\TaxDetailsInterface::class
198 $taxDetailsDataObject->setItems($processedItems);
199 return $taxDetailsDataObject;
240 $storeId = $this->storeManager->getStore()->getStoreId();
243 $addressRequestObject = $this->calculationTool->getRateRequest(
null,
null,
null,
$storeId,
$customerId);
245 $addressRequestObject = $this->calculationTool->getDefaultRateRequest(
$storeId,
$customerId);
247 $addressRequestObject->setProductClassId($productTaxClassID);
248 return $this->calculationTool->getRate($addressRequestObject);
257 private function computeRelationships(
$items)
259 $this->keyedItems = [];
260 $this->parentToChildren = [];
262 if (
$item->getParentCode() ===
null) {
265 $this->parentToChildren[
$item->getParentCode()][] =
$item;
297 $rowTotalInclTax = 0.00;
299 $taxableAmount = 0.00;
302 $rowTotal += $child->getRowTotal();
303 $rowTotalInclTax += $child->getRowTotalInclTax();
304 $rowTax += $child->getRowTax();
305 $taxableAmount += $child->getTaxableAmount();
308 $price = $this->calculationTool->round($rowTotal / $quantity);
309 $priceInclTax = $this->calculationTool->round($rowTotalInclTax / $quantity);
311 $taxDetailsItemDataObject = $this->taxDetailsItemDataObjectFactory->create()
313 ->setPriceInclTax($priceInclTax)
314 ->setRowTotal($rowTotal)
315 ->setRowTotalInclTax($rowTotalInclTax)
316 ->setRowTax($rowTax);
318 return $taxDetailsItemDataObject;
338 +
$item->getDiscountTaxCompensationAmount();
340 $itemAppliedTaxes =
$item->getAppliedTaxes();
341 if ($itemAppliedTaxes ===
null) {
342 return $taxDetailsData;
345 foreach ($itemAppliedTaxes as $taxId => $itemAppliedTax) {
346 if (!isset($appliedTaxes[$taxId])) {
349 $rateDataObjects = $itemAppliedTax->getRates();
350 foreach ($rateDataObjects as $rateDataObject) {
351 $rates[$rateDataObject->getCode()] = [
357 $appliedTaxes[$taxId] = [
369 return $taxDetailsData;
383 if (
$item->getParentCode()) {
384 $parentQuantity = $this->keyedItems[
$item->getParentCode()]->getQuantity();
385 return $parentQuantity *
$item->getQuantity();
387 return $item->getQuantity();
processItem(QuoteDetailsItemInterface $item, AbstractCalculator $calculator, $round=true)
const KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT
aggregateItemData($taxDetailsData, TaxDetailsItemInterface $item)
getTotalQuantity(QuoteDetailsItemInterface $item)
$taxDetailsItemDataObjectFactory
$discountTaxCompensations
calculate(QuoteDetailsItemInterface $item, $quantity, $round=true)
getRate( $productTaxClassID, $customerId=null, $storeId=null, $isDefault=false)
__construct(Calculation $calculation, CalculatorFactory $calculatorFactory, Config $config, TaxDetailsInterfaceFactory $taxDetailsDataObjectFactory, TaxDetailsItemInterfaceFactory $taxDetailsItemDataObjectFactory, StoreManagerInterface $storeManager, TaxClassManagementInterface $taxClassManagement, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper)
getCalculatedRate( $productTaxClassID, $customerId=null, $storeId=null)
getDefaultCalculatedRate( $productTaxClassID, $customerId=null, $storeId=null)
calculateTax(\Magento\Tax\Api\Data\QuoteDetailsInterface $quoteDetails, $storeId=null, $round=true)
$taxDetailsDataObjectFactory
calculateParent($children, $quantity)