2026 Executive BenchmarkMid-Market Enterprise Modernization: How leaders across unify Commerce, Odoo ERP & AI in 90 days.
MAGENTO COMMERCE

Add custom attribute to customer grid

we do need to show that attribute in the Customer Grid then we need to follow the steps below: Step: 1. Override the Mage_Adminhtml_Block_Widget_Grid class Excellence_Subcust_Block...

Akshar Group Technologies
Dec 25, 2020
1 min read
Verified Source

we do need to show that attribute in the Customer Grid then we need to follow the steps below:

Step: 1. Override the Mage_Adminhtml_Block_Widget_Grid

php
<script>
class Excellence_Subcust_Block_Adminhtml_Customer_Grid extends
Mage_Adminhtml_Block_Customer_Grid {
public function setCollection($collection) {
$collection->addAttributeToSelect('custom_attr');
$this->_collection = $collection;
}
protected function _prepareColumns() {
$this->addColumnAfter('custom_attr', array(
'header' => Mage::helper('customer')->__('Customer Code'),
'type' => 'text',
'index' => 'custom_attr'
), 'entity_id');
return parent::_prepareColumns();
}
}
Step: 2. Edit your config.xml

Excellence_Subcust_Block_Adminhtml_Customer_Grid

In Step 1 we had not overridden the_prepareCollection()because callingreturn parent::_prepareCollection();=will reset the collection to default magento implementation and searching will not work for custom attribute column. For this we had overridden thesetCollection()and added our custom attribute to select. You can change it as per your requirement.
Share this playbook
LET'S BUILD WHAT'S NEXT

What's Holding Your Business Back?

Tell us where you want to go, what's getting in the way, and we'll help you figure out the technology to get there.

No sales pitch. Confidential strategic advisory.