I try to access stock data for a product, using
$product->getExtensionAttributes()->getStockItem()->getIsInStock()
and receive the following error on this line
PHP Fatal error: Call to a member function getIsInStock() on null.
Obviously the stock_item
extension attribute was not loaded. $product
comes from the product repository and has been loaded with $productRepository->getList()
.
How can I get products with stock information from the product repository?