cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 API Performance - Retrieving All Sales Order Info

SOLVED

Magento 1.9 API Performance - Retrieving All Sales Order Info

I'm creating a page that shows order sales data such as sales revenue, total quantity of orders and also best sellers which consist of products from all sales orders.

The problem is that this takes 20 minutes to run for a database with only 1200 orders. I'm certain this is because an API call needs to be made for each order separately to retrieve the item information:

 

$orderDetails[] = array($client->salesOrderInfo($sessionId, $orderNumbers[$d]));

 

Here's an example of my code:

 

    // API Connection.
    $client = new SoapClient('htps://www.mysite.com/api/v2_soap/?wsdl');
    $sessionId = $client->login('API Username', 'API Password');

    // Filter orders for this year only.
    $filter = array('complex_filter' => array(
           array('key' => 'created_at', 'value' => array('key' => 'gt', 'value' => $currentYear . '2017-01-01 00:00:00'))
       )
    );

    // Call the API and retrieve the orders.
    $orders = $client->salesOrderList($sessionId, $filter);

    // Loop through orders and store order numbers against the $orderNumbers array.
    $orderNumbers = array();
    for ($i = 0; $i < count($orders); $i++) {
        $orderNumbers[] = $orders[$i]->increment_id;
    }

   // Loop through order numbers and store the order details against the $orderDetails array (this seems to be the problem area).
   $orderDetails = array();
   for ($d = 0; $d < count($orderNumbers); $d++) {
      $orderDetails[] = array($client->salesOrderInfo($sessionId, $orderNumbers[$d]));
   }

Is there a way of improving my script so that it performs much better? I cannot find a way of retrieving sales order info for more than one order at a time.

Thanks so much for any help.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 1.9 API Performance - Retrieving All Sales Order Info

Magento's API is notoriously slow. You could try enabled WSDL cache if you haven't already done. You could try the Magento Rest API but I don't that'll be much faster. 

 

The most common solution here is to write your own script/extension which provides your own protected endpoint that is tailored to the information that you want. 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

View solution in original post

2 REPLIES 2

Re: Magento 1.9 API Performance - Retrieving All Sales Order Info

Magento's API is notoriously slow. You could try enabled WSDL cache if you haven't already done. You could try the Magento Rest API but I don't that'll be much faster. 

 

The most common solution here is to write your own script/extension which provides your own protected endpoint that is tailored to the information that you want. 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Magento 1.9 API Performance - Retrieving All Sales Order Info

Hi Tom,

 

Your reply is much appreciated, thank you.