Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento addAttributeToFilter具有多个选择_Magento_Addattribute - Fatal编程技术网

Magento addAttributeToFilter具有多个选择

Magento addAttributeToFilter具有多个选择,magento,addattribute,Magento,Addattribute,在Magento多个选择属性上使用addAttributeToFilter时遇到问题 我对汽车品牌有一个多选属性,所以内容是“奥迪”、“宝马”等等。在我的例子中,我有一个轮胎产品,我从多重选择中选择了5个品牌 我想展示将make“BMW”作为其选定领域之一的产品 我尝试了以下所有方法,但均无效: $products->addAttributeToFilter('make', array('like' => '%BMW%')); $products->addFieldToFi

在Magento多个选择属性上使用addAttributeToFilter时遇到问题

我对汽车品牌有一个多选属性,所以内容是“奥迪”、“宝马”等等。在我的例子中,我有一个轮胎产品,我从多重选择中选择了5个品牌

我想展示将make“BMW”作为其选定领域之一的产品

我尝试了以下所有方法,但均无效:

$products->addAttributeToFilter('make', array('like' => '%BMW%'));  
$products->addFieldToFilter('make', array('like' => '%BMW%'));  
$products->addAttributeToFilter('make', array('like' => '%38%')); // id of the attribute option

似乎什么都不起作用。

解决方案是使用
在集合中查找查询,例如:

$this->_productCollection->addAttributeToFilter("make", array("finset"=>"38"));
这里可以看到一个讨论:


还有一个不同选项的列表:

试试下面的语法,让它为我工作

$collection->addAttributeToFilter($attribute,
    array(
        array('finset'=> array('237')),
        array('finset'=> array('238')),
        array('finset'=> array('239')),
    )
);

是否执行$products->addAttributeToFilter('make','38')或$products->addAttributeToFilter('make',array('eq',38));给你什么?没用。由于它是一个多选属性,Magento将“make”创建为如下字符串:28,30,35,38-因此,如果我需要通过BMW筛选id为38的产品,那么我需要它来检查所有这些值。finset
me是否有一个选项?类似于
$products->addAttributeToFilter(“make”、array(“finset”=>“38”)谢谢Alex,这似乎有效!我发现这也适用于常规下拉列表,而不仅仅是多选。我不确定是否有定期下降速度下降或没有。根据ee 1.14.2进行测试