1

I am showing new and featured products on my home page. I'd like to show only products that are on stock. If a product is marked as new or featured it will be shown here only if it is on stock (have stock greater than zero).

This requirement is just for home page, on other pages I'd like to show out of stock products.

This method don't work: System/Configuration/Catalog/Inventory/Display Out of Stock Products - NO

How can I do that?

Thank you!

2

Marius,

Please reindex from admin>System>Index Management.

Basically,You can filter any product collection by

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

but it depends on System/Configuration/Catalog/Inventory/Display Out of Stock Products -NO

If not work then try this

/* $collection=Your Product 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';

        $collection->joinField(
            'inventory_in_stock',
            'cataloginventory/stock_item',
            'is_in_stock',
            'product_id=entity_id',
            '(' . join(') OR (', $cond) . ')'
        );
  • The first method solved my problem. Thank you! – Marius Mar 8 '15 at 21:49

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.