Magento 自定义订单属性/字段?搬起石头砸自己的脚?

发布于 2024-09-26 18:17:04 字数 1431 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2024-10-03 18:17:04

您正朝着正确的方向前进,但是(与 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 (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.

╰ゝ天使的微笑 2024-10-03 18:17:04

另一个(更好?)选择是遵循 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文