【问题标题】:Magento both AND and OR conditions in a collectionMagento 集合中的 AND 和 OR 条件
【发布时间】:2014-11-23 09:41:29
【问题描述】:

我想进行如下所示的查询,以从产品集合中过滤一些产品(使用属性)。

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

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

【问题讨论】:

    标签: magento collections filter multiple-conditions


    【解决方案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 &gt;= '2012-07-03' OR special_to_date IS NULL)...

    【讨论】:

      猜你喜欢
      • 2011-07-15
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多