/**
  * @param \Magento\Quote\Model\Cart\TotalsConverter $subject
  * @param \Closure $proceed
  * @param \Magento\Quote\Model\Quote\Address\Total[] $addressTotals
  * @return \Magento\Quote\Api\Data\TotalSegmentInterface[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundProcess(\Magento\Quote\Model\Cart\TotalsConverter $subject, \Closure $proceed, array $addressTotals = [])
 {
     $totalSegments = $proceed($addressTotals);
     if (!array_key_exists($this->code, $addressTotals)) {
         return $totalSegments;
     }
     $taxes = $addressTotals['tax']->getData();
     if (!array_key_exists('full_info', $taxes)) {
         return $totalSegments;
     }
     $detailsId = 1;
     $finalData = [];
     foreach (unserialize($taxes['full_info']) as $info) {
         if (array_key_exists('hidden', $info) && $info['hidden'] || $info['amount'] == 0 && $this->taxConfig->displayCartZeroTax()) {
             continue;
         }
         $taxDetails = $this->detailsFactory->create([]);
         $taxDetails->setAmount($info['amount']);
         $taxRates = $this->getRatesData($info['rates']);
         $taxDetails->setRates($taxRates);
         $taxDetails->setGroupId($detailsId);
         $finalData[] = $taxDetails;
         $detailsId++;
     }
     $attributes = $totalSegments[$this->code]->getExtensionAttributes();
     if ($attributes === null) {
         $attributes = $this->totalSegmentExtensionFactory->create();
     }
     $attributes->setTaxGrandtotalDetails($finalData);
     $totalSegments[$this->code]->setExtensionAttributes($attributes);
     return $totalSegments;
 }
 /**
  * @param CartTotalRepository $subject
  * @param \Closure $proceed
  * @param int $cartId
  * @return \Magento\Quote\Model\Cart\Totals
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGet(CartTotalRepository $subject, \Closure $proceed, $cartId)
 {
     $result = $proceed($cartId);
     $quote = $this->quoteRepository->getActive($cartId);
     $totals = $quote->getTotals();
     if (!array_key_exists('tax', $totals)) {
         return $result;
     }
     $taxes = $totals['tax']->getData();
     if (!array_key_exists('full_info', $taxes)) {
         return $result;
     }
     $detailsId = 1;
     $finalData = [];
     foreach ($taxes['full_info'] as $info) {
         if (array_key_exists('hidden', $info) && $info['hidden'] || $info['amount'] == 0 && $this->taxConfig->displayCartZeroTax()) {
             continue;
         }
         $taxDetails = $this->detailsFactory->create([]);
         $taxDetails->setAmount($info['amount']);
         $taxRates = $this->getRatesData($info['rates']);
         $taxDetails->setRates($taxRates);
         $taxDetails->setGroupId($detailsId);
         $finalData[] = $taxDetails;
         $detailsId++;
     }
     $attributes = $result->getExtensionAttributes();
     if ($attributes === null) {
         $attributes = $this->extensionFactory->create();
     }
     $attributes->setTaxGrandtotalDetails($finalData);
     /** @var $result \Magento\Quote\Model\Cart\Totals */
     $result->setExtensionAttributes($attributes);
     return $result;
 }
Example #3
0
 /**
  * Add tax totals information to address object
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @param Address\Total $total
  * @return array|null
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
 {
     $totals = [];
     $store = $quote->getStore();
     $applied = $total->getAppliedTaxes();
     $amount = $total->getTaxAmount();
     $taxAmount = $amount + $total->getTotalAmount('discount_tax_compensation');
     $area = null;
     if ($this->_config->displayCartTaxWithGrandTotal($store) && $total->getGrandTotal()) {
         $area = 'taxes';
     }
     if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
         $totals[] = ['code' => $this->getCode(), 'title' => __('Tax'), 'full_info' => $applied ? $applied : [], 'value' => $amount, 'area' => $area];
     }
     /**
      * Modify subtotal
      */
     if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
         if ($total->getSubtotalInclTax() > 0) {
             $subtotalInclTax = $total->getSubtotalInclTax();
         } else {
             $subtotalInclTax = $total->getSubtotal() + $taxAmount - $total->getShippingTaxAmount();
         }
         $totals[] = ['code' => 'subtotal', 'title' => __('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $total->getSubtotal()];
     }
     if (empty($totals)) {
         return null;
     }
     return $totals;
 }
