php - Magento 集合中的 addAttributeToFilter 和 OR 条件

标签 php collections magento attributes

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

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

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

喜欢:

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

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

获取“someattribute”“otherattribute”设置为“value”的产品

这可能吗?

最佳答案

是的。

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

关于php - Magento 集合中的 addAttributeToFilter 和 OR 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301231/

相关文章:

php - 如何提取 HTML 并将其放入 php 关联数组中?

php - PHP 数组可以容纳不同类型的项目吗?

php - 所选日期(周一、周二、周三等)的数据

Java - 就性能而言,哪个集合最适合这种情况?

Magento - getOptionsByCode 的用途和优点

php - 如何在 Magento 中设置一个 cron 作业

php - azure应用程序url重写中的.htaccess文件

java - ArrayList.addAll 的任何空安全替代方案?

java - 为什么集合会返回无序值,即使它在内部实现了 HashMap?

mysql - Magento 重建索引问题 - 一般错误 : 1005 Can't create table (errno: 121)