Page tree
Skip to end of metadata
Go to start of metadata

Updated on 05 Jan 2010 - bolasevich 

Everything below was correct.. i actually found this wiki to offer 2 different methods.. 1 for adding custom fields to the “customer account” and then at the bottom the dates go august 2008 and down from there.. this is how you can create custom fields for “customer account ADDRESS”.. its 2 seperate areas.. the link above and my issue with data not saving from the frontend was related to just the customer account adding.. i havent tried customer account ADDRESS

[Update 23 Dec 2008 - phlux0r] Be aware that editing Magento Core files is not recommended as your changes may be overwritten by future updates. [/Update 23 Dec 2008 - phlux0r]

The better approach is to override the functionality in your local namespace as this will protect your changes from updates. I have successfully added a new Mobile Phone attribute to the address records on the Registration, One page checkout (for guest and registered) and multishipping pages. An overview of what I’ve done can be found at the end of this article.

Bear in mind that my changes relate to adding a mobile phone field to the addresses NOT the Occupation field to the customer data.

[Update 3 Oct 2008 - Fibo]Completed on how to display the info in the Edit Form –Note: done on the old 1.1.3, your mileage may vary[/Update 3 Oct 2008 - Fibo]

[Update 30 Aug 2008 - AlexSz]Info on how to make this work at the end of this post.[/Update 30 Aug 2008 - AlexSz]

Alright, we will be dealing with 5 files. So open each of the following:

app/design/frontend/default/yourtheme/template/customer/form/register.phtml - Has the HTML form for initial registration Note: this file will also be used for a one-shot database extension

app/design/frontend/default/yourtheme/template/customer/form/edit.phtml - Has the HTML form for edit by customers

app/code/core/Mage/Customer/Model/Entity/Setup.php - Has an array full of customer attributes to use for registration

app/code/core/Mage/Customer/controllers/AccountController.php - Has a specific block of code for registration - this is no more needed

app/code/core/Mage/Customer/etc/config.xml - Has a description of fields to be used in the forms

Alright, for this little tutorial, we will do a couple of fields. The first one will be a text box asking the customer for their occupation/title. Navigate to somewhere around line 54 of register.html - You should see this block of code:

 Expand source
Now, we need to add our code for the occupation text box, so change that block of code to the following:


 Expand source

Ok, if you refresh your create account (register) page, you will see the new field show up.

Do a similar thing in edit.phtml, replacing getFormData by getCustomer. In my 1.1.3 version, this is at line 32. Old code:

 Expand source
New code:


 Expand source


Now, the fun part is getting that value into the database. Now, navigate to around line 93 in Setup.php - you should see this block of code:

 Expand source

Now, we need to add our attribute to this file. So, change this block of code to:




 Expand source

Right under your occupation array, you will see the group_id one, etc. You need to increment the sort_order as they were doing before. So, since the sort_order for occupation is 7, make the one after it 8, and so on.

Now, our code is all set up and ready. However, we still need to add this attribute to the eav_attribute table in your mysql database. How do we do that? This block of code:


 Expand source

My suggestion is to add this block of code to the very top of your register.html file. You only need to load this block of code once, so add it to your register.html file, navigate to your register.html file, and then remove the block of code. If you go to your mysql database, view the eav_attribute table and do a search for occupation, you will see that your attribute has been added. Note: when doing all that is described here on my 1.1.3 version, the fields I was including got the “required” flag; I manually edited it in the eav_attribute table – Fibo

Now, go back to your create account page, fill it out, including your occupation, and bam you’re finished. If you need proof that it was added to the database, simply go to the customer_entity_varchar table and look for yourself smile

Also, to retrieve the customer data (as if you were in the account dashboard or something) you call this function:getOccupation.

Written by: Chris Woodard

[Update 30 Aug 2008 - AlexSz] In order to insert the values from custom registration fields you have to edit a .xml file:app/code/core/Mage/Customer/etc/config.xml Inside this file you will find the tag <fieldsets>. To get this to work you have to add the field here. I’ve added the line:


I’m attaching an excerpt of this file below. Also, you don’t need to edit the AccountController.php as the Mangento team apparently made that part of the code more generic (it reads the fields from the config.xml file).




 Expand source




[/Update 30 Aug 2008 - AlexSz]

[Update 23 Dec 2008 - phlux0r] Instead of editing the core files as described above, I created under app/local/MyCompany the following folders: /Customer /Customer/etc /Customer/Model/Entity /Customer/sql

I copied the original config.xml (as stated above) to the local etc folder and kept only the parts that are to be changed:

 Expand source


In the above file, the stuff within the curly brackets { ... } (and specifically the <html...> section) are the customer address templates that are displayed on the Sales Order pages, the Manage Customers > Addresses tabs and on the One page checkout status side bar. The {depend} tags determine whether a field is shown when its value is empty.

I created in Customer/Model/Entity Setup.php with the following content:

 Expand source


I also created the sql file to update the attribute but I don’t know how to actually get it to run as this is not a standard magento connect module installed through the installer (if anyone knows how to get Magento to run the SQL, let me know :).

I also edited the template files described above. Additionally, I edited the One Page Checkout template files as well: /template/checkout/onepage/billing.phtml - added after the fax field:

 Expand source


/template/checkout/onepage/shipping.phtml - added after the fax field:

 Expand source

Since we are adding a field to the addresses in order for them to show up on all the admin pages including the Sales/Order pages and for Guest checkouts, we need to add 3 versions of the mobile attribute to the eav_attribute table plus a column to the sales_flat_quote_address table since that one doesn’t follow the eav model and stores the guest checkout address in columns (doh!):




 Expand source




The three addAttribute statements will each add a record to your eav_attribute table. The SQL query at the end will add a column to the sales_flat_quote_address table. However if you run the above in another page like /app/design/frontend/[interface]/[theme]/template/checkout/onepage/billing.phtml the $this object does not extend a class with a getTable method which means that your SQL query wont have a table name and it will fail. One way to get around this is to hardcode the table name in the SQL string.

Finally, I overrode the Mage/Sales/etc/config.xml by creating: /MyCompany/Sales/etc/config.xml with:

 Expand source
Also, not to forget to enable your overridden modules in: app/etc/modules/MyCompany_All.xml:


 Expand source


[/Update 23 Dec 2008 - phlux0r]

the app/etc/modules/MyCompany_All.xml:

must be named like that: MyCompany_MyModule.xml and further it must look like this:

 Expand source


Take a look in the admin-panel system-configuration-admin-extended if your module is in the list and activated.

Anywhere, its strongy neccessary to take of care of capital and not capital writings, and at all, its a must to use Capital letters. I don´t know, where it is not neccessary, but if you copy the code from someone, and he is using a Capital Letter somewhere, do the same. (Hoping that he got no mistake in his Capital Non-Capital synthax LOL — 5erTag 2009/05/28 10:36


  • No labels