Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

Pushing out of stock to the end of product listing when sorting by price
Jr. Member
Total Posts:  7
Joined:  2011-04-08

Hi, I’m customizing some things on a store and I’m in a challenge to “push” all out of stock products to the end of each listing page. I already got it for almost all parameters for sorting, except by price. I made the following change on file /app/code/local/mage/Catalog/Block/Product/List.php:

Changed this:

$this->_productCollection $layer->getProductCollection();

For this:

$this->_productCollection $layer->getProductCollection()

By this way, the products always will be sorted considering first their stock status and the date which they were associated to be a new product, and this is working fine for a lot of sorting options, like Best Sellers or Newest or Name. However, when I sort by price, this doesn’t work and all out of stock products are being shown. I have looked at my file /app/code/local/Mage/Catalog/Model/Resource/Product/Collection.php and, after function “setOrder” is open, there is an if:

if ($attribute == 'price'{
else {
return $this;

Where can I fix this in order to make my first code work with price sorting too?


Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top