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 magento.stackexchange.com, 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 community@magento.com.

Magento Forum

Pushing out of stock to the end of product listing when sorting by price
 
joaosvu
Jr. Member
 
Avatar
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()
                ->
joinField('stock_status''cataloginventory_stock_status''stock_status''product_id=entity_id','stock_status>=0''left')
                ->
setOrder('stock_status','desc')
                ->
setOrder('news_from_date''desc');

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'{
            $this
->addAttributeToSort($attribute$dir);
        
else {
            parent
::setOrder($attribute$dir);
        
}
        
return $this;

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

Thanks.

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