I want to show a custom attribute of a customer in the adminhtml customer grid.
I managed to do this by creating a new module, and extends the setCollection
method of Mage_Adminhtml_Block_Customer_Grid
public function setCollection($collection)
{
$collection->addAttributeToSelect('x_customer_category');
parent::setCollection($collection);
}
And I add the column via observer to the view
/**
* Adds column to admin customers grid
*
* @param Varien_Event_Observer $observer
*
* @return Mscg_TemplateOverwrite_Model_Customer_Observer
*/
public function addCustomerGroupToGrid(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if (!isset($block)) {
return $this;
}
if ($block->getType() == 'adminhtml/customer_grid') {
/* @var $block Mage_Adminhtml_Block_Customer_Grid */
$block->addColumnAfter('x_customer_category', array(
'header' => 'x_customer_category',
'type' => 'text',
'index' => 'x_customer_category',
), 'email');
}
}
However, since this is a option-wise attribute I only get the id of the selected value for the customer but I do want the textvalue, not the entity value of given attribut.
How can I do that?