0

I trying to filter a product collection based on an attribute which is a multi-select attribute. here is my code,

$collection2 = Mage::getModel('catalog/product')->getCollection();

$collection2->addAttributeToSelect('name'); 
$collection2->addAttributeToSelect('manufacturer');
$collection2->addAttributeToSelect('printer_family');
$collection2->addAttributeToSelect($attributeCode);

$collection2->addFieldToFilter(array(
array('attribute'=>'manufacturer','eq'=>$ctname), 
)); 


$collection2->addFieldToFilter(array(
array('attribute'=>'printer_family','eq'=>$value), //this filter is not working
)); 

the variable $value is retrieved as follows

$product->getAttributeText($attributeCode);

can anyone tell me what i am doing wrong?

1

Just change

->addFieldToFilter(array(
array('attribute'=>'printer_family','eq'=>$value), //this filter is not working
)); 

to

addFieldToFilter('printer_famil',
    array(
        array('finset'=> array($val1)),
        array('finset'=> array($val2)),
        array('finset'=> array($val3)),
    )
);

Check the links:

https://jmpmaniacs.wordpress.com/2012/03/03/filter-product-collection-for-multi-select-attribute-in-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.