Home » Magento tutorial for developer » How to sort product order in Magento category

How to sort product order in Magento category

In this tutorial, we will go throw on how to sort product in a category and how to setup different types of sorting. We will also see how to set default sorting in product collection e.g if we want to sort products in ascending order by price,name etc.
By default, the product sorting drop-down in category page is shown in:

magento product sort in category 2

Assuming that we want to add/remove sorting options from the drop-down go to the Admin -> Manage Categories and then edit the current category, there go to the “Display Settings” Tab. There will see the list of sorting attributes that show up in the category page drop down, and you can also see an option to select default sorting method.
magento product sort in category-

How to add extra sorting options?

In case you want to add more sorting options, go to Catalog -> Attributes -> Manage Attributes in admin. Open the edit page of the attribute which you want to add to sort. There in the “Font-end Properties” box you will get the option for “Used for Sorting in Product Listing”, make this drop down as Yes and then this attribute will show up on the Manage Category Page. 

Manage Category Page

Manage Category Page

Custom Product Sorting In Category Page

Assuming that we want to add a custom product sorting option, like sort product by created date or update date. For this we need to add some code.
Let’s take a simple example first i.e need to sort product by created_date. First will add an option to our drop down.

For this open the file Mage_Catalog_Model_Config and we need to make changes to the function  getAttributeUsedForSortByArray().

Note:You need to override this class to make the changes

Next we need to make changes to the our collection, so that products are sorted by our custom drop down value. But right now, since ‘created_at’ is already a product attribute, we don’t need to make changes anywhere else.

Let’s take another example where we will sort products by number of reviews.

Since review is not a product attribute, we need to make changes to our product collection. Rest everything is same as far as adding option to drop down is concerned.
For this open file Mage_Catalog_Block_Product_List_Toolbar and around line 221 there is a function ‘setCollection’. You need to override this class in your module and then change the ‘setCollection’ function to

As you can see we have added a new function to the product collection sortByReview(), so we need to implement this function. For this we will override the product collection class and add the function sortByReview().

The sortByReview function is given below

Good luck with the coding!

About Brian Wilson

Brian is a freelance Magento developer with 5 years of experience with customizing Magento extensions, magento themes. He's interested in sharing Magento Tutorials to the community


  1. avatar

    Hi! Brian

    I am having a difficult time getting the images I post on the HOME PAGE of this website (posters-usa.com), to load from the top of the page to the bottom, or to load randomly. I have tried using the “position” option, but that doesn’t seem to work either. Do you have any suggestions?
    Best regards,
    Ray Martel
    email address:

  2. avatar

    Hey, thanks for the post! Have you tested the code on Magento 1.9?
    I have 2 options now: either to use code for adding 4 different sorting options to my store or use a ready extension like that one https://amasty.com/improved-sorting.html

  3. avatar

    Hi Brian,

    I tried the above procedures, It really worked. Now i can able to sort the products by it reviews. I came across a new extension available in the magento market. It gives you option to drag and drop the products to the position as we wish. We can do that in the manage categories section itself. Please find the link below….


    Hope this will helps somebody else :)

    thanks a lot

  4. avatar

    Great post, I would like to share a extension for the people like me who has less technical know-how and want to have improved sorting options in their stores.


Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top