Magento 1.9.2自定义属性不起作用

时间:2016-06-20 18:53:39

标签: magento attributes magento-1.9

我到处搜寻,但由于某种原因无法找到答案。我的第一个属性是保存并在我的数据库中工作,但我的第二个属性不起作用。我相信我的安装程序脚本没有被执行,这令人非常沮丧。这就是我所拥有的:

app/local/Name/Module/sql/name_module_setup/mysql4-upgrade-0.1.0-0.1.1.php

(请注意我在.../mysql4-install-0.1.0.php.../mysql4-install-0.1.1.php中使用了相同的脚本以尝试不同的事情。

    <?php
require_once('app/Mage.php');

$installer = $this;
$installer->startSetup();
//$installer = new Mage_Sales_Model_Mysql4_Setup; //this line has been both commented and non-commented

$attribute  = array(
    'type'          => 'text',
    'backend_type'  => 'text',
    'frontend_input' => 'text',
    'is_user_defined' => false,
    'label'         => 'Custom ID',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,
    'searchable'    => true,
    'filterable'    => true,
    'comparable'    => true,
    'default'       => 'Test'
);
$installer->addAttribute('order', 'custom_id', $attribute);

$attribute  = array(
    'type'          => 'int',
    'backend_type'  => 'int',
    'frontend_input' => 'int',
    'is_user_defined' => false,
    'label'         => 'Custom Number',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,
    'searchable'    => true,
    'filterable'    => true,
    'comparable'    => true,
    'default'       => '0'
);
$installer->addAttribute('order', 'custom_number', $attribute);

error_log("The new custom number attribute is being made",0); //Never sent to error_log
$installer->endSetup();

...应用程序/本地/名称/模块的/ etc / config.xml中

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Name_Module>
            <version>0.1.1</version><!--Tried 0.1.0 and 0.1.1-->
        </Name_Module>
    </modules>
    <global>
        <models>
            <name_module>
                <class>Name_Module_Model</class>
            </name_module>
        </models>
        ...
        <resources>
            <name_module_setup>
                <setup>
                    <module>Name_Module</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </name_module_setup>
            <module_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </module_write>
            <module_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </module_read>
        </resources>
        <fieldsets>
            <sales_convert_quote>
                <custom_id>
                    <to_order>*</to_order>
                </custom_id>
                <custom_number>
                    <to_order>*</to_order>
                </custom_number>
            </sales_convert_quote>
        </fieldsets>
    </global>
    ...
</config>

我觉得我已经尝试了一切......任何帮助都会很棒!提前谢谢!

2 个答案:

答案 0 :(得分:1)

所以我终于明白了...出于某种原因,我不得不进入 phpmyadmin 并转到core/resource并删除包含模块,刷新缓存和行的行再试一次。之后,安装程序脚本运行了!希望这可以帮助别人!

答案 1 :(得分:0)

您可以尝试以下代码

<?php

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('order', 'custom_id', array(
    'type'          => 'text',
    'backend_type'  => 'text',
    'frontend_input' => 'text',
    'is_user_defined' => false,
    'label'         => 'Custom ID',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,
    'searchable'    => true,
    'filterable'    => true,
    'comparable'    => true,
    'default'       => 'Test'

));

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('order', 'custom_number', array(
    'type'          => 'int',
    'backend_type'  => 'int',
    'frontend_input' => 'int',
    'is_user_defined' => false,
    'label'         => 'Custom Number',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,
    'searchable'    => true,
    'filterable'    => true,
    'comparable'    => true,
    'default'       => '0'
));

$installer->endSetup();

尝试清除magento缓存并检查。