cancel
Showing results for 
Search instead for 
Did you mean: 

Sort by % Off

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Sort by % Off

Hi everyone !

 

I want to sort by % Off like below imageScreenshot from 2018-10-18 14-27-35.png

 

 

 

and here is my code 

$toolbar
->getCollection()->getSelect()
->where('ROUND(((price_index.price - price_index.final_price)/price_index.price)*100,0)')
->order('ROUND(((price_index.price - price_index.final_price)/price_index.price)*100,0) DESC');
but my code not working Smiley Sad i'm new one working on magento 2. Can you help me to fix my code or guide me to shows right order ? Thanks
2 REPLIES 2

Re: Sort by % Off

I think Magento can only filter via attributes. Create an custom attribute called "discount" and activate the option sortable and calculate the % automatically if you save theproduct. 

 

After that you can sort in the frontend with the default magento engine.

---
If my answer is useful, please Accept as Solution & give Kudos

Re: Sort by % Off

Hello @BinhXuanNguyen

 

You need to rewrite magento files,
1. add your new options to default magento filter.
2. Add your logic to product collection file which create collection for page.

Was my answer helpful? You can accept it as a solution.
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer