Magento 2 – Resolving Checkout Event Issues

checkoutevent-observermagento2productproduct-list

I try to take the final product list after the checkout, so I create an observer for that.
I found a list of all dispatched events in Magento 2.1 which looks like this:

dispatched-events

I tried a lot of events, which is work properly, but nothing seems to work for the final checkout button.

I also tried checkout_cart_save_after but this event is before the final checkout button, and checkout_type_onepage_save_order_afterbut this event is not working.

Does anyone know how to solve this problem? Or which event is responsible for this?

Best Answer

I think you have to use the event sales_order_place_after. This event will work on final checkout (Place Order) button.

Get order data :

$order = $observer->getEvent()->getOrder();
$order_id = $order->getIncrementId();
foreach($order->getAllItems() as $item){
      $ProdustIds[]= $item->getProductId();
      $proName[] = $item->getName(); // product name
 }
$shippingAddress = $order->getShippingAddress(); // shipping address
$customer = $order->getCustomerId(); // using this id you can get customer name
Related Topic