1

I read many posts and articles but still didn't find a solution.

I would like to filter my product collection with this condition:

... 
WHERE ('supplier_id' = 1 AND 'product_type' = 'first_type') 
OR ('supplier_id' = 2 AND 'product_type' = 'another_type') 
...

Is it possible to achieve this using addFieldToFilter method?

Any other suggestions are welcome as well!

  • use getSelect()->where() to work around it. – Rahul Singh Jan 24 at 5:18
0

Can you try by this way, I think this will solve your problem

->getSelect()->where(" (`Your attribute` = 'Value' AND `Your attribute` = 'Value') OR (`Your attribute` = 'Value' AND `Your attribute` = 'Value')");

In your case in the getSelect() could be:

->getSelect()->where("(`supplier_id` = '1' AND `product_type` = 'first_type') OR (`supplier_id` = '2' AND `product_type` = 'another_type')");
  • Can I get any working example? I am not really sure how to implement it, cause I am getting empty array or error. And again, there is no much information on Google. My whole query looks like this: $products = Mage::getResourceModel('catalog/product_collection')->getSelect()->where("(supplier_id = '1' AND product_type = 'first_type') OR (supplier_id = '2' AND product_type = 'another_type')"); – user3088867 Jan 24 at 11:28
  • first you check what you getting in collection, whether 'another_type' 'first_type' or 'supplier_id' attribute exist or not – Rahul Singh Jan 24 at 12:23

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.