One big problem with Magento is that when products become out of stock they still show up on top in the product listing and this can get very annoying for some users if there are several products out of stock. This very easy code fix will automatically make products that are out of stock show up last in all your categories and search results.
Go to the following folder in Magento where you will find List.php
/app/code/core/Mage/Catalog/Block/Product/List.php
If you don’t want to change the core files, which is always a bad habit then copy the file to
/app/code/local/Mage/Catalog/Block/Product/List.php
Find the following around line 86.
And change it to
Now clear cache from admin and check your listing page.
Go to the following folder in Magento where you will find List.php
/app/code/core/Mage/Catalog/Block/Product/List.php
If you don’t want to change the core files, which is always a bad habit then copy the file to
/app/code/local/Mage/Catalog/Block/Product/List.php
Find the following around line 86.
$this->_productCollection = $layer->getProductCollection();
And change it to
$this->_productCollection = $layer->getProductCollection()
->joinField(
'inventory_in_stock',
'cataloginventory_stock_item',
'is_in_stock',
'product_id=entity_id',
'is_in_stock>=0',
'left')
->setOrder('inventory_in_stock','desc');
Now clear cache from admin and check your listing page.
