1

I want to apply multiple price ranges on final price of product collection. I have tried below code.

$collection->addFinalPrice();
$collection->getSelect()
->where('price_index.final_price <= ' . $maxprice)- 
>where('price_index.final_price >= ' . $minprice);

But from above method i can only apply one range to it. Also price range is dynamic. It can be one or more than one. I found following solution regarding my problem

->addFieldToFilter('final_price', 
 array(array('from'=>'0','to'=>'5000'), 
 array('from'=>'15000','to'=>'20000')))

But addFieldToFilter is not working on $collection. Any help will be appreciated.

0

You can pass more complex conditions to the where() method and there is also a orWhere method which appends the condition with OR.

For example this should do what you expect:

$collection->getSelect()
->where(diy_kit_price >= 0 AND diy_kit_price <= 5000) 
->orWhere(diy_kit_price >= 15000 AND diy_kit_price <= 20000);
  • Thanks it helped! There is just little problem as i mentioned price ranges are dynamic that's why when i am going through ranges in a loop i have to check if it's a first iteration than use ->where else ->orWhere. Which feels odd to me. – Bharat Singh Feb 13 at 7:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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