I am making a Mage::getModel call to try and get all products in a certain category that is in stock.

$stockIds = Mage::getModel('cataloginventory/stock_item')
    ->addFieldToFilter('is_in_stock', 1)


Everything works apart from the ->addFieldToFilter('is_in_stock', 1) line. Without it all products in the category show up. With it, it's filtering some (apparently random) products out, but not based on whether it is 'In stock'. Some out-of-stock items still appears, and some in-stock items do not appear.

I have checked that all the products are enabled and all quantities are at least 10.

How do I get all products in a certain category that is in stock?


first,$stockIds don't return the product ids ,it give the stock id,basically stock table primary key. If you want to filter product collection by saleable then you need use below code:


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.