【问题标题】:How to addAttributeToFilter AND and OR at the same time?如何同时 addAttributeToFilter AND 和 OR?
【发布时间】:2011-03-21 20:47:17
【问题描述】:

我想制作如下所示的过滤器:
(伪代码)

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

我知道如何通过提供数组来构造OR 条件,但不能同时提供两者。

谢谢你

【问题讨论】:

标签: php sql collections magento addattribute


【解决方案1】:
"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%'));

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-07-02
      • 2018-09-06
      • 2018-12-08
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 2013-08-26
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多