how to magento Add new field in Account Information
In this post we will show you magento Add new field in Account Information, hear for magento Add new field in Account Information we will give you demo and example for implement.
The following instructions will add a new customer attribute called Mobile. This attribute will be added to the Customer information only, it will not be added to the Customer Address.
Apologies for the pastebin links, my syntax highlighter is currently out of action.
Create the following fields:
app/code/local/Onlinecode/Mobile/etc/config.xml app/code/local/Onlinecode/Mobile/Helper/Data.php app/code/local/Onlinecode/Mobile/sql/mobile_setup/mysql4-install-0.1.0.php app/etc/modules/Onlinecode_Mobile.xml
Add the following content to fields:
app/code/local/Onlinecode/Mobile/etc/config.xml
code for config.xml
<?xml version="1.0"?> <config> <modules> <Onlinecode_Mobile> <version>0.1.0</version> </Onlinecode_Mobile> </modules> <global> <helpers> <mobile> <class>Onlinecode_Mobile_Helper</class> </mobile> </helpers> <models> <mobile> <class>Onlinecode_Mobile_Model</class> <resourceModel>mobile_mysql4</resourceModel> </mobile> </models> <resources> <mobile_setup> <setup> <module>Onlinecode_Mobile</module> <class>Mage_Customer_Model_Entity_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </mobile_setup> <mobile_write> <connection> <use>core_write</use> </connection> </mobile_write> <mobile_read> <connection> <use>core_read</use> </connection> </mobile_read> </resources> </global> </config>
Add the following content to fields:
app/code/local/Onlinecode/Mobile/Helper/Data.php
code for Data.php
<?php class Onlinecode_Mobile_Helper_Data extends Mage_Core_Helper_Abstract { }
Add the following content to fields:
app/code/local/Onlinecode/Mobile/sql/mobile_setup/mysql4-install-0.1.0.php
code for mysql4-install-0.1.0.php
<?php $installer = $this; $installer->startSetup(); $installer->addAttribute("customer", "mobile", array( "type" => "varchar", "backend" => "", "label" => "Mobile Number", "input" => "text", "source" => "", "visible" => true, "required" => false, "default" => "", "frontend" => "", "unique" => false, "note" => "" )); $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "mobile"); $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();
Add the following content to fields:
app/etc/modules/Onlinecode_Mobile.xml
code for Onlinecode_Mobile.xml
<?xml version="1.0"?> <config> <modules> <Onlinecode_Mobile> <active>true</active> <codePool>local</codePool> <version>0.1.0</version> </Onlinecode_Mobile> </modules> </config>
Once you have uploaded these fields and clear your cache you will notice a new Mobile input field available in the customer admin section (Customers/Manage Customers/Click Customer/Click Account Information).
Mobile Number is now added to the customer account.
Adding Mobile to Customer Account Edit Form.
Create/Edit: app/design/frontend/yourpackage/yourtheme/template/customer/form/edit.phtml
See for Content: http://pastebin.com/90huyGAV
Insert the above code around line 46 before
$_dob = $this->getLayout()->createBlock('customer/widget_dob');
Adding Mobile to Customer Registration form.
Create/Edit: app/design/frontend/yourpackage/yourtheme/template/persistent/customer/form/register.phtml
See for Content: See for Content: http://pastebin.com/mzdFQCbp
Insert the above code around line 57 before
$_dob = $this->getLayout()->createBlock('customer/widget_dob')
You and your customers should now be able to add/edit their mobile number.
Please note this has only been tested on Magento 1.9.0.0 To 1.9.3.7.
Hope this code and post will helped you for implement magento Add new field in Account Information. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org