/** * Add shipping totals information to address object * * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * @return array */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $amount = $total->getShippingAmount(); $shippingDescription = $total->getShippingDescription(); $title = $amount != 0 && $shippingDescription ? __('Shipping & Handling (%1)', $shippingDescription) : __('Shipping & Handling'); return ['code' => $this->getCode(), 'title' => $title, 'value' => $amount]; }
/** * @param ShippingAssignmentInterface $shippingAssignment * @param QuoteAddress\Total $total * @param bool $useBaseCurrency * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface */ public function getShippingDataObject(ShippingAssignmentInterface $shippingAssignment, QuoteAddress\Total $total, $useBaseCurrency) { $store = $shippingAssignment->getShipping()->getAddress()->getQuote()->getStore(); if ($total->getShippingTaxCalculationAmount() === null) { //Save the original shipping amount because shipping amount will be overridden //with shipping amount excluding tax $total->setShippingTaxCalculationAmount($total->getShippingAmount()); $total->setBaseShippingTaxCalculationAmount($total->getBaseShippingAmount()); } if ($total->getShippingTaxCalculationAmount() !== null) { /** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $itemDataObject */ $itemDataObject = $this->quoteDetailsItemDataObjectFactory->create()->setType(self::ITEM_TYPE_SHIPPING)->setCode(self::ITEM_CODE_SHIPPING)->setQuantity(1); if ($useBaseCurrency) { $itemDataObject->setUnitPrice($total->getBaseShippingTaxCalculationAmount()); } else { $itemDataObject->setUnitPrice($total->getShippingTaxCalculationAmount()); } if ($total->getShippingDiscountAmount()) { if ($useBaseCurrency) { $itemDataObject->setDiscountAmount($total->getBaseShippingDiscountAmount()); } else { $itemDataObject->setDiscountAmount($total->getShippingDiscountAmount()); } } $itemDataObject->setTaxClassKey($this->taxClassKeyDataObjectFactory->create()->setType(TaxClassKeyInterface::TYPE_ID)->setValue($this->_config->getShippingTaxClass($store))); $itemDataObject->setIsTaxIncluded($this->_config->shippingPriceIncludesTax($store)); return $itemDataObject; } return null; }