Example #4
0
 /**
  * Add tax totals information to address object
  *
  * @param   Address $address
  * @return  $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function fetch(Address $address)
 {
     $applied = $address->getAppliedTaxes();
     $store = $address->getQuote()->getStore();
     $amount = $address->getTaxAmount();
     $items = $this->_getAddressItems($address);
     $discountTaxCompensation = 0;
     foreach ($items as $item) {
         $discountTaxCompensation += $item->getDiscountTaxCompensation();
     }
     $taxAmount = $amount + $discountTaxCompensation;
     $area = null;
     if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
         $area = 'taxes';
     }
     if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
         $address->addTotal(['code' => $this->getCode(), 'title' => __('Tax'), 'full_info' => $applied ? $applied : [], 'value' => $amount, 'area' => $area]);
     }
     $store = $address->getQuote()->getStore();
     /**
      * Modify subtotal
      */
     if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
         if ($address->getSubtotalInclTax() > 0) {
             $subtotalInclTax = $address->getSubtotalInclTax();
         } else {
             $subtotalInclTax = $address->getSubtotal() + $taxAmount - $address->getShippingTaxAmount();
         }
         $address->addTotal(['code' => 'subtotal', 'title' => __('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $address->getSubtotal()]);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function getConfig()
 {
     return ['isDisplayShippingPriceExclTax' => $this->isDisplayShippingPriceExclTax(), 'isDisplayShippingBothPrices' => $this->isDisplayShippingBothPrices(), 'reviewShippingDisplayMode' => $this->getDisplayShippingMode(), 'reviewItemPriceDisplayMode' => $this->getReviewItemPriceDisplayMode(), 'reviewTotalsDisplayMode' => $this->getReviewTotalsDisplayMode(), 'includeTaxInGrandTotal' => $this->isTaxDisplayedInGrandTotal(), 'isFullTaxSummaryDisplayed' => $this->isFullTaxSummaryDisplayed(), 'isZeroTaxDisplayed' => $this->taxConfig->displayCartZeroTax(), 'reloadOnBillingAddress' => $this->reloadOnBillingAddress(), 'defaultCountryId' => $this->scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'defaultRegionId' => $this->scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'defaultPostcode' => $this->scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)];
 }
Example #6
0
 /**
  * Check if need display zero tax in subtotal
  *
  * @param null|int|string|Store $store
  * @return bool
  */
 public function displayZeroTax($store = null)
 {
     return $this->_config->displayCartZeroTax($store);
 }
 /**
  * {@inheritdoc}
  */
 public function getConfig()
 {
     return ['isDisplayShippingPriceExclTax' => $this->isDisplayShippingPriceExclTax(), 'isDisplayShippingBothPrices' => $this->isDisplayShippingBothPrices(), 'reviewShippingDisplayMode' => $this->getDisplayShippingMode(), 'reviewItemPriceDisplayMode' => $this->getReviewItemPriceDisplayMode(), 'reviewTotalsDisplayMode' => $this->getReviewTotalsDisplayMode(), 'includeTaxInGrandTotal' => $this->isTaxDisplayedInGrandTotal(), 'isFullTaxSummaryDisplayed' => $this->isFullTaxSummaryDisplayed(), 'isZeroTaxDisplayed' => $this->taxConfig->displayCartZeroTax(), 'reloadOnBillingAddress' => $this->reloadOnBillingAddress()];
 }