Sometimes we need to add some Custom fields in the Billing and Shipping Address of the Onepage Checkout for Registered user, Guest user and at the time of Registration.
I have created the module for adding the new custom field in the Billing and Shipping address of the Onepage checkout. All the code of the module is given below.
Step: – 1
Add Custom Field into Billing Address tab of the Onepage Checkout in Frontend.
app\design\frontend\[Package_name]\[Theme_name]\template\checkout\onepage\billing.phtml
<li class="wide"> <label for="billing:jobtitle"><?php echo $this->__('Job Title') ?></label> <div class="input-box"> <input type="text" id="billing:jobtitle" name="billing[jobtitle]" value="<?php echo $this->htmlEscape($this->getAddress()->getJobtitle()) ?>" title="<?php echo $this->__('Job Title') ?>" class="input-text" /> </div> </li>
Step: – 2
Add Custom Field into Shipping Address tab of the Onepage Checkout in Frontend.
app\design\frontend\[Package_name]\[Theme_name]\template\checkout\onepage\shipping.phtml
<li class="wide"> <label for="shipping:jobtitle"><?php echo $this->__('Job Title') ?></label> <div class="input-box"> <input type="text" id="shipping:jobtitle" name="shipping[jobtitle]" value="<?php echo $this->htmlEscape($this->getAddress()->getJobtitle()) ?>" title="<?php echo $this->__('Job Title') ?>" class="input-text" onchange="shipping.setSameAsBilling(false);" /> </div> </li>
Step: – 3
Add Custom Field into Customer Address Edit tab in Frontend.
app\design\frontend\[Package_name]\[Theme_name]\template\customer\address\edit.phtml
<li class="wide"> <label for="jobtitle"><?php echo $this->__('Job Title') ?></label> <div class="input-box"> <input type="text" name="jobtitle" id="jobtitle" title="<?php echo $this->__('Job Title') ?>" value="<?php echo $this->htmlEscape($this->getAddress()->getJobtitle()) ?>" class="input-text" /> </div> </li>
Step: – 4
I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
app/code/core/Mage/Customer/etc/config.xml
and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
System->Configuration->Customers->Customer Configurations->Address Templates
Add following code in the “Text” Textarea.
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}} {{depend company}}{{var company}}{{/depend}} {{depend jobtitle}}{{var jobtitle}}{{/depend}} {{if street1}}{{var street1}} {{/if}} {{depend street2}}{{var street2}}{{/depend}} {{depend street3}}{{var street3}}{{/depend}} {{depend street4}}{{var street4}}{{/depend}} {{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}} {{var country}} T: {{var telephone}} {{depend fax}}F: {{var fax}}{{/depend}}
Step: – 5
I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
app/code/core/Mage/Customer/etc/config.xml
and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
System->Configuration->Customers->Customer Configurations->Address Templates
Add following code in the “HTML” Textarea.
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/> {{depend company}}{{var company}}<br />{{/depend}} {{depend jobtitle}}{{var jobtitle}}<br />{{/depend}} {{if street1}}{{var street1}}<br />{{/if}} {{depend street2}}{{var street2}}<br />{{/depend}} {{depend street3}}{{var street3}}<br />{{/depend}} {{depend street4}}{{var street4}}<br />{{/depend}} {{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/> {{var country}}<br/> {{depend telephone}}T: {{var telephone}}{{/depend}} {{depend fax}}<br/>F: {{var fax}}{{/depend}}
Step: – 6
I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
app/code/core/Mage/Customer/etc/config.xml
and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
System->Configuration->Customers->Customer Configurations->Address Templates
Add following code in the “PDF” Textarea.
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}| {{depend company}}{{var company}}|{{/depend}} {{depend jobtitle}}{{var jobtitle}}|{{/depend}} {{if street1}}{{var street1}} {{/if}} {{depend street2}}{{var street2}}|{{/depend}} {{depend street3}}{{var street3}}|{{/depend}} {{depend street4}}{{var street4}}|{{/depend}} {{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}| {{var country}}| {{depend telephone}}T: {{var telephone}}{{/depend}}| {{depend fax}}<br />F: {{var fax}}{{/depend}}|
I have created the separate module for adding Custom Field into Billing and Shipping Address in Frontend and Backend of the Magento Store.
Step: – 7
app\etc\modules\Tdg_All.xml
First of all create file with above given name and put following code into that file.
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Tdg_Check> <active>true</active> <codePool>local</codePool> </Tdg_Check> </modules> </config>
Step: – 8
app\code\local\Tdg\Check\etc\ config.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Tdg_Check> <version>1.0.0</version> </Tdg_Check> </modules> <admin> <fieldsets> <customer_dataflow> <jobtitle><billing>1</billing><shipping>1</shipping></jobtitle> </customer_dataflow> </fieldsets> </admin> <global> <models> <check> <class>Tdg_Check_Model</class> </check> </models> <resources> <check_setup> <setup> <module>Tdg_Check</module> </setup> <connection> <use>core_setup</use> </connection> </check_setup> <check_write> <connection> <use>core_write</use> </connection> </check_write> <check_read> <connection> <use>core_read</use> </connection> </check_read> </resources> <fieldsets> <sales_copy_order_billing_address> <jobtitle><to_order>*</to_order></jobtitle> </sales_copy_order_billing_address> <sales_copy_order_shipping_address> <jobtitle><to_order>*</to_order></jobtitle> </sales_copy_order_shipping_address> <sales_convert_quote_address> <jobtitle><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></jobtitle> </sales_convert_quote_address> <sales_convert_order_address> <jobtitle><to_quote_address>*</to_quote_address></jobtitle> </sales_convert_order_address> <customer_address> <jobtitle><to_quote_address>*</to_quote_address></jobtitle> </customer_address> <checkout_onepage_billing> <jobtitle><to_customer>*</to_customer></jobtitle> </checkout_onepage_billing> </fieldsets> </global> </config>
Step: – 9
app\code\local\Tdg\Check\sql\check_setup\ mysql4-install-1.0.0.php
<?php /* @var $installer Mage_Customer_Model_Entity_Setup */ $installer = $this; $installer->startSetup(); /* @var $addressHelper Mage_Customer_Helper_Address */ $addressHelper = Mage::helper('customer/address'); $store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID); /* @var $eavConfig Mage_Eav_Model_Config */ $eavConfig = Mage::getSingleton('eav/config'); // update customer address user defined attributes data $attributes = array( 'jobtitle' => array( 'label' => 'Job Title', 'backend_type' => 'varchar', 'frontend_input' => 'text', 'is_user_defined' => 1, 'is_system' => 0, 'is_visible' => 1, 'sort_order' => 140, 'is_required' => 1, 'multiline_count' => 0, 'validate_rules' => array( 'max_text_length' => 255, 'min_text_length' => 1 ), ), ); foreach ($attributes as $attributeCode => $data) { $attribute = $eavConfig->getAttribute('customer_address', $attributeCode); $attribute->setWebsite($store->getWebsite()); $attribute->addData($data); $usedInForms = array( 'adminhtml_customer_address', 'customer_address_edit', 'customer_register_address' ); $attribute->setData('used_in_forms', $usedInForms); $attribute->save(); } $installer->run(" ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `jobtitle` VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`; ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `jobtitle` VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`; "); $installer->endSetup(); ?>
July 31, 2011 at 9:29 pm
Hi, i have try almost five to six time to apply this structure in magento 1.5 but field added but value not store in database, Any one who knew the solution plz reply me.
August 5, 2011 at 12:35 pm
Hi, Zahid
You just open your phpmyadmin and go to “eav_attribute” table.
on there check that your attribute has been added or not if added then change the value of “backend_type” field from “static” to “varchar” and also change the value of “frontend_input” field from “NULL” or any other to “text”.
but if the attribute has not been added then you just remove the module and all the code which you have updated or added after that refresh the cache and reinstall it. I have updated the code of Step: – 9.
I hope it wil help you.
December 8, 2012 at 1:25 pm
i have tested the eav_attribute table, i am getting the value of “backend_type” as “varchar” and “frontend_input” as “text”. then also i dont find the job title in the customer address and in the sales_flat_order_addrees table the value for job title in passing as null.
Waiting for your reply
August 11, 2011 at 2:06 pm
Hi together,
the example works fine with 1.5.1.0. Now I want to add another field.
How to add more than one different fields? I’ll tried to add another one with replacing the variables and in a second try by copying all relevant parts. Both methodes didn’t work out. There are no changes in the database like the first time with your example. Can you give me an advice? That would be great!
Thanks for your efforts!
Patrick
September 5, 2011 at 7:22 am
Hi, I have same problem with zahid and I have try follow your instruction, but the problem is not solved. I have been uninstall the module and refreshing the cache an reinstall it again, But the attribute stay has not been added. Can help me? thanks before .. 🙂
September 23, 2011 at 12:45 am
I have not luck with this code eav_attriburte tabel missing jobtitle record … any idea ?
November 2, 2011 at 11:48 am
have you followed all the steps which has been given above specially Step: – 9?? because Steps: – 9 is use to create the “jobtitle” attribute so that you must have to follow all the steps and can you tell me which magento version are you using?
April 22, 2012 at 6:11 am
even i have the same problem..i am trying it in magento version 1.6.2.0 can you please help me …
November 2, 2011 at 3:34 pm
This is works for me, thank you very much!
January 23, 2012 at 5:13 pm
in config.xml defined model Tdg_Check_Model
where is it?
October 30, 2013 at 7:13 pm
Excellence question, i can´t found this
April 4, 2012 at 9:04 am
Hi Team Indies !
I installed this module but have problem 😦 , help me, please !!!
Can you send your module for me to my email ?
Thanks before 🙂
September 1, 2012 at 10:53 am
Hi Team Indies,
I just added the two fields (best_method_to_reach, best_availability_time ) as per your instructions. and I am able to save values to the DB 🙂 . but I am unable to get the values from the DB back to show it on the Edit address section.
I have added the text field in the edit form as :
<input type="text" name="best_method_to_reach" id="best_method_to_reach" value="escapeHtml($this->getAddress()->getBest_method_to_reach()) ?>” />
but getBest_method_to_reach() seems to return nothing… Can you please help..
March 4, 2013 at 1:16 pm
Its working fine. But issue is interesting here…When we go through onepage checkout and adding jot title…it doesnt inserting into table…but when we update/edit from my account page its working…i mean job titile value showing into db.
So How i can resolve this issue? magento 1.7.0.2
March 5, 2013 at 6:29 am
i have tried the above code of Add Custom Field in the Billing and Shipping Address of Onepage Checkout in Magento but no luck with this code. please help me out with different solution as i’m using 1.7.0.2 version of magento.thanks before..!
May 17, 2013 at 1:22 am
Hi, I’m using magento 1.7.02 too, some one know any solution?
Or have the sql query, to put it directly in phpmyadmin?
regards.
July 1, 2013 at 12:22 pm
this give me a error now, when i checkout i want to remove that error:
“” is a required value.
“” length must be equal or greater than 1 characters.
July 1, 2013 at 1:37 pm
I follow those steps, and my DB have that problem…
June 6, 2014 at 8:24 am
Open eav_attribute table and find jobtitle in attribute_code field. Edit that row and set is_required = 0.
July 10, 2013 at 4:32 am
A wise return to running should involve short, slow runs on flat, soft surfaces so as to tackle the problem of structural abnormalities.
The established curatives for removing under eye circles include rest, medicines, exercises and
taping. At times, iontophoresis can also be a symptom of a systemic disease.
As I said, if you have removing under eye circles is a painful condition caused by overuse and protracted trauma of the connective tissue called plantar fascia.
September 12, 2013 at 10:22 am
is this working on magento 1.4?
February 8, 2014 at 3:43 pm
Hi thanks for the wonderful help Its works perfect for me .Can you please tell me if i need to add mor fields can i make changes in this module or i have to create a new one .
thanks a lot
April 24, 2014 at 2:07 pm
hello i used magento 1.8.1 i follow your tutorial step by step but not jobtitle field is show in billing address.
May 8, 2014 at 12:07 pm
$attributes = array(
‘jobtitle’ => array(
‘label’ => ‘Title’,
‘backend_type’ => ‘varchar’,
‘frontend_input’ => ‘select’,
‘is_user_defined’ => 1,
‘is_system’ => 0,
‘is_visible’ => 1,
‘sort_order’ => 140,
‘is_required’ => 1,
‘multiline_count’ => 0,
‘option’ => array (
‘values’ => array(
‘Mr’ => array(‘Mr’),
‘Mrs’ => array(‘Mrs’),
‘Ms’ => array(‘Ms’),
‘Miss’ => array(‘Miss’),
‘Dr’ => array(‘Dr’),
)
),
‘validate_rules’ => array(
‘max_text_length’ => 255,
‘min_text_length’ => 1
),
),
);
This is not please help i change fields type text to select. i got dropdown but the value is not display blank dropdown is comming. please help. thank you so much for this tutorial.