/** * @inheritdoc */ public function getLowStockItems($websiteId, $qty, $currentPage = 1, $pageSize = 0) { $criteria = $this->criteriaFactory->create(); $criteria->setLimit($currentPage, $pageSize); $criteria->setWebsiteFilter($websiteId); $criteria->setQtyFilter('>=', $qty); $criteria->addField('qty'); return $this->stockItemRepository->getList($criteria); }
/** * Detect current stock and get appropriate stock item. * * @param \Magento\CatalogInventory\Model\StockRegistryProvider $subject * @param \Closure $proceed * @param int $productId * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ public function aroundGetStockItem(\Magento\CatalogInventory\Model\StockRegistryProvider $subject, \Closure $proceed, $productId, $scopeId) { $result = $this->_storageStockRegistry->getStockItem($productId, $scopeId); if (null === $result) { $criteria = $this->_factoryStockItemCrit->create(); $criteria->setProductsFilter($productId); $stockId = $this->_toolStockManager->getCurrentStockId(); $criteria->setStockFilter($stockId); $collection = $this->_repoStockItem->getList($criteria); $result = current($collection->getItems()); if ($result && $result->getItemId()) { $this->_storageStockRegistry->setStockItem($productId, $scopeId, $result); } else { $result = $this->_factoryStockItem->create(); } } return $result; }
public function testGetStockItem() { $this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockItemCriteria); $this->stockItemCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null); $stockItemCollection = $this->getMock('\\Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item\\Collection', ['getFirstItem', '__wakeup', 'getItems'], [], '', false); $stockItemCollection->expects($this->once())->method('getItems')->willReturn([$this->stockItem]); $this->stockItemRepository->expects($this->once())->method('getList')->willReturn($stockItemCollection); $this->stockItem->expects($this->once())->method('getItemId')->willReturn(true); $this->assertEquals($this->stockItem, $this->stockRegistryProvider->getStockItem($this->productId, $this->scopeId)); }
/** * @param int $productId * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ public function getStockItem($productId, $scopeId) { $key = $scopeId . '/' . $productId; if (!isset($this->stockItems[$key])) { $criteria = $this->stockItemCriteriaFactory->create(); $criteria->setProductsFilter($productId); $collection = $this->stockItemRepository->getList($criteria); $stockItem = current($collection->getItems()); if ($stockItem && $stockItem->getItemId()) { $this->stockItems[$key] = $stockItem; } else { return $this->stockItemFactory->create(); } } return $this->stockItems[$key]; }
/** * @param int $productId * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ public function getStockItem($productId, $scopeId) { $stockItem = $this->stockRegistryStorage->getStockItem($productId, $scopeId); if (null === $stockItem) { $criteria = $this->stockItemCriteriaFactory->create(); $criteria->setProductsFilter($productId); $collection = $this->stockItemRepository->getList($criteria); $stockItem = current($collection->getItems()); if ($stockItem && $stockItem->getItemId()) { $this->stockRegistryStorage->setStockItem($productId, $scopeId, $stockItem); } else { $stockItem = $this->stockItemFactory->create(); } } return $stockItem; }