Changing default category sort order in Magento

17 Comments 27th FEB 2009 | Posted by Tomislav Bilic in Magento

Changing default category sort order in Magento

Category toolbar has many options. By default is shows how many items are in the category, you can choose how many products you wish to be displayed per page, you can change the listing type (List or Grid) and you may choose Sort Order. This “Sort Order” can be confusing. The default “Sort Order” is “Best Value”. What does it mean? How is the Best value determined? Can we change the default sort order?

What is “Best Value” filed?

When you go to Category page in Magento administration, you will see “Category Products” tab. From there, you will see the list of products that are associated to this category. The last column in “Position”. That is how “Best Value” is determined. So, best value is not something that is dynamically calculated. You can tailor it to your likings.
Magento Category Product List Position

How to change default Sort Order

The file you need to look at is: /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php Since we’ll modify it, make a copy to /app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

One there, you will notice this code at the beginning of the file:

$this->_availableOrder = array(
'position'  => $this->__('Best Value'),
'name'      => $this->__('Name'),
'price'     => $this->__('Price')
);

Default order takes the first value available. So, all you have to do is to either:

  • reorder it if you want to have a selection in the Toolbar or
  • set only one value of choice if you will remove the selection from the toolbar

I hope this will help somebody.

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 17 comments (Add Yours +)

  • yes, that helped. thanks!

  • I want the same but for Search Result. When I search anything in Search box, it return the Product List with Sort By option “Relevance”. I want to make “Name” as a default sort option instead of “Relevance”. Please suggest me..

  • does not work with 1.3.x
    there was an option embedded in the configuration menu for changing the sort order. in 1.3.0 there is a bug, so the sort order is alwas “best value”. updating to 1.3.1 will fix this problem.

  • For those of you who don’t want to alter the core code, adding this to the /app/design/frontend/default/[theme]/layout/catalog.xml file seems to work:

    <!-- Add this line -->
    name

    This would make your code “upgrade-proof”. Feel free to correct this if it’s wrong.

  • Thanks very very much…!!!
    its helped me so much.
    thanks i’m delight

  • Andres Galindo Says

    Just wanted yo let you know – it helped. Thanks.

  • That was great! Just changing the position number in the category products tab works perfect. This way I don’t have to be messing around with coding.

    Thanks a lot!

  • Well that doesn’t seem to work for latest Magento version.
    My toolbar.php doesn’t have any of that sort of code :-(

  • @Daniel: Yep, changed again.

  • This is bugging me as well. I can’t seem to get it to work by price.

    It’s all messed up – http://www.scalesmart.co.uk/bench-scales/counting-scales?order=price&dir=asc

    This this a Magento problem or an Andrew problem?!

  • in the last version we can set the default sort order between 3 deicded attribute best value name and price … that’s ok thank to the system config menu….. if we want to change the same about search result which is the best solution ??? which is exactly relevance ???

  • The code for $this->_availableOrder isn’t there in 1.3.2.4. Instead, it sets it to simply ‘array()’, and $this->_availableOrder is set in the construct, by calling $this->_getConfig()->getAttributeUsedForSortByArray(); This hits the database for all attributes that are considered sortable, then builds a list based on that. It’s also not possible to override it as $this->_availableOrder is also ‘reset’ when Mage_Catalog_Block_Product_List kicks in (around line 150, there’s a $toolbar->setAvailableOrders). *sigh*
    Any clues how to get around this?
    Thanks

  • toniyecla Says

    please try to comment this in app/code/core/Mage/Catalog/Model/Config.php:

    public function getAttributeUsedForSortByArray()
    {
    $options = array(
    // ‘position’ => Mage::helper(‘catalog’)->__(‘Position’)
    );
    foreach ($this->getAttributesUsedForSortBy() as $attribute) {
    /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
    $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
    }

    return $options;
    }

  • For magento 1.4 chage line 119 ( /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php )to:
    protected $_direction = ‘desc’;

  • toniyecla Says

    the tip is to avoid Position order (almost not be default) :)

    regards!

  • Well if you want to change the Default “order by” field, without coding you can in v1.4! Just from the Admin Settings.

    For individual categories go to: Catalog>Manage Categories>(Pick the Category you want to change)>Display Settings>Default Product Listing Sort by> And Select some of the available fields

    For the Global setting go to: System>Settings>Catalog>Frontend>Product listing sort by

    Also, you can use custom fields to use as “order by”. In your Attribute creation there is the option “Used for sorting in product listing”. Set this to YES, and you will be able to sort your products by your custom Field (Attribute).

  • Thanx a lot….

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009