Send Order data to other Server After Successful Order In Magento

To update our store orders on some other website other than our magento store we need to send the orders details after successful order at our store.To do this we need to dispatch a method after success action. So we need to create a module in our ocal folder of magento . Here our module name is Postdata with package name Letsknnowit OR we can write this code in any other module also. We need to write some code in config.xml and Observer.php

File: app/code/local/Letsknowit/Checkout/etc/config.xml

<config>
<global>
<models>
<letsknowit_checkout>
<class>Letsknowit_Checkout_Model</class>
</letsknowit_checkout>
</models>
<events>
<checkout_onepage_controller_success_action>
<observers>
<postDataTosServer>
<type>singleton</type>
<class>Letsknowit_Checkout_Model_Observer</class>
<method>postDataTosServer</method>
</postDataTosServer>
</observers>
</checkout_onepage_controller_success_action>
</events>
</global> </config>

 

After successfull order in magento the observer is dispatched . In observer.php we will get the order details and send it to the url of other server via CURL method.

File: app/code/local/Letsknowit/Checkout/Model/Observer.php

<?php 
class Letsknowit_Postdata_Model_Checkout_Observer
{
public function postDataTosServer(Varien_Event_Observer $observer){
$orderIds = $observer->getData('order_ids');
foreach($orderIds as $_orderId){
$order = Mage::getModel('sales/order')->load($_orderId);
$customer = Mage::getModel('customer/customer')->load($order->getData('customer_id'));
$customer->getDefaultBillingAddress()->getLastname();
$billingaddress = $order->getBillingAddress();

try { /* parameters can be change according to requirment */
$params =    array( 'customerName'=>$order->getData('customer_firstname'),
'companyName'=>$billingaddress->getData('company'),
'telephone'=>  $billingaddress->getData('telephone'),
'email'=> $billingaddress->getData('email'),
'street'=> $billingaddress->getData('street'),
'city'=>  $billingaddress->getData('city'),
'region'=> $billingaddress->getData('region'),
'postcode'=> $billingaddress->getData('postcode'),
'total'=>$order->getGrandTotal() );

           $url= 'exmaple.com/getorders.php'; // the url on which the data will be send through curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HEADER);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$response = curl_exec($ch);
curl_close($ch);
Mage::log('Order has been sent to exmaple.com');

} catch (Exception $e) {
Mage::logException($e);}
}
return $this;
}
}
?>

 

1   0
Aditya Singh

To download the sample code click here

profile Mike 16th March 2024

Awesome blog. I have read and thought about what you said. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
Mark Wahlberg The Union Green Jacket

Write a comment ...
Post comment
Cancel
profile muneer 28th January 2024

You have a great sense of writing I must say. Your post has those facts which are not accessible from anywhere else. It’s my humble request to u please keep writing such remarkable articles bachelorette panties

Write a comment ...
Post comment
Cancel
profile Jewel Galore 22nd January 2024

Explore Jewelgalore's collection of  earrings for girls . Discover elegantly designed pieces perfect for adding a touch of charm and grace to young girls' fashion.

Write a comment ...
Post comment
Cancel
profile OSH 22nd January 2024

Osh University's  International Medical Faculty  is a beacon for students seeking a global medical education. With a commitment to excellence, it prepares the next generation of healthcare leaders for an ever-evolving world of medicine.

Write a comment ...
Post comment
Cancel
profile Shalamar Hospital 22nd January 2024

If you're seeking the best cancer care, Shalamar Hospital stands out as a dedicated  cancer hospital , providing comprehensive oncology services and support for those in need.

Write a comment ...
Post comment
Cancel
profile muneer 4th January 2024

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks. appartement huren

Write a comment ...
Post comment
Cancel
profile muneer 28th December 2023

Excellent article plus its information and I positively bookmark to this site because here I always get an amazing knowledge as I expect. Thanks for this to share with us personalized underwear wife

Write a comment ...
Post comment
Cancel
profile Matt 5th October 2023

Initially, it did not work for me. Only later did I realize, and with the help of Estephania Ha that forgot to close the config.xml code with </config>, hence it was showing an error message.

Write a comment ...
Post comment
Cancel
profile 222 Aloha 5th July 2023

To ensure that the experience is outstanding, the photo booth rental business will make sure to deliver all the essential supplies, such as a printer and props check our packages!

Write a comment ...
Post comment
Cancel
profile Rahim Auxano 27th December 2016

what a great page .....

Write a comment ...
Post comment
Cancel
profile Rahim Auxano 27th December 2016

what a great page .....

Write a comment ...
Post comment
Cancel
profile Terry Wong 3rd July 2016
I used this code in Magento Ver 1.9.2.4 and it works well. Thank you.
Write a comment ...
Post comment
Cancel
profile Vivek 14th June 2016

I used this code in Magento Ver 1.9.0.1 and it works well.

Ranjeet
13-02-2017 00:00

@vivek : you used in enterprise or community

Write a comment ...
Post comment
Cancel
profile Manoj Silva 28th August 2015

This doesn't work in 1.9

06-02-2017 00:00

hhhhhh

Shailesh
13-03-2017 00:00

hello

Write a comment ...
Post comment
Cancel
profile Scott 13th August 2015

This doesn't work in 1.9. Quick heads up!

Write a comment ...
Post comment
Cancel

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site