How to create a Category Attribiute in magento

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

hiya,

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’);
$installer->startSetup();

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

$installer->endSetup();

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:-

INSERTINTO`eav_attribute`

(`entity_type_id`,`attribute_code`,`attribute_model`,`backend_model`,`backend_type`,`backend_table`,`frontend_model`,`frontend_input`,`frontend_input_renderer`,`frontend_label`,`frontend_class`,`source_model`,`is_global`,`is_visible`,`is_required`,`is_user_defined`,`default_value`,`is_searchable`,`is_filterable`,`is_comparable`,`is_visible_on_front`,`is_html_allowed_on_front`,`is_unique`,`is_visible_in_advanced_search`,`is_configurable`,`apply_to`,`position`,`note`,`is_used_for_price_rules`,`is_filterable_in_search`,`used_in_product_listing`,`used_for_sort_by`)

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`)
VALUES(4500,9,12,7,950,2);

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
ORDER BY DESC

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

css.php