/**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     $shippingAddress = $quote->getShippingAddress();
     if ($quote->isVirtual()) {
         $totalsData = array_merge($quote->getBillingAddress()->getData(), $quote->getData());
     } else {
         $totalsData = array_merge($shippingAddress->getData(), $quote->getData());
     }
     $totals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     $weeeTaxAppliedAmount = 0;
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->itemConverter->modelToDataObject($item);
         $weeeTaxAppliedAmount += $item->getWeeeTaxAppliedAmount();
     }
     $totals->setCouponCode($this->couponService->get($cartId));
     $calculatedTotals = $this->totalsConverter->process($quote->getTotals());
     $amount = $totals->getGrandTotal() - $totals->getTaxAmount();
     $amount = $amount > 0 ? $amount : 0;
     $totals->setGrandTotal($amount);
     $totals->setTotalSegments($calculatedTotals);
     $totals->setItems($items);
     $totals->setWeeeTaxAppliedAmount($weeeTaxAppliedAmount);
     return $totals;
 }
Example #2
0
 /**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     $shippingAddress = $quote->getShippingAddress();
     if ($quote->isVirtual()) {
         $totalsData = array_merge($quote->getBillingAddress()->getData(), $quote->getData());
     } else {
         $totalsData = array_merge($shippingAddress->getData(), $quote->getData());
     }
     $totals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->converter->modelToDataObject($item);
     }
     $totals->setItems($items);
     return $totals;
 }