Question

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();
Was it helpful?

Solution

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

OTHER TIPS

Note I: Based on your question i have tried in default magento and got the solution.

Please follow the below steps and try the same in your local/default magento. Here i am showing you how to create a customer custom attribute and save the filed value while customer register from frontend.

Step1: Create a customer attribute using silk software tool.

create a module for customer attribute

Please specify the details as shown in the screenshot and download the module and install the module in your magento. don't forget to clear cache and session after installed the module.

Note II: Now login to admin and check the customer details you can able to view the new attribute text field.

enter image description here just check whether you are able to save and update the filed properly or not.

Step2: File path: app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml

Keep the below code in the register.pthml

<label for="custom_mobile"><em>*</em><?php echo $this->__('Custom Mobile Field') ?></label>
<div class="input-box">
<input type="text" autocapitalize="off" autocorrect="off" spellcheck="false" name="custom_mobile" id="custom_mobile" value="<?php echo $this->escapeHtml($this->getFormData()->getCustomMobile()) ?>" 
title="<?php echo $this->quoteEscape($this->__('Custom Mobile')) ?>" class="input-text" />
</div>

keep the code as shown this screen shot

Note III: if the field want to required you can specify the class required.

Step 3: Now click on register button and do the process as shown below screenshot.

click on register

Step 4: output screenshot here i am showing you. please check it admin end

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top