/**
  * @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;
 }
 protected function setupTaxDetails(array $taxDetails)
 {
     $taxDetailsMock = $this->getMockBuilder('\\Magento\\Tax\\Api\\Data\\GrandTotalDetailsInterface')->getMock();
     $this->detailsFactoryMock->expects($this->once())->method('create')->willReturn($taxDetailsMock);
     $taxDetailsMock->expects($this->once())->method('setAmount')->with($taxDetails['amount'])->willReturnSelf();
     $taxDetailsMock->expects($this->once())->method('setRates')->with($taxDetails['rates'])->willReturnSelf();
     $taxDetailsMock->expects($this->once())->method('setGroupId')->with(1)->willReturnSelf();
     return $taxDetailsMock;
 }
 /**
  * @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;
 }