cancel
Showing results for 
Search instead for 
Did you mean: 

Get order data on checkout_submit_all_after event

Get order data on checkout_submit_all_after event

Hi, 

I am new to magento. I am trying to create a observer to the event 

checkout_submit_all_after. I would like to post the order content to an external url.
My version of magento is 2.3.5-p1.
My observer is being executed, and is calling my external endpoint, but the order data is always empty.
 
class AfterOrderPlaced implements ObserverInterface {
    public function execute(\Magento\Framework\Event\Observer $observer) {
        {
            error_log(print_r("alterado pra chamar endpoint com guzzle \n", TRUE), 3, '/var/www/html/var/log/cotriba_errors.log');

	    $order = $observer->getEvent()->getData();
	    $order_content = json_encode($observer -> getEvent()-> getData());

            $client = new \GuzzleHttp\Client();
            $response = $client->request('POST', 'http://192.168.0.23:8080/hello', array(
                'headers' => [],
                'json' => $order_content
            ));



            return $this;
        }

    }
}
How can I get all the order data?
3 REPLIES 3

Re: Get order data on checkout_submit_all_after event

Hi @kellygoede46b1 ,

 

Can you try replacing line of code with options

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

To 

$order = $observer->getEvent()->getData('order');

Else

$order = $observer->getOrder();

 

Thanks!

Problem Solved! Click kudos & Accept as Solution.

Re: Get order data on checkout_submit_all_after event

I tried what you suggested but the answer I get is still "{}"

Re: Get order data on checkout_submit_all_after event

Hi @kellygoede46b1 ,

 

In this case, can you try changing the event and try below mention the event to get the order data.

 

https://meetanshi.com/blog/get-order-data-from-magento-2-sales_order_place_after-event/

 

Thanks!

--------------------------------

Problem Solved! Click Kudos and Accept as Solution!