You need to add new file(installer script) and the file name should be,
mysql4-upgrade-0.0.2-0.0.1.php
So now in this you can add your installer script like,
$installer = $this;
$installer->startSetup();
$entity = $installer->getEntityTypeId('customer');
if(!$installer->attributeExists($entity, 'attribute_2')) {
$installer->removeAttribute($entity, 'attribute_2');
}
$installer->addAttribute($entity, 'attribute_2', array(
'type' => 'text',
'label' => 'Attribute 2',
'input' => 'text',
'visible' => TRUE,
'required' => FALSE,
'default_value' => '',
'adminhtml_only' => '0'
));
$forms = array(
'adminhtml_customer',
'customer_account_edit'
);
$attribute = Mage::getSingleton('eav/config')->getAttribute($installer->getEntityTypeId('customer'), 'attribute_2');
$attribute->setData('used_in_forms', $forms);
$attribute->save();
$installer->endSetup();
And you need to update the config.xml file also. So it should be,
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Custom_Customerattribute>
<version>0.0.2</version>
</Custom_Customerattribute>
</modules>
<global>
<resources>
<customerattribute_setup>
<setup>
<module>Custom_Customerattribute</module>
<class>Custom_Customerattribute_Model_Mysql4_Setup</class>
</setup>
....
</customerattribute_setup>
</resources>
</global>
</config>
For more information, go here. If you have any doubt please comment here.
Update:
I'm sorry. The file name should be like this,
mysql4-upgrade-0.0.2-0.0.1.php
The core_resource
table contains module entries. Now the 0.0.2
is also updated. So magento will not look up your module(updated) xml files to load. so you need to again change the file name to mysql4-upgrade-0.0.3-0.0.2.php
or delete that entry in your database and rename your module version to fresh like mysql4-upgrade-0.0.0.php
Update-2:
Here I have attached new codes, I checked in my local its working fine,
app/code/local/Packagename/Modulename/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Packagename_Modulename>
<version>0.0.0</version>
</Packagename_Modulename>
</modules>
<global>
<helpers>
<modulename>
<class>Packagename_Modulename_Helper</class>
</modulename>
</helpers>
<models>
<modulename>
<class>Packagename_Modulename_Model</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename>
</models>
<resources>
<customerattribute1415104755_setup>
<setup>
<module>Packagename_Modulename</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattribute1415104755_setup>
<customerattribute1415104755_write>
<connection>
<use>core_write</use>
</connection>
</customerattribute1415104755_write>
<customerattribute1415104755_read>
<connection>
<use>core_read</use>
</connection>
</customerattribute1415104755_read>
</resources>
</global>
</config>
app/code/local/Packagename/Modulename/Helper/Data.php
<?php
class Packagename_Modulename_Helper_Data extends Mage_Core_Helper_Abstract
{
}
app/code/local/Packagename/Modulename/sql/customerattribute1415104755_setup/mysql4-install-0.0.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "myattrbute1", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-1",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute1");
$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->addAttribute("customer", "myattrbute2", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-2",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute2");
$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->addAttribute("customer", "myattrbute3", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-3",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute3");
$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->addAttribute("customer", "myattrbute4", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-4",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute4");
$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();
And finally enable your module in,
app/etc/modules/Packagename_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Packagename_Modulename>
<active>true</active>
<codePool>local</codePool>
<version>0.0.0</version>
</Packagename_Modulename>
</modules>
</config>