我建议您使用观察者系统来添加新的属性值,但要添加到相关的模型中。也就是说,不要将属性添加到 Order 模型本身,而是创建一个包含 order_id 和自定义属性的模型。挂钩适当的事件(可能是所有订单的 sales_convert_quote_to_order 或前端订单的 checkout_type_onepage_save_order_after)并检查报价项以设置自定义模型中的值。当您执行将订单传输到配送中心的流程时,您可以通过 order_id 查找自定义属性。
You're heading in the right direction, but (as with most things Magento), there are a couple of options. The most important principle here is that the architecture of the modifications must not lead to the situation where upgrades/patches on the core are compromised. What's interesting about that is that Magento has moved away from the highly extensible and upgrade-safe (mostly) EAV model for Mage_Sales_Model_Order (and related objects) in the current release. That makes it more difficult to add attributes in a upgrade-safe manner, IMHO.
I would recommend that you use the Observer system to add your new attribute values, but into a related Model. That is, rather than adding the attribute into the Order model itself, create a model that holds an order_id and your custom attributes. Hook into the appropriate event (probably sales_convert_quote_to_order for all Orders or checkout_type_onepage_save_order_after for frontend orders) and examine the Quote Items to set the values in your custom Model. When you execute your process to transmit orders to the fulfilment house, you can lookup the custom attributes via the order_id.
发布评论
评论(2)
您正朝着正确的方向前进,但是(与 Magento 的大多数事情一样),有几个选择。这里最重要的原则是修改的架构不能导致核心上的升级/补丁受到损害的情况。有趣的是,Magento 在当前版本中已经放弃了 Mage_Sales_Model_Order(以及相关对象)的高度可扩展和升级安全(大部分)的 EAV 模型。恕我直言,这使得以升级安全的方式添加属性变得更加困难。
我建议您使用观察者系统来添加新的属性值,但要添加到相关的模型中。也就是说,不要将属性添加到 Order 模型本身,而是创建一个包含
order_id
和自定义属性的模型。挂钩适当的事件(可能是所有订单的sales_convert_quote_to_order
或前端订单的checkout_type_onepage_save_order_after
)并检查报价项以设置自定义模型中的值。当您执行将订单传输到配送中心的流程时,您可以通过order_id
查找自定义属性。You're heading in the right direction, but (as with most things Magento), there are a couple of options. The most important principle here is that the architecture of the modifications must not lead to the situation where upgrades/patches on the core are compromised. What's interesting about that is that Magento has moved away from the highly extensible and upgrade-safe (mostly) EAV model for
Mage_Sales_Model_Order
(and related objects) in the current release. That makes it more difficult to add attributes in a upgrade-safe manner, IMHO.I would recommend that you use the Observer system to add your new attribute values, but into a related Model. That is, rather than adding the attribute into the Order model itself, create a model that holds an
order_id
and your custom attributes. Hook into the appropriate event (probablysales_convert_quote_to_order
for all Orders orcheckout_type_onepage_save_order_after
for frontend orders) and examine the Quote Items to set the values in your custom Model. When you execute your process to transmit orders to the fulfilment house, you can lookup the custom attributes via theorder_id
.另一个(更好?)选择是遵循 Ivan 的建议 Magento - 向 sales_flat_quote_item 和 sales_flat_order_item 添加新列,并使用 Magento 的销售设置类以升级安全的方式将数据添加到 sales_flat_order 表中。
Another (better?) option is to follow Ivan's advice at Magento - Adding a new column to sales_flat_quote_item and sales_flat_order_item and use Magento's sales setup class to add your data onto the sales_flat_order table in an upgrade-safe manner.