Tuesday, 26 September 2017

Add Custom Field to Customer Address

$installer = Mage::getSingleton('eav/entity_setup', 'eav_setup');

$installer->startSetup();

$installer->addAttribute('customer_address', 'addresstyped', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Address Type',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'addresstyped')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
$installer->endSetup();


Module created :-
1. Path :- /app/etc/modules/Dapl_Excellenceaddress.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dapl_Excellenceaddress>
            <active>true</active>
            <codePool>local</codePool>
        </Dapl_Excellenceaddress>
    </modules>
</config>

2. Path:- /app/code/local/Dapl/Excellenceaddress/etc/config.xml

 <global>
                <fieldsets>
            <sales_convert_quote_address>
                <addresstyped>
                    <to_order_address>*</to_order_address>
                    <to_customer_address>*</to_customer_address>
                </addresstyped>
            </sales_convert_quote_address>
            <customer_address>
                <addresstyped>
                    <to_quote_address>*</to_quote_address>
                </addresstyped>
            </customer_address>
        </fieldsets>
 </global>

Next step:-
ALTER TABLE  `sales_flat_quote_address` ADD  `addresstyped` VARCHAR( 255 ) NOT NULL AFTER  `fax` ;

Text
Add {{depend addresstyped}}ID# {{var addresstyped}}{{/depend}} where ever you want it. {{depend}} basically checks, if govt_id is not empty.
Text One line
Add {{depend addresstyped}}ID# {{var addresstyped}}{{/depend}} where ever you want it. This format shows up in the checkout page shipping,billing address dropdowns.
HTML
Add {{depend addresstyped}}<br/>ID# {{var addresstyped}}{{/depend}}. This format is used in many places like Order View, Address Display etc.
PDF
Add {{depend addresstyped}}<br/>ID# {{var addresstyped}}{{/depend}}|. This format is used in PDF invoices, shipments etc.
Javascript Template
Add <br/>ID#{addresstyped}. This is used in admin add/edit address area.
After saving these in the configuration, the new address format should be visible. 

No comments:

Post a Comment