Magento – Sort Products by Newest First

30th July 2016

Magento is a great eCommerce platform with loads of great features but one thing clients have asked me in the past is can their customers sort products by newest first? Clients have some of options built in Magento to sort products but unfortunately sorting by date added is not an out of the box option in Magento. Currently the options Magento offer you are Best Value, Name and Price. Not Price - Low > High and Price - High > Low, it is just price. The same goes for name, no A – Z, just name.

In this blog post I will be exploring how to customise these sorting options, allowing you to include sorting by Newest and amending price to Price - Low > High and Price - High > Low. Options that will be far more useful for your customers.

 

Lets take a look at creating a Newest filter. There are 2 files you will need to edit to create this functionality.

It is advised to recreate all of the files modified in core in the local folder to ensure that nothing is overridden if you update Magento.

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

Around line 119 change the following…

to…

This will set the default sort order or all filters to ascending.

Find the function setDefaultOrder around line 386 and change to the following…

2 – /app/design/frontend/YOURPACKAGE/YOURTHEME/template/catalog/product/list/toolbar.php

Find the class sort-by. This is where the filter drop down is generated. We are going to replace this with our own dropdown.

Replace the current sort-by div with the following…

This code uses your new created_at filter as the default for the filter drop down as well as adding the option for customers to filter Price Low > High or Price High > Low. These second 2 options are achieved by the addition of the asc/desc within the getOrderUrl function.

 

There you have it, clear your browser cache and cookies and Mangeto cache and you should see the categories listing by default as Newest first. You can see it in action on this Magento store I built. If you are interested in any bespoke Magento features for your store then get in touch.

Leave a Reply

Your email address will not be published. Required fields are marked *