Magento – Change default order by in category list - Sulopa Solutions
single,single-post,postid-16270,single-format-standard,,-,ajax_fade,page_not_loaded,qode-theme-ver-5.9,wpb-js-composer js-comp-ver-4.3.4,vc_responsive

Magento – Change default order by in category list

22 Jul Magento – Change default order by in category list

Magento category listing is ordered by ascending by default installation. Under the attribute settings, we can easily manage the element listing used to sort the products, but changing the sort order to descending requires to add a line of code in layout.xml file.

Category page layout is handled by the catalog.xml file. Just an action tag can change the game.

Start Editing

Follow these steps.

  1. Open the file  app/design/frontend/package_name/theme_name/layout/catalog.xml
  2. Find the block code <block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”> somewhere near line 122. Its under the <catalog_category_layered translate=”label”> handle.
  3. Now add this line <action method=”setDefaultDirection”><direction>desc</direction></action> beneath the above searched block and its done.
  4. We have added an action tag inside the block.
  5. This is for the category type anchor. We need to repeat the task for the default category layout as well.
  6. Find the block code <block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”> somewhere near line 90 under the <catalog_category_default translate=”label”> layout handle.
  7. Add the same code <action method=”setDefaultDirection”><direction>desc</direction></action>.

Save the file.

Final output will look similar to this.


Whats next.

Clear you cache and re-index data. The products will be ordered descending in catalog.

How it works

Catalog listing toolbar template is handled by the block app/code/core/Mage/Catalog/Product/Block/Product/List/Toolbar.php.This class has a variable protected $_direction = ‘asc';. A method setDefaultDirection() is used to set the default direction. Using the above given code, we are calling the same method and assigning the desc to $_direction variable.


Jenny Tran
No Comments

Post A Comment