/** * Calculate item fixed tax and prepare information for discount and regular taxation * * @param \Magento\Quote\Model\Quote\Address $address * @param \Magento\Quote\Model\Quote\Address\Total $total * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @return void|$this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function process(\Magento\Quote\Model\Quote\Address $address, \Magento\Quote\Model\Quote\Address\Total $total, $item) { $attributes = $this->weeeData->getProductWeeeAttributes($item->getProduct(), $address, $address->getQuote()->getBillingAddress(), $this->_store->getWebsiteId()); $productTaxes = []; $totalValueInclTax = 0; $baseTotalValueInclTax = 0; $totalRowValueInclTax = 0; $baseTotalRowValueInclTax = 0; $totalValueExclTax = 0; $baseTotalValueExclTax = 0; $totalRowValueExclTax = 0; $baseTotalRowValueExclTax = 0; $associatedTaxables = $item->getAssociatedTaxables(); if (!$associatedTaxables) { $associatedTaxables = []; } else { // remove existing weee associated taxables foreach ($associatedTaxables as $iTaxable => $taxable) { if ($taxable[CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_TYPE] == self::ITEM_TYPE) { unset($associatedTaxables[$iTaxable]); } } } foreach ($attributes as $key => $attribute) { $title = $attribute->getName(); $baseValueExclTax = $baseValueInclTax = $attribute->getAmount(); $valueExclTax = $valueInclTax = $this->priceCurrency->round($this->priceCurrency->convert($baseValueExclTax, $this->_store)); $rowValueInclTax = $rowValueExclTax = $this->priceCurrency->round($valueInclTax * $item->getTotalQty()); $baseRowValueInclTax = $this->priceCurrency->round($baseValueInclTax * $item->getTotalQty()); $baseRowValueExclTax = $baseRowValueInclTax; $totalValueInclTax += $valueInclTax; $baseTotalValueInclTax += $baseValueInclTax; $totalRowValueInclTax += $rowValueInclTax; $baseTotalRowValueInclTax += $baseRowValueInclTax; $totalValueExclTax += $valueExclTax; $baseTotalValueExclTax += $baseValueExclTax; $totalRowValueExclTax += $rowValueExclTax; $baseTotalRowValueExclTax += $baseRowValueExclTax; $productTaxes[] = ['title' => $title, 'base_amount' => $baseValueExclTax, 'amount' => $valueExclTax, 'row_amount' => $rowValueExclTax, 'base_row_amount' => $baseRowValueExclTax, 'base_amount_incl_tax' => $baseValueInclTax, 'amount_incl_tax' => $valueInclTax, 'row_amount_incl_tax' => $rowValueInclTax, 'base_row_amount_incl_tax' => $baseRowValueInclTax]; if ($this->weeeData->isTaxable($this->_store)) { $weeeItemCode = self::ITEM_CODE_WEEE_PREFIX . $this->getNextIncrement(); $weeeItemCode .= '-' . $title; $associatedTaxables[] = [CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_TYPE => self::ITEM_TYPE, CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_CODE => $weeeItemCode, CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_UNIT_PRICE => $valueExclTax, CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_BASE_UNIT_PRICE => $baseValueExclTax, CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_QUANTITY => $item->getTotalQty(), CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_TAX_CLASS_ID => $item->getProduct()->getTaxClassId()]; $this->weeeCodeToItemMap[$weeeItemCode] = $item; } } $item->setAssociatedTaxables($associatedTaxables); $item->setWeeeTaxAppliedAmount($totalValueExclTax)->setBaseWeeeTaxAppliedAmount($baseTotalValueExclTax)->setWeeeTaxAppliedRowAmount($totalRowValueExclTax)->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValueExclTax); $item->setWeeeTaxAppliedAmountInclTax($totalValueInclTax)->setBaseWeeeTaxAppliedAmountInclTax($baseTotalValueInclTax)->setWeeeTaxAppliedRowAmountInclTax($totalRowValueInclTax)->setBaseWeeeTaxAppliedRowAmntInclTax($baseTotalRowValueInclTax); $this->processTotalAmount($total, $totalRowValueExclTax, $baseTotalRowValueExclTax, $totalRowValueInclTax, $baseTotalRowValueInclTax); $this->weeeData->setApplied($item, array_merge($this->weeeData->getApplied($item), $productTaxes)); }
/** * Map an item to item data object * * @param \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $itemDataObjectFactory * @param AbstractItem $item * @param bool $priceIncludesTax * @param bool $useBaseCurrency * @param string $parentCode * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface */ public function mapItem(\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, AbstractItem $item, $priceIncludesTax, $useBaseCurrency, $parentCode = null) { if (!$item->getTaxCalculationItemId()) { $sequence = 'sequence-' . $this->getNextIncrement(); $item->setTaxCalculationItemId($sequence); } /** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $itemDataObject */ $itemDataObject = $itemDataObjectFactory->create(); $itemDataObject->setCode($item->getTaxCalculationItemId())->setQuantity($item->getQty())->setTaxClassKey($this->taxClassKeyDataObjectFactory->create()->setType(TaxClassKeyInterface::TYPE_ID)->setValue($item->getProduct()->getTaxClassId()))->setIsTaxIncluded($priceIncludesTax)->setType(self::ITEM_TYPE_PRODUCT); if ($useBaseCurrency) { if (!$item->getBaseTaxCalculationPrice()) { $item->setBaseTaxCalculationPrice($item->getBaseCalculationPriceOriginal()); } $itemDataObject->setUnitPrice($item->getBaseTaxCalculationPrice())->setDiscountAmount($item->getBaseDiscountAmount()); } else { if (!$item->getTaxCalculationPrice()) { $item->setTaxCalculationPrice($item->getCalculationPriceOriginal()); } $itemDataObject->setUnitPrice($item->getTaxCalculationPrice())->setDiscountAmount($item->getDiscountAmount()); } $itemDataObject->setParentCode($parentCode); return $itemDataObject; }
/** * Get actual SKU for quote item. This used since configurable product quote items report the child SKU when * $item->getProduct()->getSku() is called * * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @return mixed */ protected function getActualSkuForQuoteItem(\Magento\Quote\Model\Quote\Item\AbstractItem $item) { return $item->getProduct()->getData('sku'); }