0

I am using Magento 2.2.2

I have created one attribute "Retail Price". Input type for this attribute is "Price". I have added values in some products for this attribute. Now I want to load product collection based on "Retail Price" range. I have tried using the following code:

$collection = $productCollection->addAttributeToSelect('*')
                ->addAttributeToFilter('status', 1)
                ->addAttributeToFilter('retail_price' , array('from' => 501, 'to' => 700));
$collection->load();

After using the above code I didn't get any products in the result. So, what can be the issue in the above code?

| improve this question | | | | |
0

Try This :-

$collection = $productCollection->addAttributeToSelect('*')
                ->addAttributeToFilter('status', 1)
                ->addFieldToFilter('retail_price', array('gteq' => 501))
                ->addFieldToFilter('retail_price', array('lteq' => 700));
| improve this answer | | | | |
  • I have implemented your solution but it's not working. Is there any alternate solution for this? – Chintan Kaneriya May 21 '19 at 10:30
  • any error ????? – Rk Rathod May 21 '19 at 10:33
  • check updated answer – Rk Rathod May 21 '19 at 10:36
  • how can I apply greater or equal(>=)/ less or equal(<=) instead of only 'gt' and 'lt'? – Chintan Kaneriya May 22 '19 at 11:06
  • check my updated answer – Rk Rathod May 22 '19 at 12:04

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.