Reputation: 345
I cannot find the solution to this problem in magento tutorials. How can I implement the boolean OR operator in custom models when there are two attributes involved? The example in the official tutorial only demonstrated the use of OR boolean for one field, sku.
$filter_a = array('like'=>'a%');
$filter_b = array('like'=>'b%');
Mage::getModel('catalog/product')
->getCollection()
->addFieldToFilter('sku', array($filter_a, $filter_b))
->getSelect();
This translates to
WHERE e.sku like 'a%' or e.sku like 'b%'
But what if I need to run conditions such as :
WHERE (e.sku like 'a%' or e.sku like 'b%') or (table_price.value >= '10' )
How can I do this on Magento? Thanks
Upvotes: 2
Views: 393
Reputation: 12809
You have your syntax incorrec, try this:
Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter(
array(
array('attribute'=>'firstname', 'like'=>'test%'),
array('attribute'=>'lastname', 'like'=>'test%'),
)
)
you could replace the attribute names by 'sku' or what ever you wanted. Each array entry will be OR'd.
Upvotes: 2