magento将自定义列添加到eav_attribute表

时间:2016-03-11 14:58:02

标签: magento magento-1.9

我想将自定义字段(数据库中的列)添加到表eav_attribute 这是我在t

中的配置模型和资源
 <models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <module>Mage_Eav</module>
        <module>Mage_Eav_Model_Entity_Setup</module>
    </mycompany_filters_setup>
</resources>

目录树

sql
 -- mycompany_filters_setup
  -- install-0.1.4.php

和内容文件install-0.1.4.php

<?php

$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */

$installer->startSetup();

$installer->getConnection()->addColumn(
    $installer->getTable('eav/attribute'), 
    "is_used_in_category", 
    "TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'"
);

$installer->endSetup();

但这不起作用。在表core_resource中,不为mycompany_filters创建字符串资源,而在表eav_attribute中不创建新列。

错误日志:system.log和exception.log apache2 log为空

主要问题为什么不起作用?

1 个答案:

答案 0 :(得分:3)

我想指出一些我认为错误的事情。

首先是config.xml

<models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <module>Mage_Eav</module>
        <module>Mage_Eav_Model_Entity_Setup</module>
    </mycompany_filters_setup>
</resources>

应该是:

<models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <setup>
            <module>Mage_Eav</module>
            <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <!-- You could add these as well
        <connection>
            <use>core_setup</use>
        </connection>
        -->
    </mycompany_filters_setup>
    <!-- If you add the connection tag above, you should add these as well
    <filters_write>
        <connection>
            <use>core_write</use>
        </connection>
    </filters_write>
    <filters_read>
        <connection>
            <use>core_read</use>
        </connection>
    </filters_read>
    -->
</resources>

基本上,您缺少应包含资源<setup><module>标记的<class>标记。

install-0.1.4.php的内容应改为:

$installer = $this;
$installer->startSetup();

$table = $installer->getTable('eav/attribute');
$installer->getConnection()
        ->addColumn($table, 'is_used_in_category', array(
            'type'      => 'could be Varien_Db_Ddl_Table::TYPE_TEXT or any you want it should be,
            'nullable'  => 'could be true or false',
            'default'   => null,
            'unique'    => 'could be true or false',
            'comment'   => 'Your comment here. Not important'
        ));

$installer->endSetup();

config.xml中,确保声明的版本与0.1.4相同。 在完成这些更改后清除您的CACHE并运行您的应用

希望它有所帮助。