I want to sort my collection by discount percentage for my sale category, I don't know if it is possible in Magento

  • Can you please add some code that you have tried? – Rizwan Khan Feb 10 '19 at 5:51
  • Why do I need code to do this? I thought it could be done using backend – Atif Ameer Feb 10 '19 at 12:44

You need to create a new attribute like discount_per or something like this. Using Import assign percentage values in this attribute.

Now in attribute description on Storefront Properties tab 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 "Discount Per" in "Default Product Listing Sort By" dropdown (Discount per is the attribute that you have just created)

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>

That would be all. Hope you find your solution

  • It was not working before. But after your edit on answer, it is working now. Thanks bro! – Atif Ameer Feb 13 '19 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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