/**
  * {@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;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function remove($cartId)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->couponManagement->remove($quoteIdMask->getId());
 }