On Magento while listing categories you can sor the available products: By price, name or relevance, and ascending or descending. By default sorting of (price, name or relevance) can be configured from magento backend under catalog section however we can’t change the default sort order. Here is a XML layout update that allows you to do this as per your requirement.
XML-layouts are part of the Magento theming system. XML-updates can be applied in the GUI (for products and categories) but also through your own XML-files within the Magento theming folders.
Set Sort to Asc in Category Pages
The following XML-code will modify the default direction to asc (ascending) while the default ordering is set to price:
<reference name=”product_list”>
<action method=”setDefaultDirection”><string>asc</string></action>
<action method=”setDefaultOrder”><string>price</string></action>
</reference>
<reference name=”product_list”>
<action method=”setDefaultDirection”><string>asc</string></action>
<action method=”setDefaultOrder”><string>price</string></action>
</reference>
or use the below code if above one doesn’t wok
<reference name=”product_list_toolbar”>
<action method=”setDefaultDirection”><string>asc</string></action>
<action method=”setDefaultOrder”><string>price</string></action>
</reference>
<reference name=”product_list_toolbar”>
<action method=”setDefaultDirection”><string>asc</string></action>
<action method=”setDefaultOrder”><string>price</string></action>
</reference>
To implement the code in magento. Go to magento backend -> Catalog -> Manage Categories
Once there select the top cateogry (All Category) from left section and go to custom design. Paste the above code inside “Custom Layout Update” field and save category. Now it will by default take the same value for others.
If this method doesn’t work then you can try one more alternate method given below.
Go to /app/design/frontend/default/[Your-theme]/layout using FTP of your magento installation. Download and edit the local.xml or catalog.xml page.
Copy and paste above code inside “config” tag of local.xml and upload the file.
Don’t forgot to clear your cache after doing all these step in case result doesn’t appear as desired.
You can also change the default direction of sorting in asc or desc format by changing the file “magmodules_sortbydate.xml” under “/app/design/frontend/base/default/layout”. Just change the direction to asc or desc as per your requirement.
Leave a Reply