Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Send data after checkout
 
fcollins
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2011-08-27
 

I’ve an e-commerce website powered by Magento but now I need to make the connection bewteen Magento and the company’s management software.

The process should be this:

1. The user put some stuff in his cart
2. The user go through the checkout process
3. After the user have paid the total with Paypal, Magento should send an HTTP request (perhaps POST, with order’s data) to an external server that handles the request and do stuff with the data received.

My problem is that I’ve no idea how to send a request from Magento with the order data after the checkout process. I think this is a common scenario for companies that uses e-commerce. Do you have some ideas for this? Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
BelVG
Guru
 
Avatar
Total Posts:  306
Joined:  2011-02-16
Minsk, Belarus
 

Hi,

For such purposes it is usually used success page that appears after successful checkout
The standard page location is app/design/frontend/default(base)/default/template/checkout/success.phtml.

It’s the easiest way to collect information about existing orders from this file and pass it to remote server by curl (for ex.)

The information about the orders for Google Analytics is collected and sent from this file too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fcollins
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2011-08-27
 

Thank you for the reply.
I’ve seen that file but how can I send a CURL request with the order data from that file?

Can you give me a simple example? Also CURL is a good way for doing this? Even if two users make two order at the same time?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
BelVG
Guru
 
Avatar
Total Posts:  306
Joined:  2011-02-16
Minsk, Belarus
 

Simple code (as example очень простой код (only as an example of implementation and not a guide as it should be):

In the template in the begin of success.phtml we add a code:

<?php $this->sendOrder(); ?>

in Mage_Checkout_Block_Onepage_Success we add the method itself:

public function sendOrder()
    
{


    $remote_serv_url 
\'http://www.myremoteserver.com/order_registration_controller/?orderinfo=\';   //url of remote server with controller
    
$param json_encode(Mage::getModel(\'sales/order\')->getCollection()->addFieldToFilter(\'increment_id\'$this->getOrderId())->getLastItem()->getData());
    
//^^^^^^^^collecting of data for recieve
        
    
$url $remote_serv_url $param;
        
    
$ch curl_init();
        
    
curl_setopt($chCURLOPT_URL$url);
        
    
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    
$success curl_exec($ch);  //recieving of success from remote server
    

}

Yes, in case of a big quatntity (really very big quantity) of orders it may be increased the load on the server. In this case it is possible to send data about orders via Cron (the accumulation of a number of them over time and sending all at once with one request). It may slightly reduce the load on the server.

For a very large flow of orders (for very large stores) the best variant of transfering data of the orders is through the API.
The presented implementation is the most simple and in original the question was how to organize data transfer directly after placing the order

 
Magento Community Magento Community
Magento Community
Magento Community
 
antarlevonsys
Jr. Member
 
Total Posts:  2
Joined:  2012-12-16
 

I want to add three parameters: “From”, “To” and “Body” in the HTTP POST request

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top