Timeline for "Call to a member function getIsInStock() on null" with getExtensionAttributes()->getStockItem()
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 19, 2018 at 13:02 | comment | added | Jaisa | I m using I am using Magento\Catalog\Model\Product.php in my block to get the product collection | |
| Feb 19, 2018 at 13:01 | comment | added | Jaisa | I need to check stock status whether the product is in stock or out of stok | |
| Aug 4, 2016 at 3:31 | comment | added | mrtuvn | where i can find method getQuantityAndStockStatus define? | |
| Aug 2, 2016 at 21:51 | comment | added | Ruud N. | Alternatively you can use the \Magento\CatalogInventory\Api\StockItemRepositoryInterface to just load the stock item seperately, like this: $this->_stockItemRepository->get($product->getQuantityAndStockStatus())->getIsInStock() | |
| Aug 2, 2016 at 21:13 | comment | added | Fabian Schmengler | Thanks, I'll probably resort to collections again for more flexibility | |
| Aug 2, 2016 at 21:10 | comment | added | Ruud N. | Correct. You can't call isInStock() on the items, since they'll always return 1, even if they're not in stock and you also can't use getStockData() since that'll return NULL. As far as I know stock data isn't included in the product list items. | |
| Aug 2, 2016 at 21:00 | comment | added | Fabian Schmengler | But this will trigger another full product load, right? The repository methods are slow enough already, triggering the classic "load in a a loop" is not an option for me. | |
| Aug 2, 2016 at 20:57 | history | answered | Ruud N. | CC BY-SA 3.0 |