Magento – How to filter collection by OR condition

convertmagento-1.8MySQLquery

I have two 'Yes/No' attributes created for products in my store. I want to get the product collection of products whose at least one attribute is set to yes. I've searched the web, but many websites mentions OR condition against a single attribute.

For the sake of clearance I'll mention the relevant SQL statement which I want to convert in Magento way,

SELECT * FROM catalog_product_entity WHERE attribute1 = true OR attribute2 = true;

Any suggestions would appreciate.

Best Answer

you can perform OR condition in this manner

$_products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
    array(
        array('attribute'=>'attribute1', 'eq' => '1'),
        array('attribute'=>'attribute2', 'eq' => '1'),
    )
);

Refer this link

Related Topic