Is there any clean way to add custom field to all product attributes in Magento? Catalog -> Attributes -> Manage Attributes -> (Add new/Edit) Attribute page.

Something like it can be done for catalog category:

$setup = new Mage_Eav_Model_Entity_Setup("core_setup");
// below code will add text attribute
$setup->addAttribute("catalog_category", "attribute_code", array(
"group"         => "General",
"input"         => "text",
"type"          => "varchar",
"label"         => "Attribute label",
"backend"       => "",
"visible"       => 1,
"required"      => 0,
"user_defined" => 1,
"global"        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

There is no record in eav_entity_type table for attributes, so i can not use this method. Is there any suggestion on the best way for adding this custom field for attributes.

  • What you do there for the category is adding an attribute for the category. This can be done for products as well (adding attributes for products -> just in the backend). What you want is to "add attributes to eav attributes". In pseudo code something like addAttribute('eav_attribute' ...)` – Alex Jul 31 '13 at 9:25
  • Hi Alex, thanks for your comment. What class should I use to add a custom field to attribute edit page this way. Using the example above $setup = new Mage_Eav_Model_Entity_Setup("core_setup"); // below code will add text attribute $setup->addAttribute("eav_attribute", "attribute_code", array(...) I receiving Wrong entity ID error. I am new to Magento so it is not clear for me. – Vitaliy Povar Jul 31 '13 at 9:49
  • Hi, a bit confused by your question. Are you asking how to add an attribute to a product? Or how to add a new option field to the admin backend attribute editor? – ProxiBlue Aug 9 '13 at 4:41
  • Just to confirm: Have you have tried Alex's suggestion $setup->addAttribute("catalog_product","your_attribute_code", with the rest as you already posted it. – Kristof at Fooman Aug 10 '13 at 15:30

There is no record in eav_entity_type table for attributes

The only attribute connection in the eav_entity_type table is a field (addition_attribute_table) which points to additional attribute metadata for each type.

The fields in the Catalog > Attributes > Manage Attributes create/edit views are attribute metadata and map to the columns in the eav_attribute and catalog_eav_attribute tables. The canonical attribute record and cross-entity metadata are in the former table, while catalog attribute metadata are in the latter table.

In order to have another field in the referenced view, you either need to rewrite the Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main class or (more flexibly) add another tab which contains the input for your custom field. You will also need to add your column to the catalog_eav_attribute table.

You might want to rewrite the Mage_Catalog_Model_Resource_Product_Attribute_Collection model if you need to conveniently apply filtering conditions based on your field, and you might consider rewriting Mage_Catalog_Model_Resource_Setup::_prepareValues() if you want to specify a default value for your field.

Pretty neat!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.