Magento – New customer address attributes not saving

attributes

I've created 2 new customer attributes. These attributes show in the admin under "Customers > Attributes > Manage Customer Address Attributes".

I've overwritten the registration form (register.phtml) to display form fields matching these attributes. When I debug through the registration process, I see that Mage_Customer_Model_Form::getAttributes does not include my new attributes.

Because of this (I think), my new attributes are not being saved in the database. What step am I missing to make the registration form save my new attributes?

Best Answer

Add the attribute to the form-filter

To save new attributes in an EAV table through a form, you need to set the used_on_forms setting, like this in a setup file

$oAttribute = Mage::getSingleton('eav/config')->getAttribute(
     'customer', 'agb'
);
$oAttribute->setData('used_in_forms', array('adminhtml_customer', 'customer_account_create'));

There are a lot more forms, like customer_account_edit.

Be careful, this example is from a customer attribute, not customer address!

A few form codes:

SELECT DISTINCT form_code FROM `customer_form_attribute` WHERE 1
  • adminhtml_checkout
  • adminhtml_customer
  • adminhtml_customer_address
  • checkout_register
  • customer_account_create
  • customer_account_edit
  • customer_address_edit
  • customer_register_address

I'm not sure whether I got all, maybe there are some, which are not used but mentioned in the code.

Related Topic