在magento的catalog_category_entity表中添加两列

时间:2014-06-25 12:57:01

标签: magento categories

我想在添加类别时在catalog_category_entity表中存储两列。我修改了像

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

并修改了app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.phpsaveAction()文件中的代码。在$category->addData($data['general']);行之后我添加了

$category->setCategoryOwner(1);
$category->setCategoryType(1);
这两行。但它没有保存在catalog_category_entity表中。 我需要更改吗?请帮帮我。

提前致谢。

2 个答案:

答案 0 :(得分:1)

not good idea to add new columns in catalog_category_entity table最好创建new category attribute using installer

创建扩展程序app/code/local/Bh/Categoryattribute/etc/config.xml并编码

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

安装程序代码app\code\local\Bh\Categoryattribute\sql\categoryattribute_setup\mysql4-install-0.0.1.php和代码

<?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();'

是/不使用

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

答案 1 :(得分:0)

请清除缓存,然后重试。

删除var / cache目录