如何同时添加AttributeToFilter AND和OR?

时间:2011-03-21 20:47:18

标签: php sql collections magento addattribute

我想制作看起来像这样的过滤器:
(伪代码)

SELECT * FROM Products WHERE 
   (`attribute_foo` LIKE 'bar' AND `attribute_bar` LIKE 'foo')
OR (`attribute_far` LIKE 'boo');

我知道如何通过提供数组来构造OR条件,而不是两者。

谢谢你

2 个答案:

答案 0 :(得分:2)

"from"=>$fromValue, "to"=>$toValue
"like"=>$likeValue
"neq"=>$notEqualValue
"in"=>array($inValues)
"nin"=>array($notInValues)
"eq"=>$equal
"nlike"=>$notlike
"is"=>$is
"gt"=>$greaterthan
"lt"=>$lessthan
"gteq"=>$greterthanequal
"lteq"=>$lessthanequal
"finset"=>$unknown
"date"=>true, "to" => $now

$collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')
        ->addFieldToFilter('entity_id', array('from'=>20, 'to'=>30))
        ->addFieldToFilter('name', array('like'=>'%cindy%'));

答案 1 :(得分:0)

您可以使用Magento数据对象进行过滤:

$product = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToFilter("attribute_code", $value);

print_r($product->getItems());