First create xml file in etc/module named as: Bd_Customercustomfield
<?xml version="1.0"?>
<config>
<modules>
<Bd_Customercustomfield>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Bd_Customercustomfield>
</modules>
</config>
Then create config file of your module with following code
<?xml version="1.0"?>
<config>
<modules>
<Bd_Customercustomfield>
<version>0.1.0</version>
</Bd_Customercustomfield>
</modules>
<global>
<helpers>
<customercustomfield>
<class>Bd_Customercustomfield_Helper</class>
</customercustomfield>
</helpers>
<models>
<customercustomfield>
<class>Bd_Customercustomfield_Model</class>
<resourceModel>customercustomfield_mysql4</resourceModel>
</customercustomfield>
</models>
<resources>
<customerattribute_setup>
<setup>
<module>Bd_Customercustomfield</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattribute_setup>
<customerattribute_write>
<connection>
<use>core_write</use>
</connection>
</customerattribute_write>
<customerattribute_read>
<connection>
<use>core_read</use>
</connection>
</customerattribute_read>
</resources>
</global>
</config>
At last create a mysql file mysql4-install-0.1.0.php with following code
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "customer_mobile", array(
"type" => "varchar",
"backend" => "",
"label" => "Mobile Number",
"input" => "text",
"source" => "",
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => "Customer Mobile Number"
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "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";
$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();
?>
<?xml version="1.0"?>
<config>
<modules>
<Bd_Customercustomfield>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Bd_Customercustomfield>
</modules>
</config>
Then create config file of your module with following code
<?xml version="1.0"?>
<config>
<modules>
<Bd_Customercustomfield>
<version>0.1.0</version>
</Bd_Customercustomfield>
</modules>
<global>
<helpers>
<customercustomfield>
<class>Bd_Customercustomfield_Helper</class>
</customercustomfield>
</helpers>
<models>
<customercustomfield>
<class>Bd_Customercustomfield_Model</class>
<resourceModel>customercustomfield_mysql4</resourceModel>
</customercustomfield>
</models>
<resources>
<customerattribute_setup>
<setup>
<module>Bd_Customercustomfield</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattribute_setup>
<customerattribute_write>
<connection>
<use>core_write</use>
</connection>
</customerattribute_write>
<customerattribute_read>
<connection>
<use>core_read</use>
</connection>
</customerattribute_read>
</resources>
</global>
</config>
At last create a mysql file mysql4-install-0.1.0.php with following code
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "customer_mobile", array(
"type" => "varchar",
"backend" => "",
"label" => "Mobile Number",
"input" => "text",
"source" => "",
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => "Customer Mobile Number"
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "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";
$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();
?>
Hi, nice tutorial..
ReplyDeleteI have one doubt. What´s the folder of code for the source model??
<?php
class Excellence_Profile_Model_Entity_School extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
public function getAllOptions()
......
}
}
I´m using Magento 1.6.2
Thanks
Hey, create directory as
ReplyDeleteapp\code\local\Excellence\Profile\Model\Entity\School.php
Open following file
ReplyDeleteshop/app/design/frontend/default/helloeuropa/template/customer/form/register.phtml
And copy/paste setShowAddressFields(true)?> at the top
thank you for the post. really useful one. i spent much time for learning some information about magento coding. but i make a conclusion that use magento extensions more profitable than try to do some things by yourself.
ReplyDeleteNot some time ago i bought amasty's customer attributes extension and now i don't know any problems with attributes
Hi Bhoopendra ,
ReplyDeletecool blog,Thanks for sharing this information .
Magento Developers
Dear Bhupendra,
ReplyDeleteI don't understand why any body do not write the exact things for each & every step...To get the options you have written to put getalloptions() function but the thing is I do not have any custom module then where to put that code? I searched approx. all the articles but none said where to put this code in case if you do not have custom module. Can you please give solution for this?
Thanks
Kaushal
Ctrl+C Ctrl+V detected
ReplyDeletehttp://www.excellencemagentoblog.com/customer-registration-fields-magento1-6
Hello, I need some help in the magento theme creation. If possible can you share your email id with me or if you dont mind can you share your gtalk r skype or fb id. So that i can discuss with you.
ReplyDeleteThanks
It's ok. You can contact me on d.bhoopendra@gmail.com.
Delete