/**
  * {@inheritdoc}
  */
 public function getTotals($cartId)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     $this->totalsBuilder->populateWithArray($this->totalsMapper->map($quote));
     $items = [];
     foreach ($quote->getAllItems() as $item) {
         $items[] = $this->itemTotalsMapper->extractDto($item);
     }
     $this->totalsBuilder->setItems($items);
     return $this->totalsBuilder->create();
 }
Beispiel #2
0
 public function testMap()
 {
     $methods = ['getBaseGrandTotal', 'getGrandTotal', 'getBaseSubtotal', 'getSubtotal', 'getBaseCurrencyCode', 'getBaseSubtotalWithDiscount', 'getSubtotalWithDiscount', 'getShippingAddress', '__wakeUp', 'getQuoteCurrencyCode'];
     $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', $methods, [], '', false);
     $methods = ['getDiscountAmount', 'getBaseDiscountAmount', 'getShippingAmount', 'getBaseShippingAmount', 'getShippingDiscountAmount', 'getBaseShippingDiscountAmount', 'getTaxAmount', 'getBaseTaxAmount', 'getShippingTaxAmount', 'getBaseShippingTaxAmount', 'getSubtotalInclTax', 'getBaseSubtotalTotalInclTax', 'getShippingInclTax', 'getBaseShippingInclTax', 'getId', '__wakeUp'];
     $shippingAddressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', $methods, [], '', false);
     $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
     $expected = [Totals::BASE_GRAND_TOTAL => 100, Totals::GRAND_TOTAL => 150, Totals::BASE_SUBTOTAL => 150, Totals::SUBTOTAL => 150, Totals::BASE_SUBTOTAL_WITH_DISCOUNT => 120, Totals::SUBTOTAL_WITH_DISCOUNT => 120, Totals::BASE_CURRENCY_CODE => 'EUR', Totals::QUOTE_CURRENCY_CODE => 'BR', Totals::DISCOUNT_AMOUNT => 110, Totals::BASE_DISCOUNT_AMOUNT => 110, Totals::SHIPPING_AMOUNT => 20, Totals::BASE_SHIPPING_AMOUNT => 20, Totals::SHIPPING_DISCOUNT_AMOUNT => 5, Totals::BASE_SHIPPING_DISCOUNT_AMOUNT => 5, Totals::TAX_AMOUNT => 3, Totals::BASE_TAX_AMOUNT => 3, Totals::SHIPPING_TAX_AMOUNT => 1, Totals::BASE_SHIPPING_TAX_AMOUNT => 1, Totals::SUBTOTAL_INCL_TAX => 153, Totals::BASE_SUBTOTAL_INCL_TAX => 153, Totals::SHIPPING_INCL_TAX => 21, Totals::BASE_SHIPPING_INCL_TAX => 21];
     $expectedQuoteMethods = ['getBaseGrandTotal' => 100, 'getGrandTotal' => 150, 'getBaseSubtotal' => 150, 'getSubtotal' => 150, 'getBaseSubtotalWithDiscount' => 120, 'getSubtotalWithDiscount' => 120];
     $addressMethods = ['getDiscountAmount' => 110, 'getBaseDiscountAmount' => 110, 'getShippingAmount' => 20, 'getBaseShippingAmount' => 20, 'getShippingDiscountAmount' => 5, 'getBaseShippingDiscountAmount' => 5, 'getTaxAmount' => 3, 'getBaseTaxAmount' => 3, 'getShippingTaxAmount' => 1, 'getBaseShippingTaxAmount' => 1, 'getSubtotalInclTax' => 153, 'getBaseSubtotalTotalInclTax' => 153, 'getShippingInclTax' => 21, 'getBaseShippingInclTax' => 21];
     $quoteMock->expects($this->atLeastOnce())->method('getBaseCurrencyCode')->will($this->returnValue('EUR'));
     $quoteMock->expects($this->atLeastOnce())->method('getQuoteCurrencyCode')->will($this->returnValue('BR'));
     foreach ($expectedQuoteMethods as $method => $value) {
         $quoteMock->expects($this->once())->method($method)->will($this->returnValue($value));
     }
     foreach ($addressMethods as $method => $value) {
         $shippingAddressMock->expects($this->once())->method($method)->will($this->returnValue($value));
     }
     $this->assertEquals($expected, $this->mapper->map($quoteMock));
 }
Beispiel #3
0
 /**
  * Fetch base quote data and map it to DTO fields
  *
  * @param Quote $quote
  * @return array
  */
 public function map(Quote $quote)
 {
     $this->cartBuilder->populateWithArray([Cart::ID => $quote->getId(), Cart::STORE_ID => $quote->getStoreId(), Cart::CREATED_AT => $quote->getCreatedAt(), Cart::UPDATED_AT => $quote->getUpdatedAt(), Cart::CONVERTED_AT => $quote->getConvertedAt(), Cart::IS_ACTIVE => $quote->getIsActive(), Cart::IS_VIRTUAL => $quote->getIsVirtual(), Cart::ITEMS_COUNT => $quote->getItemsCount(), Cart::ITEMS_QUANTITY => $quote->getItemsQty(), Cart::CHECKOUT_METHOD => $quote->getCheckoutMethod(), Cart::RESERVED_ORDER_ID => $quote->getReservedOrderId(), Cart::ORIG_ORDER_ID => $quote->getOrigOrderId()]);
     $this->customerBuilder->populateWithArray($this->customerMapper->map($quote));
     $this->totalsBuilder->populateWithArray($this->totalsMapper->map($quote));
     $items = [];
     foreach ($quote->getAllItems() as $item) {
         $items[] = $this->itemTotalsMapper->extractDto($item);
     }
     $this->totalsBuilder->setItems($items);
     $this->cartBuilder->setCustomer($this->customerBuilder->create());
     $this->cartBuilder->setTotals($this->totalsBuilder->create());
     $this->cartBuilder->setCurrency($this->currencyMapper->extractDto($quote));
     return $this->cartBuilder->create();
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getTotals($cartId)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     $this->totalsBuilder->populateWithArray($this->totalsMapper->map($quote));
     $this->totalsBuilder->setItems($this->fetchItemTotalsData($quote));
     return $this->totalsBuilder->create();
 }