2014-09-29 67 views
1

我想要查询,如下所示,以从产品集合中筛选某些产品(使用属性)。Magento集合中的AND和OR条件

SELECT <attributes> 
FROM <tables & joins> 
WHERE (<some AND conditions>) OR (<some AND conditions>) 

WHERE条件应该过滤匹配或者第一组AND条件或第二组AND条件的产品。 问题是我找不到在多个AND条件之间添加OR条件的方法。 任何人都可以帮助我上面的代码在哪里使用Magento addAttributeToFilter()?或任何其他功能?

回答

1

如果我正确理解你,我认为你需要做的这样一些变化:

->addAttributeToFilter(...filter here...) 
->addAttributeToFilter(array(
    array(
     'attribute' => 'special_to_date', 
     'date' => true, 
     'from' => $dateTomorrow 
    ), 
    array(
     'attribute' => 'special_to_date', 
     'null' => 1 
    ) 
)); 

具体做法是:

...filter here... AND (special_to_date >= '2012-07-03' OR special_to_date IS NULL)...

+0

尼斯one..Thanks – Elavarasan 2015-06-12 12:50:19