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.
Solved! Go to Solution.
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.
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.
Hi Tom,
Your reply is much appreciated, thank you.