简体   繁体   中英

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. 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?
  • In what class is it done?

Have you tried to use Magento events? It is even recommended to use events instead of (what I guess you want to) editing core Magento files. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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