Rate this post

Here are the steps that you will follow in this How to use Magento 2 event (Magento 2.3)?:

  1. Create a file events.xml in app/code/[Namspace]/[Module_Name]/etc
  2. Create observer file SaveAfter.php in app/code/[Namspace]/[Module_Name]\Observer\Sales\Order

Today, I want to share with you: how to use Magento 2 event with a small, simple example. 

The situation here is I want to do something after save order of Magento. So we solve it with these steps :

Step 1: How to use Magento 2 event is:

  • I will create a file events.xml in app/code/[Namspace]/[Module_Name]/etc

  • In here, I use event “sales_order_save_after”
  • Observe file is SaveAfter.php in app/code/[Namspace]/[Module_Name]\Observer\Sales\Order

Step 2:

  • Create observer file SaveAfter.php in app/code/[Namspace]/[Module_Name]\Observer\Sales\Order

  • Please write your code in function execute() that you want to do after save order.

You may want to try the Magento 2 Demo to fully experience its new awesome features. And of course, please feel free to find more Magento 2 Tutorials by our Experts.

Your Magento website needs a powerful Magento ERP for stock control.

DON'T MISS THE CHANCE!

magento erp

How to implement API in Magento 2 - Magento 2.3
How to create an event in Magento 2? - Magento 2 events (Magento 2.3)

Leave a Reply

Your email address will not be published. Required fields are marked *