2013-03-16 119 views
0

下面的代碼:過濾magento集合?

$collection->addAttributeToFilter(array(
        array('attribute'=> 'someattribute','like' => 'value'), 
        array('attribute'=> 'otherattribute','like' => 'value'), 

      )); 

創建查詢是這樣的:

  where (someattribute like 'value' OR otherattribute like 'value') 

,但我怎麼能添加AND條件這樣或條件?我的意思是這樣的:

 where ((someattribute like 'value' AND someattribute != 'another value') OR otherattribute like 'value') 

我使用addAttributeToFilter多次在我收藏的建設,但是,我想用下面的代碼添加上述條件:

$collection->getSelect->where("(someattribute like 'value' AND someattribute != 'another value') OR otherattribute like 'value')" ) 

但它的不工作。也許不可能使用addAttributeToFilter AS以及在同一個集合中的哪個位置?

提前很多感謝

回答

0

OK,它的工作...有一個在條件語句一些錯誤,我增加

的話,你可以使用addAttributeToFilter也「其中」同一Magento的集合。無論如何,也許它會幫助別人爲好,這樣的解決方案,但仍然不知道你是否能複製上述條件地方只使用addAttributeToFilter ...

0

根據定義的:

->addAttributeToFilter(array(
       array('attribute'=> 'someattribute','like' => 'value'), 
       array('attribute'=> 'otherattribute','like' => 'value'), 

     ) 

這是A或選擇有AND使用:

->addAttributeToFilter(array('attribute'=> 'someattribute','like' => 'value'))->addAttributeToFilter(array('attribute'=> 'otherattribute','like' => 'value'))