在我的模块(name = pay)中,我尝试在订单中创建自定义属性,但我的代码不起作用。
我的文件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>
我在数据库中找不到“my attr”的痕迹。 有什么想法吗?
答案 0 :(得分:0)
我明白了
$installer = $this;
$installer->startSetup();
$installer->addAttribute('order_payment', 'my_attr', array());
$installer->endSetup();
如何在我的attr。
中设置数据$order->getPayment()->setMyAttr(utf8_encode($data));
$order->getPayment()->save();