3

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

example:

->addFieldToFilter('customer_group_id',Mage::getSingleton('customer/session')->getCustomer()->getGroupId())   


->addFieldToFilter('sales_org',Mage::getSingleton('customer/session')->getCustomer()->getSalesOrgId())


->addFieldToFilter('sales_office',Mage::getSingleton('customer/session')->getCustomer()->getSalesOfficeId())

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.

3

AND Query Condition

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


OR Query Condition

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

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

$collection=Mage::getResourceModel('sales/order_collection');


$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, privacy policy and cookie policy

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