2014-09-29 69 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