In order to change default sort order from ascending to descending in Magento 2, first 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 into your theme.
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>Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!


Leave a Reply