I want to show only products in stock, how to do this with following Magento code?

$category_model = Mage::getModel('catalog/category')->load(55);
$collection = Mage::getResourceModel('catalog/product_collection');

How to add this filter to above code?

3 Answers 3


Add below code to filter the collection

$cond = array(
    '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1',
    '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0',

    $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1';

    '(' . join(') OR (', $cond) . ')'

should do the trick, at least if you did not configure Magento to show out of stock products in the frontend. This is filtering the collection to only show products available in the current store.


This worked for me:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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