Thursday, September 8, 2011

Magento: Out of stock pushed to the end of the list

Magento allows sorting by Position, Price and Name in the toolbar.

But It does not look at the status of product and if the product is available. Under normal circumstances, I would not like to show any of the products which are not available but due to SEO reasons, it makes sense to continue showing the products. So I would like to continue showing the products based on one of the sorting method but pushing the out-of-stock product at the end.

To do this a good post is http://www.magentocommerce.com/boards/viewthread/203590/#t345652

A more elegant solution is to make changes in .../Mage/Catalog/Model/Layer.php at line #102
$collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','is_in_stock>=0', 'left')->setOrder('inventory_in_stock', 'desc');

This will effect both the listing as well as the results page.

Another things is to remember to copy this file from core to code/local//Mage/Catalog/Model/Layer.php so that the core files remain as it is.

5 comments:

  1. it works fine but didn't work on price sort any clue

    ReplyDelete
  2. how can we make it to work on price ?

    ReplyDelete
  3. Does not work with bundle

    ReplyDelete
  4. In Bundle the inventory is choosen dynamically and hence does not work as it expects the attribute stock to be set.

    If you want to make bundles work, you will need to manage the bundle inventory manually, which will also painful.

    ReplyDelete
  5. hello

    thank you for the so useful post

    stock status for products is a very important part of ecommerce.
    to simplify manage products status
    http://amasty.com/custom-stock-status.html

    ReplyDelete