Add new customer address attribute on customer grid in magento1

How to add custom customer address attribute on customer grid in magento?

In this extension we add two customer address attribute (which is already created through AddCustomCustomerAddressAttribute.rar extension) like a (i) “Reference Address1”
(ii) “Reference Address2”
Note:- you can download extension from this rar_image
Add custom customer address attribute in the customer grid in Magento through the custom module.
Note:- Firstly disable the cache from the Cache Management tab and which is in System tab.
there are many steps to create the extension.

Step1:- Create Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid.xml file in app/etc/modules/.
where Mywork is Namespace and AddCustomCustomerAddressAttributeOnCustomerGrid is Modulename.
[php]
<?xml version="1.0"?>
<config>
<modules>
<Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid>
<active>true</active>
<codePool>local</codePool>
</Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid>
</modules>
</config>
[/php]

Note:- 1) If you want to active the extensions then use true otherwise false.
2) there are three code pool (a) local (b) core (c) community
when we create the own extension then we use local code pool.

Step2:- Now create the config.xml file in app/code/local/Mywork/AddCustomCustomerAddressAttributeOnCustomerGrid/etc/
[php]
<config>
<modules>
<Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid>
<version>1.0.0</version>
</Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid>
</modules>

<global>
<blocks>
<adminhtml>
<rewrite>
<customer_grid>Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid_Block_Adminhtml_Customer_Grid</customer_grid>
</rewrite>
</adminhtml>
</blocks>
<helpers>
<AddCustomCustomerAddressAttributeOnCustomerGrid>
<class>Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid_Helper</class>
</AddCustomCustomerAddressAttributeOnCustomerGrid>
</helpers>
</global>
</config>
[/php]

Step3:- Now create the Grid.php file in app/code/local/Mywork/AddCustomCustomerAddressAttributeOnCustomerGrid/Block/Adminhtml/Customer/
[php]
<?php
class Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{

public function setCollection($collection) {
$collection->joinAttribute(‘reference_address1’, ‘customer_address/reference_address1’, ‘entity_id’, null, ‘left’);
$collection->joinAttribute(‘reference_address2’, ‘customer_address/reference_address2’, ‘entity_id’, null, ‘left’);
$this->_collection = $collection;
}

protected function _prepareColumns()
{
$this->addColumnAfter(‘reference_address1’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Reference Address1’),
‘width’ => ‘150’,
‘index’ => ‘reference_address1′
),’email’);

$this->addColumnAfter(‘reference_address2’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Reference Address2’),
‘width’ => ‘150’,
‘index’ => ‘reference_address2′
),’reference_address1’);

return parent::_prepareColumns();
}

}
?>
[/php]

Note:- In setCollection function we use joinAttribute function instead of addAttributeToSelect function.
joinAttribute function coming from app/code/core/Mage/Eav/Model/Entity/Collectionn/Abstract.php
public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType=’inner’, $storeId=null)

Step4:- Now create the Data.php file in app/code/local/Mywork/AddCustomCustomerAddressAttributeOnCustomerGrid/Helper/
[php]
<?php
class Mywork_AddCustomCustomerAddressAttributeOnCustomerGrid_Helper_Data extends Mage_Core_Helper_Abstract
{
}
?>
[/php]