How to sort magento products by newest product

This FAQ will show you how to easily sort your Magento products by newest product first.

Copy app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

upload the copy to:

app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php (create a folder if it doesn’t exist already)

Now open the newly copied file and look for this line of code around line 232:

if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}

Replace it with the following:

if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){
$this->_collection->setOrder('entity_id','desc');
}
else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

Save your file, flush the Magento site caches and update your Magento indexes.

 

Nina Young About the author

I studied mathematics at university, taught myself software development, honed my skills with multinational companies such as IBM and have set up and sold my own businesses. My perspective covers the all important period when a business moves from small and successful to substantial and market-leading, and my personal experience allows me to provide online solutions that give business leaders mastery of their online presence and control over business development.

No Comments

Post a Comment