Magento - 为订单添加自定义属性 [英] Magento - Add custom attribute to order

查看:30
本文介绍了Magento - 为订单添加自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的订单添加自定义字段.此时,我发现下面的帖子帮助我在我的数据库中创建了这样的属性:http://fabrizioballiano.net/2011/11/15/create-a-custom-order-attribute-in-magento/

I'm trying to add a custom field to my orders. At this moment, I found the post bellow that helped me to create such attribute in my database: http://fabrizioballiano.net/2011/11/15/create-a-custom-order-attribute-in-magento/

require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

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

执行上述代码并创建多个订单后,我可以遍历所有订单并查看每个订单的默认值.

After executing the code above and creating several orders, I'm able to loop through all orders and see the default value to the every order.

问题是,如何在这个字段中存储我想要的数据?如何检索此类数据?

The question is, how can I store the data I want in this field? How can I retrieve such data?

谢谢!

推荐答案

将此添加到 config.xml 中的全局范围.然后只需在报价单中设置属性 - 它会自动转移到报价单到订单转换过程中的订单.

Add this to the gobal scope in config.xml. Then simply set the attribute in the quote - it gets automagically transferred to the order in the quote to order conversion process.

<global>
...
    <fieldsets>
        <sales_convert_quote>
            <your_special_attribute>
                <to_order>*</to_order>
            </your_special_attribute>
        </sales_convert_quote>
    </fieldsets>
...
</global>

您可以随时通过魔法 getter/setter 检索/设置属性,例如

You can retrieve/set the attribute at any time via the magic getter/setter e.g.

$quote->getYourSpecialAttribute()
$order->getYourSpecialAttribute()

$quote->setYourSpecialAttribute()

这篇关于Magento - 为订单添加自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