Search code examples
phpxmlmagentomagento2magento-layout-xml

How to set default product sort direction (asc/desc) for few categories only through xml


In Magento 2 how I can set default product sort direction (asc/desc) for specific categories through layout update xml of Manage Categories ->Specific Category-> Design section. Like I did in screenshot... But its not working :(enter image description here


Solution

  • You just need to change referenceblock name to "product_list_toolbar". because we dont have setDefaultDirection method in Magento\Catalog\Block\Product\ListProduct class. after update your code will become like this

    <referenceContainer name="content">
      <referenceBlock name="product_list_toolbar">
              <action method="setDefaultDirection">
                  <argument name="dir" xsi:type="string">desc</argument>
                </action>
      </referenceBlock>
    </referenceContainer>
    

    please let me know if you have any queries.