0

I'm trying to set a default sort order to products listing in category page.

I have seen people suggest using

            <action method="setDefaultOrder">
                <argument name="sort" xsi:type="string">name</argument>
            </action>
                <action method="setDefaultDirection">
                    <argument name="dir" xsi:type="string">asc</argument>
                </action>

or by using

            <action method="setSortBy"><string>name</string></action>
                <action method="setDefaultDirection">
                    <argument name="dir" xsi:type="string">asc</argument>
                </action>

Unfortunately none of the above method worked for me. But I just want to know what's the different between setDefaultOrder and setSortBy?

1 Answer 1

1

Not sure where you've got one of those snippets from

https://www.customerparadigm.com/changing-default-product-sorting-in-magento-2/

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

<?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">
        <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>
    </page>

That's to change sort by direction

To change sort by value

Stores > Config > Catalog > Catalog > Storefront > Product Listing Sort By

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.