Esempio n. 1
0
 /**
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/quote.php
  */
 public function testUpdateAction()
 {
     $items = $this->quoteItemCollectionFactory->create();
     $itemId = $items->getAllIds()[0];
     $this->getRequest()->setParam('customer_id', 1);
     $this->getRequest()->setParam('website_id', 1);
     $this->getRequest()->setParam('id', $itemId);
     $this->dispatch('backend/customer/cart_product_composite_cart/update');
     $this->assertRedirect($this->stringContains('catalog/product/showUpdateResult'));
 }
Esempio n. 2
0
 /**
  * @param array $productTypes
  * @param int $expected
  * @dataProvider dataProviderForTestBeforeSaveIsVirtualQuote
  */
 public function testBeforeSaveIsVirtualQuote(array $productTypes, $expected)
 {
     $storeId = 1;
     $currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->getMock();
     $currencyMock->expects($this->any())->method('getCode')->will($this->returnValue('test_code'));
     $currencyMock->expects($this->any())->method('getRate')->will($this->returnValue('test_rate'));
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getBaseCurrency')->will($this->returnValue($currencyMock));
     $storeMock->expects($this->once())->method('getCurrentCurrency')->will($this->returnValue($currencyMock));
     $this->storeManagerMock->expects($this->any())->method('getStore')->with($storeId)->will($this->returnValue($storeMock));
     $this->quote->setStoreId($storeId);
     $collectionMock = $this->getMock('Magento\\Quote\\Model\\Resource\\Quote\\Item\\Collection', [], [], '', false);
     $items = [];
     foreach ($productTypes as $type) {
         $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
         $productMock->expects($this->any())->method('getIsVirtual')->willReturn($type);
         $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['isDeleted', 'getParentItemId', 'getProduct'], [], '', false);
         $itemMock->expects($this->any())->method('isDeleted')->willReturn(false);
         $itemMock->expects($this->any())->method('getParentItemId')->willReturn(false);
         $itemMock->expects($this->any())->method('getProduct')->willReturn($productMock);
         $items[] = $itemMock;
     }
     $iterator = new \ArrayIterator($items);
     $collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator));
     $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $this->quote->beforeSave();
     $this->assertEquals($expected, $this->quote->getDataByKey(CartInterface::KEY_IS_VIRTUAL));
 }
Esempio n. 3
0
 public function testGetItemsCollection()
 {
     $itemCollectionMock = $this->getMockBuilder('Magento\\Quote\\Model\\Resource\\Quote\\Collection')->disableOriginalConstructor()->setMethods(['setQuote'])->getMock();
     $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->willReturn($itemCollectionMock);
     $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('Magento\\Quote\\Model\\Resource\\Quote\\Collection'));
     $itemCollectionMock->expects($this->once())->method('setQuote')->with($this->quote);
     $this->quote->getItemsCollection();
 }
Esempio n. 4
0
 public function testAddItem()
 {
     $item = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['setQuote', 'getId'], [], '', false);
     $item->expects($this->once())->method('setQuote');
     $item->expects($this->once())->method('getId')->willReturn(false);
     $itemsMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', ['setQuote', 'addItem'], [], '', false);
     $itemsMock->expects($this->once())->method('setQuote');
     $itemsMock->expects($this->once())->method('addItem')->with($item);
     $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->willReturn($itemsMock);
     $this->eventManagerMock->expects($this->once())->method('dispatch');
     $this->quote->addItem($item);
 }
Esempio n. 5
0
 /**
  * Add cart info to collection
  *
  * @return $this
  */
 public function addCartInfo()
 {
     foreach ($this->getItems() as $item) {
         try {
             $quote = $this->quoteRepository->getForCustomer($item->getId());
             $totals = $quote->getTotals();
             $item->setTotal($totals['subtotal']->getValue());
             $quoteItems = $this->_quoteItemFactory->create()->setQuoteFilter($quote->getId());
             $quoteItems->load();
             $item->setItems($quoteItems->count());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             $item->remove();
         }
     }
     return $this;
 }
Esempio n. 6
0
 /**
  * Retrieve quote items collection
  *
  * @param bool $useCache
  * @return  \Magento\Eav\Model\Entity\Collection\AbstractCollection
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getItemsCollection($useCache = true)
 {
     if ($this->hasItemsCollection()) {
         return $this->getData('items_collection');
     }
     if (null === $this->_items) {
         $this->_items = $this->_quoteItemCollectionFactory->create();
         $this->extensionAttributesJoinProcessor->process($this->_items);
         $this->_items->setQuote($this);
     }
     return $this->_items;
 }