Php Magento集合-使用addAttributeToFilter的嵌套where子句

Php Magento集合-使用addAttributeToFilter的嵌套where子句,php,mysql,zend-framework,magento,where-clause,Php,Mysql,Zend Framework,Magento,Where Clause,我正在尝试向magento集合添加多个过滤器,我可以在基本级别上这样做。 我真正想做的是能够通过许多嵌套过滤器过滤集合,这些过滤器可以是任何级别的。例如,我知道我可以使用以下代码添加多个过滤器: $collection->addAttributeToFilter('example_attribute', array('eq' => 1)); 我希望能够做到的是使过滤器(AND&OR)可以相互嵌套。我不确定Magento collection是否已经允许您这样做,但我无法在网上找到任

我正在尝试向magento集合添加多个过滤器,我可以在基本级别上这样做。 我真正想做的是能够通过许多嵌套过滤器过滤集合,这些过滤器可以是任何级别的。例如,我知道我可以使用以下代码添加多个过滤器:

$collection->addAttributeToFilter('example_attribute', array('eq' => 1));
我希望能够做到的是使过滤器(AND&OR)可以相互嵌套。我不确定Magento collection是否已经允许您这样做,但我无法在网上找到任何示例

要给出进一步的细节和示例: 我需要筛选一个集合,其中等效SQL(忽略我需要的选定字段和联接)为:

SELECT .........

WHERE 

(attribute1 = 1
OR 
atttribute2 = 'yes')

AND
qty > 5

AND(
  (attribute3 != 'no'
  AND 
  attribute4 = 50 )
  OR
  (attribute3 != 'no'
  AND 
  attribute6 > 50 )
  )

这只是一个简单的示例,但基本问题是如何嵌套任意数量的过滤器。

您可以使用以下代码:

$collection->addAttributeToFilter(array(
array('attribute'=> 'someattribute','like' => 'value'),
array('attribute'=> 'otherattribute','like' => 'value'),
array('attribute'=> 'anotherattribute','like' => 'value'),
));
编辑: 使用此选项,您应该至少能够在查询中执行AND和OR条件。标准行为似乎不允许嵌套AND或条件。所以我假设您需要为此编写一个自定义查询。
如需进一步参考,请查看文件Mage\u Eav\u Model\u Entity\u Collection\u Abstract,其中定义了addAttributeToFilter方法。

您始终可以调用集合上的
load(true)
来回显查询,这在构造复杂查询时非常有用。