user3774974
user3774974

Reputation: 1

add two columns in catalog_category_entity table in magento

I want to store two columns in catalog_category_entity table while adding a category. I modified the query like

ALTER TABLE `catalog_category_entity` ADD `category_type` ENUM( '1', '0' ) NOT NULL ,
ADD `category_owner` INT NOT NULL COMMENT 'stored vendor_id'

and modified the code in app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php file in saveAction(). After $category->addData($data['general']); line I added

$category->setCategoryOwner(1);
$category->setCategoryType(1);

these two lines. But it is not saving in catalog_category_entity table. Shall I need to change anywhere more? Please help me.

Thanks in advance.

Upvotes: 0

Views: 1079

Answers (2)

Amit Bera
Amit Bera

Reputation: 7611

It is not good idea to add new columns in catalog_category_entity table it is good idea to create new category attribute using installer.

create an extension app/code/local/Bh/Categoryattribute/etc/config.xml and it code

<?xml version="1.0"?>
<config>
    <modules>
        <Bh_Categoryattribute>
            <version>0.0.1</version>
        </Bh_Categoryattribute>
    </modules>

    <global>
        <resources>
            <categoryattribute_setup>
                <setup>
                    <module>Bh_Categoryattribute</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </categoryattribute_setup>
            <categoryattribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </categoryattribute_write>
            <categoryattribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </categoryattribute_read>
        </resources>
    </global>
</config>

code of installer app\code\local\Bh\Categoryattribute\sql\categoryattribute_setup\mysql4-install-0.0.1.php and code is

<?php
$this->startSetup();
$this->addAttribute('catalog_category', 'category_owner', array(
    'group'         => 'General Information',
    'input'         => 'text',
    'type'          => 'int',
    'label'         => 'Category Owner',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
 $this->addAttribute('catalog_category', 'category_type', array(
    'group'         => 'General Information',
    'input'         => 'text',
    'type'          => 'int',
    'label'         => 'Category Type',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->endSetup();'

for yes/no use below

$this->addAttribute('catalog_category', 'category_type', array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Top Hersteller',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => '',
    'source'            => 'eav/entity_attribute_source_boolean,//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
));

app/etc/modules/Bh_Categoryattribute.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Bh_Categoryattribute>
            <active>true</active>
            <codePool>local</codePool>
        </Bh_Categoryattribute>
    </modules>
</config>

Upvotes: 1

Dharmesh Hariyani
Dharmesh Hariyani

Reputation: 394

Please clear cache and than try again.

Delete var/cache directory

Upvotes: 0

Related Questions