0

How would I go about adding a new field to all Backend Magento Customer Address forms?

I've looked into Magento's EAV system but none of the tutorials about adding custom address fields seem to work or make any sense.

I've gotten to the point where i have the mysql4-install-0.1.0.php file in my module, but I'm not sure what needs to be in there to add the new EAV field to the customer addresses.

Any help would be massively appreciated, I'm pretty new to Magento but I've worked with PHP for years.

Thanks all!

0

Your setup file should contain something like that, assuming your installer is Mage_Customer_Model_Entity_Setup:

$installer = $this;

$installer->startSetup();

$attributeCode = 'your_attribute_code';

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

Note that you will still need to add the HTML for the field in each frontend form you want to add this in.

| improve this answer | |
  • Hi Mayers, thanks for this. I've actually just figured this out using almost the exact code you pasted above. The only different is I just added the two adminhtml forms to the used_in_forms (not sure how that stuff works.. so much magic). Cheers! – joshbrw Feb 1 '16 at 14:41
  • Yeah the "used_in_forms" in this case is very important, it works for customer attribute fields too. Basically tells Magento which customer form this field should be available for save on. – Mayers Feb 1 '16 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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