1

I have created a custom customer_address attribute using below script :

$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->startSetup();

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

and added it in billing.phtml as :

<input type="text" name="billing[country_code]" value="<?php echo $this->escapeHtml($this->getAddress()->getCountryCode()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Country Code')) ?>" class="input-text  required-entry " id="billing:country_code"  />

But on order place other values saved in customer address but not custom attribute.

How to do that?

1 Answer 1

3

You should follow this article http://excellencemagentoblog.com/blog/2011/11/29/magento-adding-custom-field-to-customer-address/ , especially the last part with Checkout Billing/Shipping Step. Even if the article its a little bit old I think its still allright also for Magento 1.9.

The most important part is that you should also add this custom attribute also on the sales/quote_address and sales/order_address entities in order to have data persistence. And you should also add some extra stuff in the config.xml file.

I hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.