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 NoreenRogers12 7th September 2025

All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation. 加密货币交易

Write a comment ...
Post comment
Cancel
profile 18th August 2025

Our Escorts in Delhi  are not just beautiful—they’re skilled in the art of seduction. Enjoy a flawless adult night full of romance and erotic play.
 

Write a comment ...
Post comment
Cancel
profile NoreenRogers12 31st July 2025

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info.situs toto

Write a comment ...
Post comment
Cancel
profile 10th July 2025

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. Lago Maggiore Webcam

Write a comment ...
Post comment
Cancel
profile Tom 25th June 2025

The Slope Run controls are generally simple, often using arrow keys or A/D keys on a keyboard for browser versions, or tilt/drag controls on mobile devices.

Write a comment ...
Post comment
Cancel
profile naveed 6th June 2025

Merely  wanna  input that you have a very nice    web site , I  love  the  pattern  it  actually stands out. chat-avenue

Write a comment ...
Post comment
Cancel
profile Abrar 19th May 2025

Water slide, large water play park, rollover trampolines and a large beach with sunbathing lawn Lido Cannobio with Acqualand Cannobio Cannobio Foil

Write a comment ...
Post comment
Cancel
profile Abrar 19th May 2025

Water slide, large water play park, rollover trampolines and a large beach with sunbathing lawn Lido Cannobio with Acqualand Cannobio

Cannobio Wetter

Write a comment ...
Post comment
Cancel
profile 30th April 2025

The Chipotle Kids Menu is perfect for smaller appetites, even for adults. I got all the nutritional info from the Chipotle Menu with Prices.

Write a comment ...
Post comment
Cancel
profile Curve 19th March 2025

The quick, single-touch control Curve Rush is genius. Simple, but keeps you coming back for more challenges!

Write a comment ...
Post comment
Cancel
profile Diana 18th February 2025

The Escorts Mahipalpur Enjoy the beauty and charm of Russian escorts with our special agency in Mahipalpur. Our crew of gorgeous call girls are at your disposal for incall and outcall bookings, offering a discreet and enjoyable service.

Write a comment ...
Post comment
Cancel
profile Cody 15th February 2025

In this particular article, you will see a summary, satisfy browse this post. Chiropractor near Me

Write a comment ...
Post comment
Cancel
profile chloe 6th February 2025

i like to make ice cream and sandwiches when playing papa's games

Write a comment ...
Post comment
Cancel
profile Cody 30th January 2025

This is very appealing, however , it is very important that will mouse click on the connection: 代写

Write a comment ...
Post comment
Cancel
profile Cody 26th January 2025

For true fans of this thread I will address      is a free online! AITELEPHONE

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