Custom Account/Registration Fields

Last modified by bolasevich on Fri, June 25, 2010 09:50
Source|Old Revisions  

This is an old revision of the document!


NOTE: i solved the issue with this

http://www.fontis.com.au/blog/magento/custom-customer-signup-attributes

basically the problem is that you need to create its “own” module vs just the local/mage/customer .. override.. i had all my code exactly the same and yet for whatever reason because i didnt create it as a seperate module from the frontend it wouldnt save the data from the registration page

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 [Updated on 05 Jan 2010 - bolasevich] ====== Custom Account/Registration Fields ====== [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: <code php> <li> <div class=”input-box”> <label for=”email_address”><?php echo $this→(’Email Address’) ?> <span class=”required”>*</span></label><br/> <input type=”text” name=”email” id=”email_address” value=”<?php echo $this→htmlEscape($this→getFormData()→getEmail()) ?>” title=”<?php echo $this→(’Email Address’) ?>” class=”validate-email required-entry input-text” /> </div> </li> </code> Now, we need to add our code for the occupation text box, so change that block of code to the following: <code php> <li> <div class=”input-box”> <label for=”email_address”><?php echo $this→(’Email Address’) ?> <span class=”required”>*</span></label><br/> <input type=”text” name=”email” id=”email_address” value=”<?php echo $this→htmlEscape($this→getFormData()→getEmail()) ?>” title=”<?php echo $this→(’Email Address’) ?>” class=”validate-email required-entry input-text” /> </div> <div class=”input-box”> <label for=”occupation”><?php echo $this→(’Occupation/Title’) ?></label><br/> <input type=”text” name=”occupation” id=”occupation” value=”<?php echo $this→htmlEscape($this→getFormData()→getOccupation()) ?>” title=”<?php echo $this→(’Occupation’) ?>” class=”input-text” /> </div> </li> </code> 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: <code php> <li> <?php echo $this→getLayout()→createBlock(’customer/widget_name’)→setObject($this→getCustomer())→toHtml() ?> </li> <li> <div class=”input-box”> <label for=”email”><?php echo $this→(’Email Address’) ?> <span class=”required”>*</span></label><br /> <input type=”text” name=”email” id=”email” value=”<?php echo $this→htmlEscape($this→getCustomer()→getEmail()) ?>” title=”<?php echo $this→(’Email Address’) ?>” class=”required-entry validate-email input-text” /> </div> </li> </code> New code: <code php> <li> <?php echo $this→getLayout()→createBlock(’customer/widget_name’)→setObject($this→getCustomer())→toHtml() ?> </li> <li> <div class=”input-box”> <label for=”email”><?php echo $this→(’Email Address’) ?> <span class=”required”>*</span></label><br /> <input type=”text” name=”email” id=”email” value=”<?php echo $this→htmlEscape($this→getCustomer()→getEmail()) ?>” title=”<?php echo $this→(’Email Address’) ?>” class=”required-entry validate-email input-text” /> </div> </li> <li> <div class=”input-box”> <label for=”occupation”><?php echo $this→(’Occupation’) ?> </label><br/> <input type=”text” name=”occupation” id=”occupation” value=”<?php echo $this→htmlEscape($this→getCustomer()→getOccupation()) ?>” title=”<?php echo $this→(’Occupation’) ?>” class=”input-text” /> </div> </li> </code> 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: <code php> ‘email’ ⇒ array( ‘type’ ⇒ ‘static’, ‘label’ ⇒ ‘Email’, ‘class’ ⇒ ‘validate-email’, ‘sort_order’ ⇒ 6, ), </code> Now, we need to add our attribute to this file. So, change this block of code to: <code php> ‘email’ ⇒ array( ‘type’ ⇒ ‘static’, ‘label’ ⇒ ‘Email’, ‘class’ ⇒ ‘validate-email’, ‘sort_order’ ⇒ 6, ), ‘occupation’ ⇒ array( ‘label’ ⇒ ‘Occupation’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 7, ), </code> 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. —— == This part is needed no more, left here for possible reference - should be deleted at the end of October 2008 == Now, head to line 164 of AccountController.php. You should see this block of code: <code php> $customer = Mage::getModel(’customer/customer’) →setFirstname($this→getRequest()→getPost(’firstname’)) →setLastname($this→getRequest()→getPost(’lastname’)) →setEmail($this→getRequest()→getPost(’email’)) →setPassword($this→getRequest()→getPost(’password’)) →setConfirmation($this→getRequest()→getPost(’confirmation’)) →setId(null); </code> We need to add our new occupation attribute to this, so change the code to this: <code php> $customer = Mage::getModel(’customer/customer’) →setFirstname($this→getRequest()→getPost(’firstname’)) →setLastname($this→getRequest()→getPost(’lastname’)) →setEmail($this→getRequest()→getPost(’email’)) →setOccupation($this→getRequest()→getPost(’occupation’)) Add this →setPassword($this→getRequest()→getPost(’password’)) →setConfirmation($this→getRequest()→getPost(’confirmation’)) →setId(null); </code> == End of the unneeded code == —- 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: <code php> <?php $setup = new Mage_Eav_Model_Entity_Setup(’core_setup’); $AttrCode = ‘occupation’; $settings = array ( ‘position’ ⇒ 1, ‘is_required’⇒ 0 ); $setup→addAttribute(’1’, $AttrCode, $settings); ?> </code> 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: <code xml> <occupation><create>1</create><update>1</update></occupation> </code> 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). <code xml> <fieldsets> <customer_account> <prefix><create>1</create><update>1</update><name>1</name></prefix> <firstname><create>1</create><update>1</update><name>1</name></firstname> <middlename><create>1</create><update>1</update><name>1</name></middlename> <lastname><create>1</create><update>1</update><name>1</name></lastname> <suffix><create>1</create><update>1</update><name>1</name></suffix> <email><create>1</create><update>1</update></email> <password><create>1</create></password> <confirmation><create>1</create></confirmation> <dob><create>1</create><update>1</update></dob> <taxvat><create>1</create><update>1</update></taxvat> <occupation><create>1</create><update>1</update></occupation> </customer_account> </fieldsets> </code> [/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: <code xml> <?xml version=”1.0” encoding=”UTF-8”?> <config> <modules> <MyCompany_Customer> <version>0.1</version> </MyCompany_Customer> </modules> <admin> <fieldsets> <customer_dataflow> <store_id><system>1</system></store_id> <store><ignore>1</ignore></store> <entity_id><system>1</system><ignore>1</ignore></entity_id> <attribute_set_id><system>1</system><ignore>1</ignore></attribute_set_id> <attribute_set><ignore>1</ignore></attribute_set> <entity_type_id><system>1</system></entity_type_id> <increment_id><system>1</system><ignore>1</ignore></increment_id> <parent_id><system>1</system></parent_id> <created_at><system>1</system></created_at> <updated_at><system>1</system></updated_at> <group_id><ignore>1</ignore></group_id> <type_id><system>1</system><ignore>1</ignore></type_id> <type><ignore>1</ignore></type> <created_in><system>1</system><ignore>1</ignore></created_in> <website_id><system>1</system></website_id> <default_billing><system>1</system></default_billing> <default_shipping><system>1</system></default_shipping> <prefix><billing>1</billing><shipping>1</shipping><mapped>1</mapped></prefix> <firstname><billing>1</billing><shipping>1</shipping><required>1</required><mapped>1</mapped></firstname> <middlename><billing>1</billing><shipping>1</shipping><mapped>1</mapped></middlename> <lastname><billing>1</billing><shipping>1</shipping><required>1</required><mapped>1</mapped></lastname> <suffix><billing>1</billing><shipping>1</shipping><mapped>1</mapped></suffix> <street_full><billing>1</billing><shipping>1</shipping></street_full> <street1><street>1</street></street1> <street2><street>1</street></street2> <street3><street>1</street></street3> <street4><street>1</street></street4> <street5><street>1</street></street5> <street6><street>1</street></street6> <street7><street>1</street></street7> <street8><street>1</street></street8> <city><billing>1</billing><shipping>1</shipping></city> <region><billing>1</billing><shipping>1</shipping></region> <country><billing>1</billing><shipping>1</shipping><billing_required>1</billing_required><shipping_required>1</shipping_required></country> <postcode><billing>1</billing><shipping>1</shipping><billing_required>1</billing_required><shipping_required>1</shipping_required></postcode> <telephone><billing>1</billing><shipping>1</shipping></telephone> <company><billing>1</billing><shipping>1</shipping></company> <fax><billing>1</billing><shipping>1</shipping></fax> <mobile><billing>1</billing><shipping>1</shipping></mobile> </customer_dataflow> </fieldsets> </admin> <global> <fieldsets> <customer_account> <prefix><create>1</create><update>1</update><name>1</name></prefix> <firstname><create>1</create><update>1</update><name>1</name></firstname> <middlename><create>1</create><update>1</update><name>1</name></middlename> <lastname><create>1</create><update>1</update><name>1</name></lastname> <suffix><create>1</create><update>1</update><name>1</name></suffix> <email><create>1</create><update>1</update></email> <password><create>1</create></password> <confirmation><create>1</create></confirmation> <dob><create>1</create><update>1</update></dob> <taxvat><create>1</create><update>1</update></taxvat> </customer_account> </fieldsets> <customer> <address> <formats> <text translate=”title” module=”customer”> <title>Text</title> <defaultFormat><![CDATA[ depend_prefixvar_prefix dependvar_firstname depend_middlenamevar_middlename dependvar_lastnamedepend_suffix var_suffixdepend depend_companyvar_companydepend var_street1 depend_street2var_street2depend depend_street3var_street3depend depend_street4var_street4depend depend_cityvar_city, dependdepend_regionvar_region, dependvar_postcode var_country T: var_telephone depend_faxF: var_faxdepend depend_mobileM: var_mobiledepend ]]></defaultFormat> </text> <oneline translate=”title” module=”customer”> <title>Text One Line</title> <htmlEscape>true</htmlEscape> <defaultFormat> <![CDATA[depend_prefixvar_prefix dependvar_firstname depend_middlenamevar_middlename dependvar_lastnamedepend_suffix var_suffixdepend, var_street, var_city, var_region var_postcode, var_country]]> </defaultFormat> </oneline> <html translate=”title” module=”customer”> <title>HTML</title> <htmlEscape>true</htmlEscape> <defaultFormat><![CDATA[ depend_prefixvar_prefix dependvar_firstname depend_middlenamevar_middlename dependvar_lastnamedepend_suffix var_suffixdepend<br/> depend_companyvar_company<br />depend var_street1<br /> depend_street2var_street2<br />depend depend_street3var_street3<br />depend depend_street4var_street4<br />depend depend_cityvar_city, dependdepend_regionvar_region, dependvar_postcode<br/> var_country<br/> depend_telephoneT: var_telephonedepend depend_fax<br/>F: var_faxdepend depend_mobile<br/>M: var_mobiledepend ]]></defaultFormat> </html> <pdf translate=”title” module=”customer”> <title>PDF</title> <defaultFormat><![CDATA[ depend_prefixvar_prefix dependvar_firstname depend_middlenamevar_middlename dependvar_lastnamedepend_suffix var_suffixdepend| depend_companyvar_company|depend var_street1| depend_street2var_street2|depend depend_street3var_street3|depend depend_street4var_street4|depend depend_cityvar_city, dependdepend_regionvar_region, dependvar_postcode| var_country| depend_telephoneT: var_telephonedepend| depend_fax<br/>F: var_faxdepend| depend_mobile<br/>M: var_mobiledepend| ]]></defaultFormat> </pdf> <js_template template=”title” module=”customer”> <title>Javascript Template</title> <defaultFormat><![CDATA[#{prefix} #{firstname} #{middlename} #{lastname} #{suffix}<br/>#{company}<br/>#{street0}<br/>#{street1}<br/>#{street2}<br/>#{street3}<br/>#{city}, #{region}, #{postcode}<br/>#{country_id}<br/>T: #{telephone}<br/>F: #{fax}<br/>M: #{mobile}]]></defaultFormat> </js_template> </formats> </address> </customer> <models> <customer_entity> <rewrite> <setup>MyCompany_Customer_Model_Entity_Setup</setup> </rewrite> </customer_entity> </models> <resources> <customer_setup> <rewrite> <setup>MyCompany_Customer_Model_Entity_Setup</setup> </rewrite> </customer_setup> </resources> </global> </config> </code> 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: <code php> class MyCompany_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup { public function getDefaultEntities() { return array( ‘customer’ ⇒ array( ‘entity_model’ ⇒‘customer/customer’, ‘table’ ⇒ ‘customer/entity’, ‘increment_model’ ⇒ ‘eav/entity_increment_numeric’, ‘increment_per_store’ ⇒ false, ‘website_id’ ⇒ array( ‘type’ ⇒ ‘static’, ‘label’ ⇒ ‘Associate to Website’, ‘input’ ⇒ ‘select’, ‘source’ ⇒ ‘customer/customer_attribute_source_website’, ‘backend’ ⇒ ‘customer/customer_attribute_backend_website’, ‘sort_order’ ⇒ 10, ), ‘store_id’ ⇒ array( ‘type’ ⇒ ‘static’, ‘label’ ⇒ ‘Create In’, ‘input’ ⇒ ‘select’, ‘source’ ⇒ ‘customer/customer_attribute_source_store’, ‘backend’ ⇒ ‘customer/customer_attribute_backend_store’, ‘visible’ ⇒ false, ‘sort_order’ ⇒ 20, ), ‘created_in’ ⇒ array( ‘type’ ⇒ ‘varchar’, ‘label’ ⇒ ‘Created From’, ‘sort_order’ ⇒ 30, ), ‘prefix’ ⇒ array( ‘label’ ⇒ ‘Prefix’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 37, ), ‘firstname’ ⇒ array( ‘label’ ⇒ ‘First Name’, ‘sort_order’ ⇒ 40, ), ‘middlename’ ⇒ array( ‘label’ ⇒ ‘Middle Name/Initial’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 43, ), ‘lastname’ ⇒ array( ‘label’ ⇒ ‘Last Name’, ‘sort_order’ ⇒ 50, ), ‘suffix’ ⇒ array( ‘label’ ⇒ ‘Suffix’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 53, ), ‘email’ ⇒ array( ‘type’ ⇒ ‘static’, ‘label’ ⇒ ‘Email’, ‘class’ ⇒ ‘validate-email’, ‘sort_order’ ⇒ 60, ), ‘group_id’ ⇒ array( ‘type’ ⇒ ‘static’, ‘input’ ⇒ ‘select’, ‘label’ ⇒ ‘Customer Group’, ‘source’ ⇒ ‘customer/customer_attribute_source_group’, ‘sort_order’ ⇒ 70, ), ‘dob’ ⇒ array( ‘type’ ⇒ ‘datetime’, ‘input’ ⇒ ‘date’, ‘backend’ ⇒ ‘eav/entity_attribute_backend_datetime’, ‘required’ ⇒ false, ‘label’ ⇒ ‘Date Of Birth’, ‘sort_order’ ⇒ 80, ), ‘password_hash’ ⇒ array( ‘input’ ⇒ ‘hidden’, ‘backend’ ⇒ ‘customer/customer_attribute_backend_password’, ‘required’ ⇒ false, ), ‘default_billing’ ⇒ array( ‘type’ ⇒ ‘int’, ‘visible’ ⇒ false, ‘required’ ⇒ false, ‘backend’ ⇒ ‘customer/customer_attribute_backend_billing’, ), ‘default_shipping’ ⇒ array( ‘type’ ⇒ ‘int’, ‘visible’ ⇒ false, ‘required’ ⇒ false, ‘backend’ ⇒ ‘customer/customer_attribute_backend_shipping’, ), ‘taxvat’ ⇒ array( ‘label’ ⇒ ‘Tax/GST number’, ‘visible’ ⇒ true, ‘required’ ⇒ false, ‘position’ ⇒ 1, ), ‘confirmation’ ⇒ array( ‘label’ ⇒ ‘Is confirmed’, ‘visible’ ⇒ false, ‘required’ ⇒ false, ), ), ), ‘customer_address’⇒array( ‘entity_model’ ⇒‘customer/customer_address’, ‘table’ ⇒ ‘customer/address_entity’, ‘is_active’ ⇒ array(’type’⇒‘static’), ‘prefix’ ⇒ array( ‘label’ ⇒ ‘Prefix’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 7, ), ‘firstname’ ⇒ array( ‘label’ ⇒ ‘First Name’, ‘sort_order’ ⇒ 10, ), ‘middlename’ ⇒ array( ‘label’ ⇒ ‘Middle Name/Initial’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 13, ), ‘lastname’ ⇒ array( ‘label’ ⇒ ‘Last Name’, ‘sort_order’ ⇒ 20, ), ‘suffix’ ⇒ array( ‘label’ ⇒ ‘Suffix’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 23, ), ‘company’ ⇒ array( ‘label’ ⇒ ‘Company’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 30, ), ‘street’ ⇒ array( ‘type’ ⇒ ‘text’, ‘backend’ ⇒ ‘customer_entity/address_attribute_backend_street’, ‘input’ ⇒ ‘multiline’, ‘label’ ⇒ ‘Street Address’, ‘sort_order’ ⇒ 40, ), ‘city’ ⇒ array( ‘label’ ⇒ ‘City’, ‘sort_order’ ⇒ 50, ), ‘country_id’ ⇒ array( ‘type’ ⇒ ‘varchar’, ‘input’ ⇒ ‘select’, ‘label’ ⇒ ‘Country’, ‘class’ ⇒ ‘countries’, ‘source’ ⇒ ‘customer_entity/address_attribute_source_country’, ‘sort_order’ ⇒ 60, ), ‘region’ ⇒ array( ‘backend’ ⇒ ‘customer_entity/address_attribute_backend_region’, ‘label’ ⇒ ‘State/Province’, ‘class’ ⇒ ‘regions’, ‘sort_order’ ⇒ 70, ), ‘region_id’ ⇒ array( ‘type’ ⇒ ‘int’, ‘input’ ⇒ ‘hidden’, ‘source’ ⇒ ‘customer_entity/address_attribute_source_region’, ‘required’ ⇒ ‘false’, ‘sort_order’ ⇒ 80, ), ‘postcode’ ⇒ array( ‘label’ ⇒ ‘Zip/Postal Code’, ‘sort_order’ ⇒ 90, ), ‘telephone’ ⇒ array( ‘label’ ⇒ ‘Telephone’, ‘sort_order’ ⇒ 100, ), ‘fax’ ⇒ array( ‘label’ ⇒ ‘Fax’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 110, ), ‘mobile’ ⇒ array( ‘label’ ⇒ ‘Mobile’, ‘required’ ⇒ false, ‘sort_order’ ⇒ 120, ), ), ); } } </code> 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: <code php> <li> <div class=”input-box”> <label for=”billing:mobile”><?php echo $this→(’Mobile’) ?></label><br /> <input type=”text” name=”billing[mobile]” id=”billing:mobile” value=”<?php echo $this→htmlEscape($this→getAddress()→getMobile()) ?>” title=”<?php echo $this→(’Mobile’) ?>” class=”input-text” /> </div> </li> </code> /template/checkout/onepage/shipping.phtml - added after the fax field: <code php> <li> <div class=”input-box”> <label for=”shipping:mobile”><?php echo $this→(’Mobile’) ?></label><br /> <input type=”text” name=”shipping[mobile]” id=”shipping:mobile” value=”<?php echo $this→htmlEscape($this→getAddress()→getMobile()) ?>” title=”<?php echo $this→(’Mobile’) ?>” class=”input-text” onchange=”shipping.setSameAsBilling(false);” /> </div> </li> </code> 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!): <code php> Run this once when installing manually (ie. in register.phtml) $setup = new Mage_Eav_Model_Entity_Setup(’core_setup’); $setup→addAttribute(’customer_address’, ‘mobile’, array( ‘label’ ⇒ ‘Mobile’, ‘visible’ ⇒ true, ‘required’ ⇒ false, ‘position’ ⇒ 1, )); $setup→addAttribute(’order_address’, ‘mobile’, array( ‘label’ ⇒ ‘Mobile’, ‘visible’ ⇒ true, ‘required’ ⇒ false, ‘position’ ⇒ 1, )); $setup→addAttribute(’quote_address’, ‘mobile’, array( ‘label’ ⇒ ‘Mobile’, ‘visible’ ⇒ true, ‘required’ ⇒ false, ‘position’ ⇒ 1, )); try { $setup→run(” ALTER TABLE {$this→getTable(’sales_flat_quote_address’)} ADD COLUMN `mobile` VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`; “); } catch (Exception $e) { } </code> 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: <code xml> <?xml version=”1.0” encoding=”UTF-8”?> <config> <global> <fieldsets> <sales_copy_order_billing_address> <prefix><to_order>*</to_order></prefix> <firstname><to_order>*</to_order></firstname> <middlename><to_order>*</to_order></middlename> <lastname><to_order>*</to_order></lastname> <suffix><to_order>*</to_order></suffix> <customer_address_id><to_order>*</to_order></customer_address_id> <company><to_order>*</to_order></company> <street><to_order>*</to_order></street> <city><to_order>*</to_order></city> <region><to_order>*</to_order></region> <postcode><to_order>*</to_order></postcode> <country_id><to_order>*</to_order></country_id> <telephone><to_order>*</to_order></telephone> <fax><to_order>*</to_order></fax> <mobile><to_order>*</to_order></mobile> <region_id><to_order>*</to_order></region_id> </sales_copy_order_billing_address> <sales_copy_order_shipping_address> <prefix><to_order>*</to_order></prefix> <firstname><to_order>*</to_order></firstname> <middlename><to_order>*</to_order></middlename> <lastname><to_order>*</to_order></lastname> <suffix><to_order>*</to_order></suffix> <customer_address_id><to_order>*</to_order></customer_address_id> <company><to_order>*</to_order></company> <street><to_order>*</to_order></street> <city><to_order>*</to_order></city> <region><to_order>*</to_order></region> <postcode><to_order>*</to_order></postcode> <country_id><to_order>*</to_order></country_id> <telephone><to_order>*</to_order></telephone> <fax><to_order>*</to_order></fax> <mobile><to_order>*</to_order></mobile> <region_id><to_order>*</to_order></region_id> </sales_copy_order_shipping_address> <sales_convert_quote_address> <weight><to_order>*</to_order></weight> <shipping_method><to_order>*</to_order></shipping_method> <shipping_description><to_order>*</to_order></shipping_description> <shipping_rate><to_order>*</to_order></shipping_rate> <subtotal><to_order>*</to_order></subtotal> <tax_amount><to_order>*</to_order></tax_amount> <tax_string><to_order>*</to_order></tax_string> <discount_amount><to_order>*</to_order></discount_amount> <shipping_amount><to_order>*</to_order></shipping_amount> <shipping_tax_amount><to_order>*</to_order></shipping_tax_amount> <giftcert_amount><to_order>*</to_order></giftcert_amount> <custbalance_amount><to_order>*</to_order></custbalance_amount> <grand_total><to_order>*</to_order></grand_total> <base_subtotal><to_order>*</to_order></base_subtotal> <base_tax_amount><to_order>*</to_order></base_tax_amount> <base_discount_amount><to_order>*</to_order></base_discount_amount> <base_shipping_amount><to_order>*</to_order></base_shipping_amount> <base_shipping_tax_amount><to_order>*</to_order></base_shipping_tax_amount> <base_giftcert_amount><to_order>*</to_order></base_giftcert_amount> <base_custbalance_amount><to_order>*</to_order></base_custbalance_amount> <base_grand_total><to_order>*</to_order></base_grand_total> <prefix><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></prefix> <firstname><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></firstname> <middlename><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></middlename> <lastname><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></lastname> <suffix><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></suffix> <company><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></company> <street_full><to_order_address>street</to_order_address></street_full> <street><to_customer_address>*</to_customer_address></street><!– ^^^ ? –> <city><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></city> <region><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></region> <region_id><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></region_id> <postcode><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></postcode> <country_id><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></country_id> <telephone><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></telephone> <fax><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></fax> <mobile><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></mobile> <email><to_customer_address>*</to_customer_address></email> </sales_convert_quote_address> <sales_convert_order_address> <prefix><to_quote_address>*</to_quote_address></prefix> <firstname><to_quote_address>*</to_quote_address></firstname> <middlename><to_quote_address>*</to_quote_address></middlename> <lastname><to_quote_address>*</to_quote_address></lastname> <suffix><to_quote_address>*</to_quote_address></suffix> <company><to_quote_address>*</to_quote_address></company> <street_full><to_quote_address>street</to_quote_address></street_full> <city><to_quote_address>*</to_quote_address></city> <region><to_quote_address>*</to_quote_address></region> <region_id><to_quote_address>*</to_quote_address></region_id> <postcode><to_quote_address>*</to_quote_address></postcode> <country_id><to_quote_address>*</to_quote_address></country_id> <telephone><to_quote_address>*</to_quote_address></telephone> <fax><to_quote_address>*</to_quote_address></fax> <mobile><to_quote_address>*</to_quote_address></mobile> </sales_convert_order_address> <customer_address> <id><to_quote_address>customer_address_id</to_quote_address></id> <parent_id><to_quote_address>customer_id</to_quote_address></parent_id> <prefix><to_quote_address>*</to_quote_address></prefix> <firstname><to_quote_address>*</to_quote_address></firstname> <middlename><to_quote_address>*</to_quote_address></middlename> <lastname><to_quote_address>*</to_quote_address></lastname> <suffix><to_quote_address>*</to_quote_address></suffix> <!–<email><to_quote_address>*</to_quote_address></email>–> <company><to_quote_address>*</to_quote_address></company> <street_full><to_quote_address>street</to_quote_address></street_full> <city><to_quote_address>*</to_quote_address></city> <region><to_quote_address>*</to_quote_address></region> <region_id><to_quote_address>*</to_quote_address></region_id> <postcode><to_quote_address>*</to_quote_address></postcode> <country_id><to_quote_address>*</to_quote_address></country_id> <telephone><to_quote_address>*</to_quote_address></telephone> <fax><to_quote_address>*</to_quote_address></fax> <mobile><to_quote_address>*</to_quote_address></mobile> </customer_address> </fieldsets> </global> </config> </code> Also, not to forget to enable your overridden modules in: app/etc/modules/MyCompany_All.xml: <code xml> <MyCompany_Customer> <active>true</active> <codePool>local</codePool> </MyCompany_Customer> <MyCompany_Sales> <active>true</active> <codePool>local</codePool> </MyCompany_Sales> </code> [/Update 23 Dec 2008 - phlux0r] ====== Important ====== the app/etc/modules/MyCompany_All.xml: must be named like that: MyCompany_MyModule.xml and further it must look like this: <code php> <?xml version=”1.0”?> <config> <modules> <Mycode_Customer> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </Mycode_Customer> </modules> </config> </code> 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;-) LOL5erTag 2009/05/28 10:36




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs