Magento 集合中的 addAttributeToFilter 和 OR 条件

2021-12-19 00:00:00 attributes collections php magento

我想根据不同属性的几个标准来选择产品.

I'd like to select products depending on several criteria from different attribute.

我知道如何使用 $collection->addAttributeToFilter('someattribute', array('like' => '%'));

但我想为 OR 条件使用多个属性.

But I'd like to use several attribute for OR condition.

喜欢:

$collection->addAttributeToFilter('someattribute', array('like' => 'value'));`

$collection->addAttributeToFilter('otherattribute', array('like' => 'value'));`

获取someattribute"或otherattribute"设置为value"的产品

To get products which either 'someattribute' OR 'otherattribute' set to 'value'

有可能吗?

推荐答案

是的.

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

相关文章