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?


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) . ')'
| improve this answer | |

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.

| improve this answer | |

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.