سؤال

example code:

$stockItem = $product->getStockItem();
$stockItem->getIsInStock()

The product is one item of a collection. Before the update I could Request the isInStock status in this way. After the Update this always returns Null.

هل كانت مفيدة؟

المحلول

The StockItem is not automatically loaded from Database anymore. You need to add the associated Data to your collection, which is also a bit more efficient then to load the data for every product separately.

You can do this via:

Mage::getModel('catalogInventory/stock')->addItemsToProducts($productCollection);

or the more efficient way, if you only want to filter them:

Mage::getModel('catalogInventory/stock')->addInStockFilterToCollection($products);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top