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;
}
}?>
To download the sample code click here
We CNC inserts Indexable Milling Insert are divided into positive-angle inserts and negative-angle inserts. A positive-angle insert means that the insert has a back angle, which is a common single-sided insert. Negative angle insert Turning Milling Inserts means that the insert does not have a back angle and both sides Tungaloy Inserts of the insert can be used.
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
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
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.
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.
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.
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
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
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.
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!
I used this code in Magento Ver 1.9.0.1 and it works well.
This doesn't work in 1.9
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