/** * Get items * * @return Item[] */ public function getItems() { $items = $this->getParentBlock()->getItems(); $oldSuperMode = $this->getQuote()->getIsSuperMode(); $this->getQuote()->setIsSuperMode(false); foreach ($items as $item) { // To dispatch inventory event sales_quote_item_qty_set_after, set item qty $item->setQty($item->getQty()); if (!$item->getMessage()) { //Getting product ids for stock item last quantity validation before grid display $stockItemToCheck = array(); $childItems = $item->getChildren(); if (count($childItems)) { foreach ($childItems as $childItem) { $stockItemToCheck[] = $childItem->getProduct()->getId(); } } else { $stockItemToCheck[] = $item->getProduct()->getId(); } foreach ($stockItemToCheck as $productId) { $check = $this->stockItemService->checkQuoteItemQty($productId, $item->getQty(), $item->getQty(), $item->getQty()); $item->setMessage($check->getMessage()); $item->setHasError($check->getHasError()); } } if ($item->getProduct()->getStatus() == ProductStatus::STATUS_DISABLED) { $item->setMessage(__('This product is disabled.')); $item->setHasError(true); } } $this->getQuote()->setIsSuperMode($oldSuperMode); return $items; }
public function testCheckQuoteItemQty() { $productId = 143; $qty = 3.5; $summaryQty = 4; $origQty = 1; $result = $this->getMock('Magento\\Framework\\Object'); $stockItemModel = $this->getStockItemModel($productId); $stockItemModel->expects($this->once())->method('checkQuoteItemQty')->with($qty, $summaryQty, $origQty)->will($this->returnValue($result)); $this->assertEquals($result, $this->model->checkQuoteItemQty($productId, $qty, $summaryQty, $origQty)); }