コード例 #1
0
 /**
  * @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];
 }
コード例 #2
0
 /**
  * @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;
 }