How to use Rest And Soap API in Magento After sales order to send information to courier partner
-
13-12-2019 - |
Question
I need to send. some information after sales ..to the courier company... I need to build API in magento..when customer purchase anything...and place successful order. Then I want to send some information to our partner courier company. Like product name, customer address, customer name And some information... Basically, I want to use rest and soap..for this. But I don't know which is good for that.
Solution
You can use magento event like "checkout_onepage_controller_success_action" which will be called after successfull order.where you can write a method to call courier api using soap.You can get all the information from event object.
Sample
1)Place in config.xml
<events>
<checkout_onepage_controller_success_action>
<observers>
<my_custom_module>
<type>singleton</type>
<class>my_custom_module_observer</class>
<method>sendtocourier</method>
</my_custom_module>
</observers>
</checkout_onepage_controller_success_action>
</events>
2) In class my_custom_module_observer, write method
function sendtocourier($observer){
$orderIds = $observer->getData('order_ids');
$orderId = current($orderIds);
$order = Mage::getModel('sales/order')->load($orderId);
//get all info from order
//call courier with soap
$client = new SoapClient('courire wsdl url', array('trace' => 1, 'cache_wsdl' => WSDL_CACHE_NONE));
}
Hope that helps