totalsInterfaceFactory = $totalsInterfaceFactory; $this->totalsFactory = $totalsFactory; $this->quoteRepository = $quoteRepository; $this->dataObjectHelper = $dataObjectHelper; $this->couponService = $couponService; $this->totalsConverter = $totalsConverter; $this->itemConverter = $converter; } /** * @param $cartId * @return TotalsInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($cartId): TotalsInterface { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if ($quote->isVirtual()) { $quote->collectTotals(); $addressTotalsData = $quote->getBillingAddress()->getData(); $addressTotals = $quote->getBillingAddress()->getTotals(); } else { $addressTotalsData = $quote->getShippingAddress()->getData(); $addressTotals = $quote->getShippingAddress()->getTotals(); } unset($addressTotalsData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]); $quoteTotals = $this->totalsInterfaceFactory->create(); $this->dataObjectHelper->populateWithArray( $quoteTotals, $addressTotalsData, TotalsInterface::class ); $items = array_map([$this->itemConverter, 'modelToDataObject'], $quote->getAllVisibleItems()); // $logger = ObjectManager::getInstance()->get(LoggerInterface::class); $calculatedTotals = $this->totalsConverter->process($addressTotals); $quoteTotals->setTotalSegments($calculatedTotals); $quoteTotals->setCouponCode($this->couponService->get($cartId)); $quoteTotals->setItems($items); $quoteTotals->setDiscountAmount($quote->getData('customer_discount')); $quoteTotals->setItemsQty($quote->getItemsQty()); $quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode()); $quoteTotals->setQuoteCurrencyCode($quote->getQuoteCurrencyCode()); return $quoteTotals;// TODO: Change the autogenerated stub } }