Add custom field in the billing and shipping address in the checkout and customer address edit page in frontend and customer addresses details in Admin.

Last modified by Md Zafar on Fri, May 6, 2011 02:16
Source|Old Revisions  

This is an old revision of the document!


In my case I needed to add Job Title field above the Company field in billing and shipping address.

First go to Magento installation directory and edit these three files to add Job Title text box in frontend.

1.app/design/frontend/default/your_theme/template/customer/address/edit.phtml.

              <li class="fields">
              <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getCustomer())->toHtml() ?>
          </li>
          <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>
          <li class="wide">
              <label for="company"><?php echo $this->__('Company') ?></label>
              <div class="input-box">
                  <input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->htmlEscape($this->getAddress()->getCompany()) ?>" class="input-text" />
              </div>
          </li>

2.app/design/frontend/default/your_theme/template/checkout/onepage/billing.phtml.

                      <div class="field">
                      <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>
                  </div>
                  <div class="field">
                      <label for="billing:company"><?php echo $this->__('Company') ?></label>
                      <div class="input-box">
                          <input type="text" id="billing:company" name="billing[company]" value="<?php echo $this->htmlEscape($this->getAddress()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text" />
                      </div>
                  </div>

3.app/design/frontend/default/your_theme/template/checkout/onepage/shipping.phtml.

                          <div class="fields">
                          <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>
                      </div>
                      <div class="fields">
                          <label for="shipping:company"><?php echo $this->__('Company') ?></label>
                          <div class="input-box">
                              <input type="text" id="shipping:company" name="shipping[company]" value="<?php echo $this->htmlEscape($this->getAddress()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text" onchange="shipping.setSameAsBilling(false);" />
                          </div>
                      </div>

Next I created a separate module. app/code/local/Tdg/Check and saved the configuration file under app/etc/modules/Tdg_All.xml

I created these files under app/code/local/Tdg/Check directory:- 1.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>



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs