php Magento 集合中的 addAttributeToFilter 和 OR 条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5301231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
addAttributeToFilter and OR condition in Magento's Collection
提问by éricP
I'd like to select products depending on several criteria from different attribute.
我想根据不同属性的几个标准来选择产品。
I know how to user $collection->addAttributeToFilter('someattribute', array('like' => '%'));
我知道如何使用 $collection->addAttributeToFilter('someattribute', array('like' => '%'));
But I'd like to use several attribute for ORcondition.
但我想为OR条件使用几个属性。
Like:
喜欢:
$collection->addAttributeToFilter('someattribute', array('like' => 'value'));`
OR
或者
$collection->addAttributeToFilter('otherattribute', array('like' => 'value'));`
To get products which either 'someattribute' OR'otherattribute' set to 'value'
获取“someattribute”或“otherattribute”设置为“value”的产品
Is it possible?
是否可以?
回答by Rito
yes it is.
是的。
$collection->addAttributeToFilter(
array(
array('attribute' => 'someattribute', 'like' => 'value'),
array('attribute' => 'otherattribute', 'like' => 'value'),
array('attribute' => 'anotherattribute', 'like' => 'value'),
)
);
回答by George Donev
In case you wish to use the same thing for addFieldToFilter function for collections that are not using the EAV, then you can using the following format:
如果您希望对不使用 EAV 的集合使用相同的 addFieldToFilter 函数,则可以使用以下格式:
$collection->addFieldToFilter(
array(
'someattribute',
'otherattribute',
'anotherattribute',
),
array(
array('like' => 'value'),
array('like' => 'value'),
array('like' => 'value'),
));
回答by johnsnails
Another thing to look at to achieve 'OR" is:
实现“或”的另一件事是:
->addFieldToFilter(
'type_id',
['in' => ['simple', 'configurable']]
)
回答by Hassan Ali Shahzad
For addAttributeToFilter:
对于 addAttributeToFilter:
$collections = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('increment_id', array('in' => $sellerIncrementIds))
->addAttributeToFilter('status', ['in' => ['pending','pending_seller_confirmation']]);