The best way to achieve this is by adding the following lines to the category pages layout file catalog_category_view.xml
. This file can be under the Magento_Catalog\layout
folder inside your theme folder.
<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> <referenceBlock name="product_list_toolbar"> <action method="setDefaultDirection"> <argument name="dir" xsi:type="string">desc</argument> </action> </referenceBlock> </body> </page>
These instructions call the
method in class Toolbar, and pass the value setDefaultDirection
desc
or
to the argument asc
dir
. This sets the default sort direction to descending or ascending respectively.
Don’t forget to clear your cache if you are in developer mode or deploy static content in production.