/** * @param int|null $scopeId * @return \Magento\CatalogInventory\Api\Data\StockInterface */ public function getStock($scopeId) { if (!isset($this->stocks[$scopeId])) { $criteria = $this->stockCriteriaFactory->create(); $criteria->setScopeFilter($scopeId); $collection = $this->stockRepository->getList($criteria); $stock = current($collection->getItems()); if ($stock && $stock->getStockId()) { $this->stocks[$scopeId] = $stock; } else { return $this->stockFactory->create(); } } return $this->stocks[$scopeId]; }
/** * @param int|null $scopeId * @return \Magento\CatalogInventory\Api\Data\StockInterface */ public function getStock($scopeId) { $stock = $this->stockRegistryStorage->getStock($scopeId); if (null === $stock) { $criteria = $this->stockCriteriaFactory->create(); $criteria->setScopeFilter($scopeId); $collection = $this->stockRepository->getList($criteria); $stock = current($collection->getItems()); if ($stock && $stock->getStockId()) { $this->stockRegistryStorage->setStock($scopeId, $stock); } else { $stock = $this->stockFactory->create(); } } return $stock; }