cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter a customer boolean attribute on the admin invoices grid?

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to filter a customer boolean attribute on the admin invoices grid?

I can successfully display my customer attribute with the following code. Here is the collection setup:

$entityType = 'customer';
$attributeCode = 'myfoo';
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode($entityType, $attributeCode);
$resource = Mage::getSingleton('core/resource');
$ceTable = $resource->getTableName($entityType . '_entity_' . $attribute->getBackendType());

$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()
    ->join(
        array('sfo' => 'sales_flat_order'),
        'main_table.order_id = sfo.entity_id',
        array('customer_email'))

    //join I added to get the boolean customer attribute value
    ->joinLeft(
        array('ce2' => $ceTable),
        'ce2.entity_id = sfo.customer_id AND ce2.attribute_id = ' . $attribute->getId(),
        array($attributeCode => 'if(ce2.value, "Yes", "No")'));

And here's the column display:

$this->addColumn('myfoo', array(
    'header'    => Mage::helper('sales')->__('My Foo'),
    'index'     => 'myfoo',
    'type'      => 'text'
));

But how can I enable filtering for that column? The user should be able to type a yes or a no into the text input at the top of the column and filter records that have that value. I've tried to use filter_index and filter_condition_callback but can't get it to work.