Adding a new attribute
This is an old revision of the document!
In order to add a new attribute to your magento installation, you can use following method:
Create an instance of Mage_Eav_Model_Entity_Setup class and use its method addAttribute() to add one.
- $code = 'my_attribute';
- $attr = array(
- 'entity_type_id' => $entity_type_id,
- 'backend_type' => 'int',
- 'is_user_defined' => 1,
- 'frontend_input' => 'test',
- 'is_visible' => 0,
- );
- $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
- $setup->addAttribute($entityTypeId, $code, $attr);
$attr is an array containing Attribute elements (like frontend and backend model, default value, etc.) Look at eav_attribute table for all possible keys.
$entity_type_id is a value from the db table eav_entity_type.entity_type_id
For details look at the sourcecode:
app/code/core/Mage/Eav/Model/Entity/Setup.php


