1

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

1
  • did you solve your issue? Commented Jan 31, 2019 at 5:01

2 Answers 2

1

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

14
  • 1
    Bother Jazak allah , Allah bless you my brother , Thank you so much !!!
    – shezan
    Commented Jan 31, 2019 at 8:59
  • You are welcome :) Commented Jan 31, 2019 at 9:33
  • There has been an error processing your request Exception printing is disabled by default for security reasons. Error log record number: 779110403205
    – shezan
    Commented Jan 31, 2019 at 9:34
  • Please check error detail in var/report/779110403205 file Commented Jan 31, 2019 at 9:35
  • the page do not load and shows error. when i use sort by Quantity...There has been an error processing your request Exception printing is disabled by default for security reasons. Error log record number: 779110403205
    – shezan
    Commented Jan 31, 2019 at 9:36
0

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.

Your Answer

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

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