In magento frontend i want to sort products by maximum quantity first to lower number of stock (Quantity sort in descending order)
Please advise which module to be made and where to save the files i am using magento 2.3.0
In magento frontend i want to sort products by maximum quantity first to lower number of stock (Quantity sort in descending order)
Please advise which module to be made and where to save the files i am using magento 2.3.0
Go to attributes settings
Store -> Attributes -> Products
Open attribute with the lable "Quantity"
Open tab: "Storefront Properties"
Set "Used for Sorting in Product Listing" to "Yes" and save it
Open category where you want your sorting.
Catalog -> Categories
Open your category, now open "Display settings" tab and set "Quantity" in "Default Product Listing Sort By" dropdown
Now to add descending sorting, open tab "Design" and add this xml code here
<referenceContainer name="content">
<referenceBlock name="product_list_toolbar">
<action method="setDefaultDirection">
<argument name="dir" xsi:type="string">desc</argument>
</action>
</referenceBlock>
</referenceContainer>
Refresh frontend category page and see if it is working. I personally implemented this it was working for me.
Hope you find your solution
shoaib bhai asalamu alikum thank you so much i finally found the solution after one year
store > configuration > catalog > storefront > Use Flat Catalog Category (NO) if the flat category will be yes then it wont let product be sorted by quantity. i realized it when i updated the products and did not performed reindexing due to which it worked fine but once i reindexed sort by quantity starting acting as sort by position.
It is very important to keep Flat catalog category OFF.