/** * @param int $stockId * @return StockInterface * @throws NoSuchEntityException */ public function get($stockId) { $stock = $this->stockFactory->create(); $this->resource->load($stock, $stockId); if (!$stock->getId()) { throw new NoSuchEntityException(__('Stock with id "%1" does not exist.', $stockId)); } return $stock; }
/** * Add Stock items to product collection * * @param EventObserver $observer * @return $this */ public function addInventoryDataToCollection($observer) { $productCollection = $observer->getEvent()->getProductCollection(); $this->_stockFactory->create()->addItemsToProducts($productCollection); return $this; }
/** * Load some inventory configuration settings * * @return void */ protected function _initConfig() { if (!$this->_isConfig) { $configMap = array('_isConfigManageStock' => \Magento\CatalogInventory\Model\Stock\Item::XML_PATH_MANAGE_STOCK, '_isConfigBackorders' => \Magento\CatalogInventory\Model\Stock\Item::XML_PATH_BACKORDERS, '_configMinQty' => \Magento\CatalogInventory\Model\Stock\Item::XML_PATH_MIN_QTY, '_configNotifyStockQty' => \Magento\CatalogInventory\Model\Stock\Item::XML_PATH_NOTIFY_STOCK_QTY); foreach ($configMap as $field => $const) { $this->{$field} = (int) $this->_scopeConfig->getValue($const, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } $this->_isConfig = true; $this->_stock = $this->_stockFactory->create(); $this->_configTypeIds = array_keys($this->stockItemService->getIsQtyTypeIds(true)); } }