Magento1.9.2.4 – Add Custom Field in Checkout and Registration Page

checkoutcustom-fieldmagento1.9.2.4registration

I need to add a custom field "Mobile" in registration and checkout pages.I have tried few methods but no luck. How can I achieve this?

config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Mobilenum_Cusmobile>
      <version>0.0.1</version>
    </Mobilenum_Cusmobile>
  </modules>
  <global>
       <fieldsets> 
     <checkout_onepage_quote>
         <customer_mobile_reg>
            <to_customer>mobile_reg</to_customer>
          </customer_mobile_reg>
     </checkout_onepage_quote>   
    <checkout_onepage_billing> 
        <mobile_reg> 
            <to_customer>*</to_customer> 
        </mobile_reg> 
    </checkout_onepage_billing> 
    <customer_account>
        <mobile_reg>
           <to_quote>customer_mobile_reg</to_quote>
         </mobile_reg>
     </customer_account>     
    <sales_convert_order>
        <customer_mobile_reg>
          <to_quote>*</to_quote>
        </customer_mobile_reg>
    </sales_convert_order>  
</fieldsets>
        <helpers>
      <cusmobile>
        <class>Mobilenum_Cusmobile_Helper</class>
      </cusmobile>
    </helpers>
    <models>
      <cusmobile>
        <class>Mobilenum_Cusmobile_Model</class>
        <resourceModel>cusmobile_mysql4</resourceModel>
      </cusmobile>
    </models>
    <resources>
      <customerattribute1486024557_setup>
        <setup>
          <module>Mobilenum_Cusmobile</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute1486024557_setup>
      <customerattribute1486024557_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute1486024557_write>
      <customerattribute1486024557_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute1486024557_read>
    </resources>
  </global>
</config> 

app/code/local/Mobilenum/Cusmobile/sql/customerattribute1486024557_setup/mysql4-install-0.0.1.php

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "mobile_reg",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Mobile Number",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => true,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "mobile_reg");


$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
        ;
        $attribute->save();
$installer->endSetup();

Best Answer

Kindly follow the below steps: I am posting the answer as per below considerations

1) module name: Ewall_Test II) Attribute code: custom_mobile

Step 1: create a module using silk software with customer attribute (which i have posted first answer)

Step 2: app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml

Keep the below code in the billing.phtml

<?php if(!$this->isCustomerLoggedIn()): ?>
<div class="field">
 <label for="billing:custom_mobile" class="required"><em>*</em><?php echo $this->__('Mobile Custom filed') ?></label>
    <div class="input-box">
     <input type="text" autocapitalize="off" autocorrect="off" spellcheck="false" name="billing[custom_mobile]" id="billing:custom_mobile" value="<?php echo $this->escapeHtml($this->getAddress()->getCustomMobile()) ?>" title="<?php echo $this->quoteEscape($this->__('Mobile Custom filed')) ?>" class="input-text required-entry" />
</div>
</div>
<?php endif; ?>

Step 3: go to 'app/code/Ewall/Test/etc/config.xml' of your module for customer attribute add below code inside the global tags

<fieldsets> 
     <checkout_onepage_quote>
         <customer_custom_mobile>
            <to_customer>custom_mobile</to_customer>
          </customer_custom_mobile>
     </checkout_onepage_quote>   
    <checkout_onepage_billing> 
        <custom_mobile> 
            <to_customer>*</to_customer> 
        </custom_mobile> 
    </checkout_onepage_billing> 
    <customer_account>
        <custom_mobile>
           <to_quote>customer_custom_mobile</to_quote>
         </custom_mobile>
     </customer_account>     
    <sales_convert_order>
        <customer_custom_mobile>
          <to_quote>*</to_quote>
        </customer_custom_mobile>
    </sales_convert_order>  
</fieldsets>

Screenshot: enter image description here

Step 4: after adding the above code in the config.xml go to your database and find the table sales_flat_quote and then create a new column as shown below screenshot

Screenshot:

enter image description here

Step 5:

Clear cache & session and go to checkout registration and do the process and check the same. thanks

Related Topic