/** * @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')); }
/** * Add cart info to collection * * @return $this */ public function addCartInfo() { foreach ($this->getItems() as $item) { $quote = $this->_quoteFactory->create()->loadByCustomer($item->getId()); if ($quote instanceof \Magento\Sales\Model\Quote) { $totals = $quote->getTotals(); $item->setTotal($totals['subtotal']->getValue()); $quoteItems = $this->_quoteItemFactory->create()->setQuoteFilter($quote->getId()); $quoteItems->load(); $item->setItems($quoteItems->count()); } else { $item->remove(); } } return $this; }
public function testAddProductItemPreparation() { $itemMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', [], [], '', false); $expectedResult = $itemMock; $requestMock = $this->getMock('\\Magento\\Framework\\Object'); $this->objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo(['qty' => 1]))->will($this->returnValue($requestMock)); $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', ['prepareForCartAdvanced'], [], '', false); $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getParentProductId', 'setStickWithinParent', '__wakeup'], [], '', false); $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Quote\\Item\\Collection', [], [], '', false); $itemMock->expects($this->any())->method('representProduct')->will($this->returnValue(true)); $iterator = new \ArrayIterator([$itemMock]); $collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator)); $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock)); $typeInstanceMock->expects($this->once())->method('prepareForCartAdvanced')->will($this->returnValue([$productMock])); $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock)); $result = $this->quote->addProduct($this->productMock, null); $this->assertEquals($expectedResult, $result); }
/** * Retrieve quote items collection * * @param bool $useCache * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection */ public function getItemsCollection($useCache = true) { if ($this->hasItemsCollection()) { return $this->getData('items_collection'); } if (null === $this->_items) { $this->_items = $this->_quoteItemCollectionFactory->create(); $this->_items->setQuote($this); } return $this->_items; }