How to Change Default Sort Order in Magento 2?

In this tutorial, you will go through how to change default product sort order in Magento 2.

In Magento 2, the default sorting order is ascending, but what if you would like to set it to descending by default? While it would seem like this would be a simple admin configuration, you actually have to edit a .xml file to get this functionality.

Change Default Sort Order in Magento 2

First of all, You need to copy

vendor/magento/module-catalog/view/frontend/layout/catalog_category_view.xml to

app/design/frontend/{{Vender_Namespace}}/{{Theme_Name}}/Magento_Catalog/layout/catalog_category_view.xml

Now copy below code to your new xml file.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<referenceBlock class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list">
<action method="setDefaultDirection">
<argument name="dir" xsi:type="string">desc</argument>
</action>
</referenceBlock>
</referenceContainer>
<move element="category.view.container" destination="content" before="-"/>
</body>
</page>

That’s it !!


I hope you like this post, Please feel free to comment below, suggestion and problems!

(Visited 3 times, 1 visits today)
Chandra Kumar

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

0 Comment

Leave a Comment

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