简体   繁体   English

Magento-订单数据何时保存到数据库中

[英]Magento - when are order data being saved into DB

I need to store additional data to PHP $_SESSION , but I need to do that while Magento order is being saved to database. 我需要将其他数据存储到PHP $_SESSION ,但是在将Magento订单保存到数据库时需要这样做。 I am saving additional payment method information which is not required to be stored in DB and is not explicitly connected to order. 我正在保存其他付款方式信息,这些信息不需要存储在数据库中, 也未明确关联到订单。 Could you please give me a little bit of background for that process? 您能给我一些背景知识吗?

  • When is it being saved? When时候保存?
  • In what class is it done? what class上做?

Have you tried to use Magento events? 您是否尝试过使用Magento事件? It is even recommended to use events instead of (what I guess you want to) editing core Magento files. 甚至建议您使用事件而不是(我想您想要)编辑核心Magento文件。 In this case you could use two events, depending on your needs. 在这种情况下,您可以根据需要使用两个事件。

sales_order_save_after

or 要么

sales_order_save_before

They basically are what they say, with first one you will be able to modify order before saving it to database and second one will let you modify the order which will be already saved. 它们基本上就是他们所说的,第一个可以在将订单保存到数据库之前修改订单,第二个可以让您修改已经保存的订单。 About Magento observers (if you are not familiar with them), answer here: https://magento.stackexchange.com/questions/41277/how-to-create-an-new-observer-on-the-event-catalog-product-save-before should be enough for you. 关于Magento观察员(如果您不熟悉的话),请在此处回答: https : //magento.stackexchange.com/questions/41277/how-to-create-an-new-observer-on-the-event-catalog-之前的产品节省对于您来说应该足够了。 Of course, remember to observer the event that you want to. 当然,请记住要观察您想要的事件。 Then inside your observer method you will just have to use something like this: 然后,在您的观察者方法内部,您将只需要使用以下内容:

$order = $observer->getEvent()->getOrder();

and do what you want to with this order (with event _after remember to ->save() order when you will change it. 并按照此顺序执行您想要的操作(事件_after记住更改后的-> save()顺序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM