Magento 如何将订购的产品保存在数据库中?

发布于 2024-11-02 20:06:42 字数 148 浏览 0 评论 0原文

发送订单后,Magento 如何保存订单产品(在 sales_flat_order_item 表中)。我需要这些文件,因为我也想将常规价格保存在数据库中;如果你有特价 Magento 仅在有人下订单时将特价保存在数据库中。 或者有人知道如何在数据库中保存每个订购产品的常规价格吗?

After I send an order , how does Magento save the order products (in sales_flat_order_item table). I need the files, because I want to save the regular price in database also; if you have special price Magento only saves the special price in database when somebody make an order.
Or does anyone have any idea how can I save the regular price in database for each ordered product?

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

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

发布评论

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

评论(2

梦里寻她 2024-11-09 20:06:42

慢慢地?小心?用SQL?我开玩笑,我开玩笑。

老实说,是的,您是正确的,订单项目表中存储的唯一数据是客户实际支付的价格(而不是正常价格)。如果要保存该表上的额外数据,请执行以下操作:

  1. 使用安装程序 SQL 脚本创建新模块
  2. 让模块的安装程序向订单项表添加新列
  3. 将观察者添加到预保存事件订单项
  4. 让观察者将常规价格记录到新列中

现在,您应该在数据库中拥有该数据,并且能够像任何其他列一样正常检索它。希望有帮助!

谢谢,

Slowly? Carefully? With SQL? I kid, I kid.

In all honesty, yes you are correct that the only data stored on the order item table is the price that the customer actually paid (as opposed to the regular price). If you want to save your extra data on that table, do the following:

  1. Create a new module with an installer SQL script
  2. Have the installer of your module add a new column to the order item table
  3. Add an observer to the pre-save event on an order item
  4. Make that observer record the regular price into your new column

Now, you should have that data in the DB and be able to retrieve it normally like any other column. Hope that helps!

Thanks,
Joe

天生の放荡 2024-11-09 20:06:42

我很好奇为什么你甚至需要将原始价格存储在表中...当你循环遍历订单的项目时,你总是可以动态查找它:

$origPrice = Mage::getModel('catalog/product')->load($item->getProductId())->getData('price');

或者你可以编写自己的模块来创建'sales_flat_order_item' 中的新列,或创建您自己的表来引用该表中的特定 ID。您可以让您的模块观察订单成功事件,并循环遍历订单中的所有产品并在数据库中设置值。

就像约瑟夫在上面的评论中所说的那样,你永远不应该修改核心代码。如果您需要进行更改,请编写适当的模块来执行此操作。如果您正在修改核心代码(或者,在我看来,如果您正在创建此目录:app/code/local/Mage/),那么您就做错了。

I'm curious why you even need to have the original price stored in the table... You could always look it up on the fly when you are looping through items of an order:

$origPrice = Mage::getModel('catalog/product')->load($item->getProductId())->getData('price');

Or you could write your own module that creates either the new column in 'sales_flat_order_item', or create your own table that references the particular id in that table. You could have your module observe the order success event, and loop through all the products in the order and set the value in the database.

Like Joseph said in a comment above, you should NEVER modify core code. If you need to make a change, write a proper module to do so. If you are modifying core code (or, in my opinion, if you are creating this directory: app/code/local/Mage/), then you are doing something wrong.

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