How to create a Category Attribiute in magento

Jul 28, 2011   //   by kdecom   //   magento  //  No Comments


Yesterday i face a new problem. So what i want is to create a category Attribute for magento.
I know how to create a category attribute in magento if you building you own module.
But i just want a single attribute and it dont really need a custom module for that.

Well if anyone want to create a categgory attribute for their extension they can use this code:

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

$setup->addAttribute(‘catalog_category’, ‘YOUR_ATTRIBUTE_CODE’, array(
‘group’ => ‘General’,
‘input’ => ‘text’,
‘type’ => ‘varchar’,
‘backend’ => ”,
‘visible’ => 1,
‘required’ => 0,
‘user_defined’ => 1,
‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,


But yes my origional problem was create an extra attribute for category without any custom module.

Here is what i did it to create to the attribute:-



VALUES(9,’ATTRIBUTE_CODE’,NULL,”,’varchar’,”,”,’text’,NULL,’ATTRIBUTE TITLE, NULL, ”, 0, 1, 0, 0, ”, 0, 0, 0, 0, 0, 0, 0, 1, ”, 1, ‘,1,0,0,0);

To check before you run this query….
Just make sure your entity_type_id for catalog/category is 9.
If not then just replace that.

Then i have to run another query this is where tricky parts comes…..

INSERTINTO`eav_entity_attribute` (`entity_attribute_id`,`entity_type_id`,`attribute_set_id`,`attribute_group_id`, `attribute_id`,`sort_order`)

Make sure list
entity_attribute_id in my case it is 4500.

How to get that id…
open your phpmyadmin Go to table name eav_entity_attribute

Run the query

SELECT entity_attribute_id
FROM eav_entity_attribute

My result was 4999.

Now whatever the results comes up add one in that its your entity_attribute_id.
My case 4999+1 = 4500 (entity_attribute_id).

I hope that make sense.

and second problem is 950 which is the attribte id that you get from the first query.

I hope this make sense…

Leave a comment