Esempio n. 1
0
 /**
  * Update tax related fields for shipping
  *
  * @param Address $address
  * @param \Magento\Tax\Service\V1\Data\TaxDetails\Item $shippingTaxDetails
  * @param \Magento\Tax\Service\V1\Data\TaxDetails\Item $baseShippingTaxDetails
  * @return $this
  */
 protected function processShippingTaxInfo(Address $address, $shippingTaxDetails, $baseShippingTaxDetails)
 {
     $address->setTotalAmount('shipping', $shippingTaxDetails->getRowTotal());
     $address->setBaseTotalAmount('shipping', $baseShippingTaxDetails->getRowTotal());
     $address->setTotalAmount('shipping_hidden_tax', $shippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setBaseTotalAmount('shipping_hidden_tax', $baseShippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setShippingInclTax($shippingTaxDetails->getRowTotalInclTax());
     $address->setBaseShippingInclTax($baseShippingTaxDetails->getRowTotalInclTax());
     $address->setShippingTaxAmount($shippingTaxDetails->getRowTax());
     $address->setBaseShippingTaxAmount($baseShippingTaxDetails->getRowTax());
     //Add the shipping tax to total tax amount
     $address->addTotalAmount('tax', $shippingTaxDetails->getRowTax());
     $address->addBaseTotalAmount('tax', $baseShippingTaxDetails->getRowTax());
     if ($this->_config->discountTax($address->getQuote()->getStore())) {
         $address->setShippingAmountForDiscount($shippingTaxDetails->getRowTotalInclTax());
         $address->setBaseShippingAmountForDiscount($baseShippingTaxDetails->getRowTotalInclTax());
     }
     return $this;
 }
 /**
  * Add row total item amount to subtotal
  *
  * @param array $taxDetailsData
  * @param TaxDetailsItem $item
  * @return array
  */
 protected function aggregateItemData($taxDetailsData, TaxDetailsItem $item)
 {
     $taxDetailsData[TaxDetails::KEY_SUBTOTAL] = $taxDetailsData[TaxDetails::KEY_SUBTOTAL] + $item->getRowTotal();
     $taxDetailsData[TaxDetails::KEY_TAX_AMOUNT] = $taxDetailsData[TaxDetails::KEY_TAX_AMOUNT] + $item->getRowTax();
     $taxDetailsData[TaxDetails::KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT] = $taxDetailsData[TaxDetails::KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT] + $item->getDiscountTaxCompensationAmount();
     $itemAppliedTaxes = $item->getAppliedTaxes();
     if (!isset($taxDetailsData[TaxDetails::KEY_APPLIED_TAXES])) {
         $taxDetailsData[TaxDetails::KEY_APPLIED_TAXES] = [];
     }
     $appliedTaxes = $taxDetailsData[TaxDetails::KEY_APPLIED_TAXES];
     foreach ($itemAppliedTaxes as $taxId => $itemAppliedTax) {
         if (!isset($appliedTaxes[$taxId])) {
             //convert rate data object to array
             $rates = [];
             $rateDataObjects = $itemAppliedTax->getRates();
             foreach ($rateDataObjects as $rateDataObject) {
                 $rates[$rateDataObject->getCode()] = [AppliedTaxRate::KEY_CODE => $rateDataObject->getCode(), AppliedTaxRate::KEY_TITLE => $rateDataObject->getTitle(), AppliedTaxRate::KEY_PERCENT => $rateDataObject->getPercent()];
             }
             $appliedTaxes[$taxId] = [AppliedTax::KEY_AMOUNT => $itemAppliedTax->getAmount(), AppliedTax::KEY_PERCENT => $itemAppliedTax->getPercent(), AppliedTax::KEY_RATES => $rates, AppliedTax::KEY_TAX_RATE_KEY => $itemAppliedTax->getTaxRateKey()];
         } else {
             $appliedTaxes[$taxId][AppliedTax::KEY_AMOUNT] += $itemAppliedTax->getAmount();
         }
     }
     $taxDetailsData[TaxDetails::KEY_APPLIED_TAXES] = $appliedTaxes;
     return $taxDetailsData;
 }
Esempio n. 3
0
 /**
  * Update tax related fields for shipping
  *
  * @param Address $address
  * @param \Magento\Tax\Service\V1\Data\TaxDetails\Item $shippingTaxDetails
  * @param \Magento\Tax\Service\V1\Data\TaxDetails\Item $baseShippingTaxDetails
  * @return $this
  */
 protected function updateShippingTaxInfo(Address $address, $shippingTaxDetails, $baseShippingTaxDetails)
 {
     $address->setTotalAmount('shipping', $shippingTaxDetails->getRowTotal());
     $address->setBaseTotalAmount('shipping', $baseShippingTaxDetails->getRowTotal());
     $address->setShippingTaxAmount($shippingTaxDetails->getRowTax());
     $address->setBaseShippingTaxAmount($baseShippingTaxDetails->getRowTax());
     $address->setTotalAmount('shipping_hidden_tax', $shippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setBaseTotalAmount('shipping_hidden_tax', $baseShippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setShippingInclTax($shippingTaxDetails->getRowTotalInclTax());
     $address->setBaseShippingInclTax($baseShippingTaxDetails->getRowTotalInclTax());
     if ($this->_config->discountTax($this->_store)) {
         $address->setShippingAmountForDiscount($shippingTaxDetails->getRowTotalInclTax());
         $address->setBaseShippingAmountForDiscount($baseShippingTaxDetails->getRowTotalInclTax());
     }
     //Add taxes applied to shipping to applied taxes
     $appliedTaxes = $shippingTaxDetails->getAppliedTaxes();
     $baseAppliedTaxes = $baseShippingTaxDetails->getAppliedTaxes();
     $appliedTaxesArray = $this->convertAppliedTaxes($appliedTaxes, $baseAppliedTaxes);
     $this->_saveAppliedTaxes($address, $appliedTaxesArray, $shippingTaxDetails->getRowTax(), $baseShippingTaxDetails->getRowTax(), $shippingTaxDetails->getTaxPercent());
     return $this;
 }