I want to filter collection for same attribute having two either values.





My question is.

If cutomer_group_id == 12 then it should have sales_org and sales_office value. else if customer_group_id == 13 then it should be null in sales_org and sales_office.

How can i achieve this filters.

2 Answers 2


AND Query Condition

$collection->addAttributeToFilter('attributecode1', array('like' => '%ch%'));
$collection->addAttributeToFilter('attributecode2', array('eq' => '1'));

OR Query Condition

                    'attribute' => 'atrributecode1',
                    'like' => '%ch%'),
                    'attribute' => 'attributecode2',
                    'eq' => '1')

For your requirement , need to write direction sql collection filter by


$read = Mage::getSingleton( 'core/resource' )->getConnection( 'core_read' );
 $whereCondition = array(
        $read->quoteInto('cutomer_group_id = ?', 12),
        $read->quoteInto('sales_org IS  NOT NULL'),
 $read->quoteInto('sales_office IS NOT NULL'),
 $collection->getSelect()->Where(implode(' AND ', $whereCondition));

 $orwhereCondition = array(
        $read->quoteInto('cutomer_group_id = ?', 13),
        $read->quoteInto(' sales_org IS NULL'),
 $read->quoteInto('sales_office IS NULL'),
 echo $collection->getSelect()->orWhere(implode(' AND ', $orwhereCondition));

You can use.But it not a good idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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