Lets say I do the following:
$prod = Mage::getModel('catalog/product');
$prod->load(243);
Mage::log($prod->getStockItem()->getIsInStock());
I get 1 (eg function returns true)
However, if I do this:
$productCollection = Mage::getModel('catalog/product')->getCollection()
->setPageSize($pageSize)->setCurPage($pageIndex)
->addAttributeToSelect('*')->load();
then I iterate over the products and do
Mage::log($prod->->getStockItem()->getIsInStock());
I always get false, even for item 243 which should return true.
Why is that? and how do I load the stock item data?
(what I care about is if item is really in stock)
Thanks!
Best Answer
If you want your collection to include the inventory information, there's a flag you need to set before you load the collection.
$productCollection->setFlag('require_stock_items', true)