- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2018
12:32 AM
10-18-2018
12:32 AM
Sort by % Off
Hi everyone !
I want to sort by % Off like below image
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
i'm new one working on magento 2. Can you help me to fix my code or guide me to shows right order ? Thanks

Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2018
07:06 AM
10-18-2018
07:06 AM
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
If my answer is useful, please Accept as Solution & give Kudos
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2018
04:43 AM
10-19-2018
04:43 AM
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
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer