Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Add Custom field in Magento Admin Category Management page
 
azizrattani
Jr. Member
 
Total Posts:  1
Joined:  2012-10-16
 

First run a select queries

RUN:

SELECT FROM `eav_attribute_groupWHERE `attribute_group_name` =  '[section name] '

[section name] will be replace with tab name you like to add that field. Write down `attribute_group_id` and `attribute_set_id` for future use

RUN:

SELECT FROM `eav_attribute_setwhere `attribute_set_id` = '[attribute set id]'

[attribute set id] will be replace with one you get after first query. Write down `entity_type_id` for future use

Execute Inster queries:

INSERT INTO `eav_attribute
(`
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 
([Entity Type ID]'[Attribute Code]'NULLNULL'varchar'NULLNULL'text''[Attribute Label]'NULL''00'0'0'');

[Entity Type ID] will be replacing with one we get from second select sql query.
[Attribute Code] will be your attribute filed name(without space; use _ if you want to add space in name)
[Attribute Label] will be label you like to show on category page.

RUN:

SELECT FROM ` eav_attribute WHERE ` attribute_code ` =  '[Attribute code] '

[Attribute code] will be replaced with name you set in above insert sql query. Write down ` attribute_id ` for future use

INSERT INTO `mage_eav_entity_attribute
(`
entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`)
VALUES 
([Entity Type ID][Attribute Set ID][Attribute Group ID]9844);

[Entity Type ID] will be replacing with one we get from second select sql query.
[Attribute Set ID] will be replacing with one you get after first select SQL query.
[Attribute Group ID] will be replacing with one you get after first select SQL query.
[Attribute ID] will be replacing with one you get after third select SQL query.

INSERT INTO `mage_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`) 
VALUES
([Attribute ID]NULL110001000001''000);

[Attribute ID] will be replacing with one you get after third select SQL query.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Hello
Here is an more clean way to do it.
Create a custom module. Let’s call it Easylife_Sql
For this you need the following files
app/etc/modules/Easylife_Sql.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sql>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends><Mage_Catalog/></depends>
        </
Easylife_Sql>
    </
modules>
</
config>
app/code/local/Easylife/Sql/etc/config.xml
<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sql>
            <
version>0.0.1</version
        </
Easylife_Sql>
    </
modules>
    <global>
        <
resources>
            <
easylife_sql_setup>
                <
setup
                    <
module>Easylife_Sql</module>
                    <class>
Mage_Catalog_Model_Resource_Setup</class>
                </
setup>
            </
easylife_sql_setup>
        </
resources>
    </global>
</
config>
These 2 are for configuring the module. Now the fun part. - the install script
app/code/local/Easylife/Sql/sql/easylife_sql_setup/install-0.0.1.php
<?php
$this
->startSetup();
$this->addAttribute('catalog_category''[attribute core here]', array(
    
'group'                => 'General',
    
'type'              => 'varchar',//can be int, varchar, decimal, text, datetime
    
'backend'           => '',
    
'frontend_input'    => '',
    
'frontend'          => '',
    
'label'             => '[Attribute label here]',
    
'input'             => '[attribute input here]'//text, textarea, select, file, image, multilselect
    
'class'             => '',
    
'source'            => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank
    
'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    
'visible'           => true,
    
'frontend_class'     => '',
    
'required'          => false,//or true
    
'user_defined'      => true,
    
'default'           => '',
    
'position'            => 100,//any number will do
));
$this->endSetup();

Now clear the cache and the module should install itself.
The advantages of this approach are:
- portability (you can move it to any other instance)
- you don’t have to worry about running queries - magento will do it for you
- if the internal api changes there ie a high probability this will still work.
- you can use the same module for adding other attributes later: just change the version in config to 0.0.2 and create a file similar to install-0.0.1.php but name it to upgrade-0.0.1-0.0.2.php
- this is the “Magento style” of doing it

Cheers,
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nayan Baraiya
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2011-08-15
 

Thanks,

It help me a lot. its very easy to create custom image field to category images in admin.

Thank you very much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
johnchamley
Jr. Member
 
Total Posts:  4
Joined:  2011-08-09
 
tzyganu - 07 March 2013 04:59 AM

Hello
Here is an more clean way to do it.
Create a custom module. Let’s call it Easylife_Sql
For this you need the following files
app/etc/modules/Easylife_Sql.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sql>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends><Mage_Catalog/></depends>
        </
Easylife_Sql>
    </
modules>
</
config>
app/code/local/Easylife/Sql/etc/config.xml
<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sql>
            <
version>0.0.1</version
        </
Easylife_Sql>
    </
modules>
    <global>
        <
resources>
            <
easylife_sql_setup>
                <
setup
                    <
module>Easylife_Sql</module>
                    <class>
Mage_Catalog_Model_Resource_Setup</class>
                </
setup>
            </
easylife_sql_setup>
        </
resources>
    </global>
</
config>
These 2 are for configuring the module. Now the fun part. - the install script
app/code/local/Easylife/Sql/sql/easylife_sql_setup/install-0.0.1.php
<?php
$this
->startSetup();
$this->addAttribute('catalog_category''[attribute core here]', array(
    
'group'                => 'General',
    
'type'              => 'varchar',//can be int, varchar, decimal, text, datetime
    
'backend'           => '',
    
'frontend_input'    => '',
    
'frontend'          => '',
    
'label'             => '[Attribute label here]',
    
'input'             => '[attribute input here]'//text, textarea, select, file, image, multilselect
    
'class'             => '',
    
'source'            => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank
    
'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    
'visible'           => true,
    
'frontend_class'     => '',
    
'required'          => false,//or true
    
'user_defined'      => true,
    
'default'           => '',
    
'position'            => 100,//any number will do
));
$this->endSetup();

Now clear the cache and the module should install itself.
The advantages of this approach are:
- portability (you can move it to any other instance)
- you don’t have to worry about running queries - magento will do it for you
- if the internal api changes there ie a high probability this will still work.
- you can use the same module for adding other attributes later: just change the version in config to 0.0.2 and create a file similar to install-0.0.1.php but name it to upgrade-0.0.1-0.0.2.php
- this is the “Magento style” of doing it

Cheers,
Marius.

this worked great for me but i had not thought about the tab ! My first tab is ‘general information’ and want the new field in postion 2… can i move this attribute from 2nd tab ‘general’ to 1st tab ‘general information’ ? my new attribute is ‘pagetite’

i have tried creating a new update install-0.0.2.php :
$setup->updateAttribute(’catalog_category’, ‘pagetitle’, ‘group’, ‘general information’ );

i have tried the same file as install-0.0.1.php but editing addAttribute to updateAttribute and ‘group’ => ‘General Information’, saved as install-0.0.3.php.....

im now on attemp 7 !

each time i update config.xml <version>0.0.7</version> and refresh all cache from admin

my module is called ‘PageTitle_Sql.xml’ from mysql> select * from core_resource;
i can see : pagetitle_sql_setup | 0.0.7 | 0.0.7 |

 
Magento Community Magento Community
Magento Community
Magento Community
 
isaacp
Jr. Member
 
Total Posts:  16
Joined:  2012-03-15
 

Thanks tzyganu

One question. Once this script runs and i see the field on the backend should/can I delete these files?

 
Magento Community Magento Community
Magento Community
Magento Community
 
samirshaban
Jr. Member
 
Total Posts:  11
Joined:  2012-10-06
 

Hello,

no need to delete them. Magento handles weather a sql script should run via the version number and the core_resource table.

Greetings
Samir

 
Magento Community Magento Community
Magento Community
Magento Community
 
melow_dee
Jr. Member
 
Total Posts:  1
Joined:  2014-03-26
 
johnchamley - 30 October 2013 03:29 PM


this worked great for me but i had not thought about the tab ! My first tab is ‘general information’ and want the new field in postion 2… can i move this attribute from 2nd tab ‘general’ to 1st tab ‘general information’ ? my new attribute is ‘pagetite’

i have tried creating a new update install-0.0.2.php :
$setup->updateAttribute(’catalog_category’, ‘pagetitle’, ‘group’, ‘general information’ );

i have tried the same file as install-0.0.1.php but editing addAttribute to updateAttribute and ‘group’ => ‘General Information’, saved as install-0.0.3.php.....

im now on attemp 7 !

each time i update config.xml <version>0.0.7</version> and refresh all cache from admin

my module is called ‘PageTitle_Sql.xml’ from mysql> select * from core_resource;
i can see : pagetitle_sql_setup | 0.0.7 | 0.0.7 |

I run in the same trouble:

To know what current version is installed you can look in your database in the table core_resource. In my case the current number was 0.0.2 although i didn’t made any update (not consciously wink)
So i had to change the version number in my config.xml to 0.0.3 and create a php-file mysql4-upgrade-0.0.2-0.0.3.php (mysql4-upgrade-oldNumber-newNumber).php with my changes.

That works for me

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top