1

Magento Enterprise 1.14.2.

Notice: This question is directly related to my other question: Why does $product->getData["is_in_stock"] differ from $product->getStockItem()->getIsInStock()?

I'm trying to get a collection of all products on my site which are actually in stock:

$inStockProducts = Mage::getModel("catalog/product")
                   ->getCollection()
                   ->addAttributeToFilter("status", 1)
                   ->addAttributeToSelect("id");

Mage::getSingleton('cataloginventory/stock')
      ->addInStockFilterToCollection($inStockProducts);

However, the above collection still includes configurable products whose children are all out of stock, and whose stockItem stock status is 0 (i.e. out of stock).

It seems like this method is filtering on some kind of inaccurate indexed stock status and not the actual stock item stock status.

For example, I might get the following output from the above code:

foreach ($inStockProducts as $inStockProduct) {

    // This might output "0" even though I used the above "InStockFilter"!
    echo $inStockProduct->getStockItem()->getIsInStock();

    // And for the same product this might output "1"!
    echo $inStockProduct->getData["is_in_stock"];

}

Reindexing the stock status index (or all indexes) does not have an effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.