Reputation: 23
I want to select products collection with condition "A or (B and C)" by using AddAttributeToFilter, but I have no idea..
Can someone help me?
Upvotes: 1
Views: 1635
Reputation: 970
$collection = Mage::getModel('xyz/abc')->getCollection();
$collection->addAttributeToFilter(
array(
array('attribute'=> 'someattribute','like' => 'value'),
array('attribute'=> 'otherattribute','like' => 'value'),
array('attribute'=> 'anotherattribute','like' => 'value'),
)
);
$collection->addAttributeToFilter('status', array('eq' => 1));
Transnational will be look like
WHERE ((someattribute LIKE 'value') OR (otherattribute LIKE 'value') OR (anotherattribute LIKE 'value')) and status=1
You can also visit this link for more info
Magento addFieldToFilter: Two fields, match as OR, not AND
Upvotes: 1