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

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

问题描述

我正在尝试向订单添加自定义字段.这时,我发现下面的文章可以帮助我在数据库中创建这样的属性: http://fabrizioballiano.net/2011/11/15/create -a-custom-order-at-at-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中的gobal范围.然后只需在报价中设置属性-它就自动转换为报价到订单转换过程中的订单.

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>

您可以通过魔术获取/设置器随时检索/设置属性.

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天全站免登陆