12 use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory;
25 private $criteriaInterfaceFactory;
30 private $stockItemRepository;
35 private $stockConfiguration;
45 StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory,
49 $this->criteriaInterfaceFactory = $criteriaInterfaceFactory;
51 $this->stockConfiguration = $stockConfiguration;
65 $criteria = $this->criteriaInterfaceFactory->create();
67 $criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId());
68 $stockItemCollection = $this->stockItemRepository->getList($criteria);
69 foreach ($stockItemCollection->getItems() as
$item) {
72 $productExtension =
$product->getExtensionAttributes();
73 $productExtension->setStockItem(
$item);
74 $product->setExtensionAttributes($productExtension);
__construct(StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory, StockItemRepositoryInterface $stockItemRepository, StockConfigurationInterface $stockConfiguration)
execute(Observer $observer)