0

在我的模块(名称=支付)中,我试图在订单中创建一个自定义属性,但我的代码不起作用。

我的文件 pay_setup/mysql4-install-1.0.0.php

$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$attribute  = array(
    'type'          => 'text',
    'backend_type'  => 'text',
    'frontend_input' => 'text',
    'is_user_defined' => true,
    'label'         => 'My Attr',
    'visible'       => true,
    'required'      => false,
    'user_defined'  => false,   
    'searchable'    => false,
    'filterable'    => false,
    'comparable'    => false,
    'default'       => ''
);
$installer->addAttribute('order', 'myattr', $attribute);
$installer->endSetup();

我的 config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Myspacework_Pay>
            <version>1.0.0</version>
        </Myspacework_Pay>
    </modules>
    <frontend>
        <routers>
            <pay>
                <use>standard</use>
                <args>
                    <module>Myspacework_Pay</module>
                    <frontName>pay</frontName>
                </args>
            </pay>
        </routers>
        <layout>
            <updates>
                <pay>
                    <file>pay.xml</file>
                </pay>
            </updates>
        </layout>
    </frontend>
    <global>
        <fieldsets>
            <sales_convert_quote_payment>
                <celphone_no>
                    <to_order_payment>*</to_order_payment>
                </celphone_no>
            </sales_convert_quote_payment>
        </fieldsets>
        <models>
            <pay>
                <class>Myspacework_Pay_Model</class>
                <resourceModel>pay_mysql4</resourceModel>
            </pay>
        </models>
        <resources>
            <pay_setup>
                <setup>
                    <module>Myspacework_Pay</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </pay_setup>
            <pay_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </pay_write>
            <pay_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </pay_read>
        </resources>
        <blocks>
            <pay>
                <class>Myspacework_Pay_Block</class>
            </pay>
        </blocks>
        <helpers>
            <pay>
                <class>Myspacework_Pay_Helper</class>
            </pay>
        </helpers>
    </global>
    <default>
        <payment>
            <pay>
                <active>1</active>
                <model>pay/standard</model>
            </pay>
        </payment>
    </default>
</config>

我在数据库中没有发现“我的属性”的踪迹。任何的想法?

4

1 回答 1

0

我得到了它

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

$installer->addAttribute('order_payment', 'my_attr', array());

$installer->endSetup();

如何在我的 attr 中设置数据。

$order->getPayment()->setMyAttr(utf8_encode($data));
$order->getPayment()->save();
于 2012-09-21T13:27:54.780 回答