Magento addAttributeToFilter with multiple selection

I'm having problems using addAttributeToFilter on Magento Multiple select attributes.

I have a multiple choice attribute for cars, so the content is "Audi", "BMW" and so on. In my example, I have a bus product that I selected 5 for multiple selection.

I want to display products that have BMW as one of their selected fields.

I tried the following, all of which do not work:

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

Nothing is working.

+3
source share
2 answers

The solution is to use a query Find In Set, for example:

$this->_productCollection->addAttributeToFilter("make", array("finset"=>"38"));

The discussion can be seen here: http://www.magentocommerce.com/boards/viewthread/201312/

: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections

+10

, .

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

All Articles