Adding new field in category section of magento ecommerce

Posted by Damodar Bashyal on April 23, 2010

 

How to add new fields in magento e-commerce?

There is no easy method like adding product attribute for category yet. But we can achieve this by adding from database. You just need to deal with three tables in the database.

First one is: eav_attribute

Insert details as: [change as you need]

`attribute_id` = '',
`entity_type_id` = 9,
`attribute_code` = 'logo_size',
`attribute_model` = NULL,
`backend_model` = '',
`backend_type` = 'text',
`backend_table` = '',
`frontend_model` = '',
`frontend_input` = 'textarea',
`frontend_label` = 'Embroidery Size Options',
`frontend_class` = NULL,
`source_model` = '',
`is_required` = 0,
`is_user_defined` = 0,
`default_value` = '',
`is_unique` = 0,
`note` = ''

Note the inserted attribute_id's value and insert data on another table: eav_entity_attribute

`entity_attribute_id` = '',
`entity_type_id` = 9,
`attribute_set_id` = 12,
`attribute_group_id` = 7,
`attribute_id` = 968, [attribute_id you get from first table insert]
`sort_order` = 8

Now the final one: catalog_eav_attribute

`attribute_id` = 968, [attribute_id you get from first table insert]
`frontend_input_renderer` = NULL,
`is_global` = 0
`is_visible` = 1,
`is_searchable` = 0,
`is_filterable` = 0,
`is_comparable` = 0,
`is_visible_on_front` = 0,
`is_html_allowed_on_front` = 0,
`is_used_for_price_rules` = 1,
`is_filterable_in_search` = 0,
`used_in_product_listing` = 0,
`used_for_sort_by` = 0,
`is_configurable` = 1,
`apply_to` = '',
`is_visible_in_advanced_search` = 0,
`position` = 1,
`is_wysiwyg_enabled` = 0

Thats all you need to do to add new field in the manage category for magento e-commerce based websites.

Same as other values you can get the value of this field in the frontend template as below:

$this->getCurrentCategory()->getLogoSize();

You can modify rest as your need.

UPDATE:

Sql statement used to insert new field in magento category manager version 1.4.2.0. This should work in latest magento but i haven't tested myself.

//eav_attribute
//===========
INSERT INTO `eav_attribute` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES ('', 3, 'cat_bg_hex', NULL, '', 'varchar', '', '', 'text', 'bg hex value', '', '', 1, 0, '', 0, '');
//insert_id: 134
//eav_entity_attribute
//=================
INSERT INTO `eav_entity_attribute` (`entity_attribute_id`, `entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`) VALUES ('', 3, 3, 3, 134, 10);
//catalog_eav_attribute
//==================
INSERT INTO `catalog_eav_attribute` (`attribute_id`, `frontend_input_renderer`, `is_global`, `is_visible`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_used_for_price_rules`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `position`, `is_wysiwyg_enabled`, `is_used_for_promo_rules`) VALUES (134, '', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, '', 0, 0, 0, 0);

Magento Development posted on - Tuesday 21st of December 2010 05:17:10 PM

Oh Great! Thanks for sharing.

Magento Themes posted on - Friday 24th of December 2010 06:18:18 PM

Thanks for your excellent tips. I have learnt to insert new field in a category on magento ecommerce by your post.

Magento Developer posted on - Tuesday 18th of January 2011 05:05:30 AM

How can i add attribute type with select option to magento category ?

Damodar Bashyal posted on - Tuesday 20th of May 2014 07:21:54 AM

to add new seo description field in new magento versions 1.4.*

[code brush=php]
INSERT INTO `eav_attribute` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES
('', 3, 'seo_description', NULL, '', 'text', '', '', 'textarea', 'Seo Description', '', '', 0, 0, '', 0, ''); 119



INSERT INTO `eav_entity_attribute` (`entity_attribute_id`, `entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`) VALUES
('', 3, 3, 3, 119, 5);


INSERT INTO `catalog_eav_attribute` (`attribute_id`, `frontend_input_renderer`, `is_global`, `is_visible`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_used_for_price_rules`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `position`, `is_wysiwyg_enabled`, `is_used_for_promo_rules`) VALUES
(119, '', 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, '', 0, 0, 1, 1);
[/code]

Max posted on - Saturday 14th of April 2012 10:19:53 PM

Magento is an open source eCommerce platform that enables entrepreneurs to set up virtual storefront easily. With its distinct features of setting up multiple stores with single administration panel, easy orders tracking options, supports multiple payment gateways etc, it has established an essential place in the world of ecommerce development services.

ilan posted on - Tuesday 24th of April 2012 11:11:14 PM

It is working on last Magento release 1.6.2.0

Cheers, and thank you

karan posted on - Wednesday 3rd of October 2012 11:23:40 AM

I Try in This Site But Not Work Please Help Me......

Surbhi Sheth posted on - Thursday 19th of September 2013 01:57:35 AM

Magento Insertion Extension helps eCommerce websites to import products in bulk & integrate feeds into Magento store. With use of product insertion extension, they can easily import group products, Cross-sell, Upsell & Related products, CSV, PDF, and Image Files supported and more.

Vijay posted on - Tuesday 15th of July 2014 09:36:58 PM

We have added the new column in categories .We tried to add the column using the above SQL query as described in the tutorial but after adding the column we are getting the below error while trying to access the category menu admin section.
Fatal error: Call to a member function setData() on a non-object in C:\xampp\htdocs\magento1_8\app\code\core\Mage\Eav\Model\Config.php on line 651
 
not published on website


QR Code: Adding new field in category section of magento ecommerce