Use Channel Advisor Order PHP API with Magento

Hello,

In my previous blog I mentioned about Channel Advisor API. You can read that blog here. In this blog we will see how to use Channel Advisor Order service to get order details from Channel Advisor. This service is useful when you want to import orders from Channel Advisor to your own CMS or ERP. In my case I was working with Magento – Channel Advisor synchronization. So the requirement was to get order from Channel Advisor and add order to Magento.

Following is the code to create soap client for order service.

$client = new SoapClient(“https://api.channeladvisor.com/ChannelAdvisorAPI/v4/OrderService.asmx?WSDL”);

$headersData = array(‘DeveloperKey’ => $developerKey, ‘Password’ => $password);

$head = new SoapHeader(“http://api.channeladvisor.com/webservices/”,”APICredentials”,$headersData);

$client->__setSoapHeaders($head);

To get necessary order details, we need to set order criteria. Following is the example of order criteria.
$OrderCriteria = array(
               ‘OrderCreationFilterBeginTimeGMT’=> $date1,
               ‘OrderCreationFilterEndTimeGMT’=> $date2,
               ‘StatusUpdateFilterBeginTimeGMT’ => $date1,
               ‘StatusUpdateFilterEndTimeGMT’ => $date2,
               ‘DetailLevel’ => ‘Complete’,
               ‘ExportState’ => ‘NotExported’,
               ‘OrderStateFilter’ => ‘Active’,
               ‘PaymentStatusFilter’ => ‘Cleared’,
               ‘CheckoutStatusFilter’  => ‘Completed’,
               ‘ShippingStatusFilter’  =>’Shipped’,
               ‘PageNumberFilter’=>1,
               ‘PageSize’=>30
          );
Here date1 and date2 variable specify date range for orders. After this call function of API to get order data.
$arrData = array(
               ‘accountID’=>$accountID,
               ‘orderCriteria’=>$OrderCriteria
    );
$result=$client->GetOrderList($arrData); 
You will get API response in $result. If there is only one order matching criteria then it will return order object else it will return order object array if more than one order is matching criteria.
This entry was posted in Channel Advisor PHP API, Magento, PHP on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

Leave a Reply

Your email address will not be published. Required fields are marked *