Magento – Send a Magento order to third-party API when placed

apihttpsjavascriptxml

I'm looking on an example of where I should place for Magento orders to be sent to a third-party API. I have all documentation and all proper code that I've tested. I just don't know where these API calls fit in.

How and where will it get triggered? Should it be a custom module? Event observer?

Best Answer

My first tought would go to creating my own extension with an observer for the checkout_submit_all_after event.

This event covers both front- and backend orders.

You can get your order object(s) like this in your observer:

    if ($observer->getEvent()->hasOrders()) {

               $orders = $observer->getEvent()->getOrders();

           } else {

               $orders[] = $observer->getEvent()->getOrder();

           }

           foreach ($orders as $order) {
           //call here
           }
}

I have also done a couple of ERP implementations where the client wanted a daily cron to sync the orders, the choise is up to you. In this case you will also create a custom extension that handles this.

Related Topic