How to add new field or attribute to magento customer , customer address or any other table

/
/
263 Views

Hello Friends ,

Some time you want to create or add extra text field to custome or any other module details.  you can create artibutes for product using custom artibutes  from magento admin.  follow this tutorials for create magento product artitbutes .

http://www.w3chacking.com/how-to-create-and-display-custom-attributes-in-magento/

But if you want to create artibutes in other modules or section in magento then you can’t use above tutorials. so after few hours of  search i found the best way to create artibutes in magento

add-new-customer-to-magento-programmiticallyToday i will tell you how to create new field or attribute in magento customer or magento customer address. Add the new customer attribute to the database. you can create a new column and you can also save it’s value to database as well as other artibutes .

Here is code for create artibutes in magento. Just put it in any .phtml file and then run this .phtml file.

Customer Table

$new_arttibute= “taxvattype”; //change this with the name of your attribute

// Add EAV Attributes (accoridng to you  needed)
$eav_arttibute= array(
'type'          => 'varchar',
'label'         => 'Tax/VAT Type',
'visible'       => true,
'required'      => false,
'user_defined'  => false,
'searchable'    => false,
'filterable'    => false,
'comparable'    => false,
);

$setup_new_model = new Mage_Eav_Model_Entity_Setup(‘core_setup’);
//Add to customer
$setup_new_mode->addAttribute(‘customer’, $new_arttibute, $eav_arttibute);

// Here customer mean customer table your can change as per needed
Customer Address Table Example

$new_arttibute= "services_id"; //modify this with the name of your attribute

//a) Add EAV Attributes (modify as you needed)
$attribute  = array(
'type'          => 'varchar',
'label'         => 'Tax/VAT Type',
'visible'       => true,
'required'      => false,
'user_defined'  => false,
'searchable'    => false,
'filterable'    => false,
'comparable'    => false,
);$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
//Add to customer address
$setup->addAttribute('customer_address', $new_arttibute, $attribute);

Sign up for our newsletter to get Daily Updates

It is main inner container footer text