Пример #1
0
 public function testMap()
 {
     $methods = ['getId', 'getStoreId', 'getCreatedAt', 'getUpdatedAt', 'getConvertedAt', 'getIsActive', 'getIsVirtual', 'getItemsCount', 'getItemsQty', 'getCheckoutMethod', 'getReservedOrderId', 'getOrigOrderId', '__wakeUp'];
     $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', $methods, [], '', false);
     $expected = [Cart::ID => 12, Cart::STORE_ID => 1, Cart::CREATED_AT => '2014-04-02 12:28:50', Cart::UPDATED_AT => '2014-04-02 12:28:50', Cart::CONVERTED_AT => '2014-04-02 12:28:50', Cart::IS_ACTIVE => true, Cart::IS_VIRTUAL => false, Cart::ITEMS_COUNT => 10, Cart::ITEMS_QUANTITY => 15, Cart::CHECKOUT_METHOD => 'check mo', Cart::RESERVED_ORDER_ID => 'order_id', Cart::ORIG_ORDER_ID => 'orig_order_id'];
     $expectedMethods = ['getId' => 12, 'getStoreId' => 1, 'getCreatedAt' => '2014-04-02 12:28:50', 'getUpdatedAt' => '2014-04-02 12:28:50', 'getConvertedAt' => '2014-04-02 12:28:50', 'getIsActive' => true, 'getIsVirtual' => false, 'getItemsCount' => 10, 'getItemsQty' => 15, 'getCheckoutMethod' => 'check mo', 'getReservedOrderId' => 'order_id', 'getOrigOrderId' => 'orig_order_id'];
     foreach ($expectedMethods as $method => $value) {
         $quoteMock->expects($this->once())->method($method)->will($this->returnValue($value));
     }
     $this->assertEquals($expected, $this->mapper->map($quoteMock));
 }
Пример #2
0
 public function testMap()
 {
     $methods = ['getId', 'getStoreId', 'getCreatedAt', 'getUpdatedAt', 'getConvertedAt', 'getIsActive', 'getIsVirtual', 'getItemsCount', 'getItemsQty', 'getCheckoutMethod', 'getReservedOrderId', 'getOrigOrderId', 'getAllItems', '__wakeUp'];
     $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', $methods, [], '', false);
     $itemMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Item', [], [], '', false);
     $quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$itemMock]));
     $expected = [Cart::ID => 12, Cart::STORE_ID => 1, Cart::CREATED_AT => '2014-04-02 12:28:50', Cart::UPDATED_AT => '2014-04-02 12:28:50', Cart::CONVERTED_AT => '2014-04-02 12:28:50', Cart::IS_ACTIVE => true, Cart::IS_VIRTUAL => false, Cart::ITEMS_COUNT => 10, Cart::ITEMS_QUANTITY => 15, Cart::CHECKOUT_METHOD => 'check mo', Cart::RESERVED_ORDER_ID => 'order_id', Cart::ORIG_ORDER_ID => 'orig_order_id'];
     $expectedMethods = ['getId' => 12, 'getStoreId' => 1, 'getCreatedAt' => '2014-04-02 12:28:50', 'getUpdatedAt' => '2014-04-02 12:28:50', 'getConvertedAt' => '2014-04-02 12:28:50', 'getIsActive' => true, 'getIsVirtual' => false, 'getItemsCount' => 10, 'getItemsQty' => 15, 'getCheckoutMethod' => 'check mo', 'getReservedOrderId' => 'order_id', 'getOrigOrderId' => 'orig_order_id'];
     foreach ($expectedMethods as $method => $value) {
         $quoteMock->expects($this->once())->method($method)->will($this->returnValue($value));
     }
     $this->customerMapper->expects($this->once())->method('map')->with($quoteMock)->will($this->returnValue(['testCustomer']));
     $this->customerBuilder->expects($this->once())->method('populateWithArray')->with(['testCustomer']);
     $this->customerBuilder->expects($this->once())->method('create')->will($this->returnValue('customer'));
     $this->totalsMapper->expects($this->once())->method('map')->with($quoteMock)->will($this->returnValue(['testTotals']));
     $this->totalsBuilder->expects($this->once())->method('populateWithArray')->with(['testTotals']);
     $this->totalsBuilder->expects($this->once())->method('create')->will($this->returnValue('totals'));
     $this->itemTotalsMapper->expects($this->once())->method('extractDto')->with($itemMock)->will($this->returnValue('mappedItem'));
     $this->totalsBuilder->expects($this->once())->method('setItems')->with(['mappedItem']);
     $this->currencyMapper->expects($this->once())->method('extractDto')->with($quoteMock)->will($this->returnValue('currency'));
     $this->cartBuilder->expects($this->once())->method('populateWithArray')->with($expected);
     $this->cartBuilder->expects($this->once())->method('setCustomer')->with('customer');
     $this->cartBuilder->expects($this->once())->method('setTotals')->with('totals');
     $this->cartBuilder->expects($this->once())->method('setCurrency')->with('currency');
     $this->mapper->map($quoteMock);
 }
Пример #3
0
 /**
  * Create cart data object based on given quote
  *
  * @param Quote $quote
  * @return Cart
  */
 protected function createCartDataObject(Quote $quote)
 {
     $this->cartBuilder->populateWithArray($this->cartMapper->map($quote));
     $this->customerBuilder->populateWithArray($this->customerMapper->map($quote));
     $this->totalsBuilder->populateWithArray($this->totalsMapper->map($quote));
     $this->totalsBuilder->setItems($this->fetchItemTotalsData($quote));
     $this->cartBuilder->setCustomer($this->customerBuilder->create());
     $this->cartBuilder->setTotals($this->totalsBuilder->create());
     $this->cartBuilder->setCurrency($this->currencyMapper->extractDto($quote));
     return $this->cartBuilder->create();
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function getCartList(SearchCriteria $searchCriteria)
 {
     $this->searchResultsBuilder->setSearchCriteria($searchCriteria);
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $this->quoteCollection);
     }
     $this->searchResultsBuilder->setTotalCount($this->quoteCollection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $this->quoteCollection->addOrder($this->getQuoteSearchField($sortOrder->getField()), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $this->quoteCollection->setCurPage($searchCriteria->getCurrentPage());
     $this->quoteCollection->setPageSize($searchCriteria->getPageSize());
     $cartList = [];
     /** @var Quote $quote */
     foreach ($this->quoteCollection as $quote) {
         $cartList[] = $this->cartMapper->map($quote);
     }
     $this->searchResultsBuilder->setItems($cartList);
     return $this->searchResultsBuilder->create();
 }