diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index d656a0a9ac5b4..38ce6ed2b30cc 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -36,6 +36,11 @@ */ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterface { + /** + * @var \Magento\CatalogInventory\Api\StockRegistryInterface + */ + protected $stockRegistry; + /** * @var \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface */ @@ -208,6 +213,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( + \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, ProductFactory $productFactory, \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $initializationHelper, \Magento\Catalog\Api\Data\ProductSearchResultsInterfaceFactory $searchResultsFactory, @@ -234,6 +240,7 @@ public function __construct( ReadExtensions $readExtensions = null, CategoryLinkManagementInterface $linkManagement = null ) { + $this->stockRegistry = $stockRegistry; $this->productFactory = $productFactory; $this->collectionFactory = $collectionFactory; $this->initializationHelper = $initializationHelper; @@ -647,6 +654,9 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr ), $product ); + $productExtension = $product->getExtensionAttributes(); + $productExtension->setStockItem($this->stockRegistry->getStockItem($product->getId())); + $product->setExtensionAttributes($productExtension); } return $searchResult;