从MWS订单2011-01-01移至2013-09-01 API未读取数据

时间:2017-04-05 19:53:29

标签: php amazon-mws

从MWS订单2011-01-01迁移到2013-09-01 API我无法使用他们提供的示例PHP代码读取订单数据。

2011版本有很多帮助,但在2013版本中没有,所以我试图使用2011年的样本来阅读回复而且我被卡住了。

ListOrdersSample.PHP有:

 invokeListOrders($service, $request);

 /**
 * Get List Orders Action Sample
 * Gets competitive pricing and related information for a product identified by
 * the MarketplaceId and ASIN.
 *
 * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface
 * @param mixed $request MarketplaceWebServiceOrders_Model_ListOrders or array of parameters
 */

 function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request)
 {
 try {
 $response = $service->ListOrders($request);

 echo ("Service Response\n");
 echo ("============================================\n");
 echo(" ListOrdersResponse\n");
 if ($response->isSetListOrdersResult()) { 
 echo(" ListOrdersResult\n");
 $listOrdersResult = $response->getListOrdersResult();
 if ($listOrdersResult->isSetNextToken()) 
 {
 echo(" NextToken\n");
 echo(" " . $listOrdersResult->getNextToken() . "\n");
 }
 if ($listOrdersResult->isSetCreatedBefore()) 
 {
 echo(" CreatedBefore\n");
 echo(" " . $listOrdersResult->getCreatedBefore() . "\n");
 }
 if ($listOrdersResult->isSetLastUpdatedBefore()) 
 {
 echo(" LastUpdatedBefore\n");
 echo(" " . $listOrdersResult->getLastUpdatedBefore() . "\n");
 }
 if ($listOrdersResult->isSetOrders()) { 
 echo(" Orders\n");
 $orders = $listOrdersResult->getOrders();
 //print_r($orders); //debug
 //exit(); //debug
 $orderList = $orders->getOrder(); //line 148

$ orders在(2011版)中看起来像这样:

  

服务响应============================================= ========   ListOrdersResponse ListOrdersResult Created在2017-04-05T18:53:56Z之前   订单MarketplaceWebServiceOrders_Model_OrderList对象(   _fields:protected =>数组(Order =>数组(FieldValue =>数组([0] => MarketplaceWebServiceOrders_Model_Order对象(   _fields:protected =>数组(AmazonOrderId =>数组(FieldValue => 026-3851269-0939511 FieldType => string)SellerOrderId =>数组(   FieldValue => FieldType => string)PurchaseDate =>数组(FieldValue   => 2017-04-04T18:03:30Z F​​ieldType => string)LastUpdateDate =>数组(FieldValue => 2017-04-04T18:33:45Z FieldType =>字符串)OrderStatus   => Array(FieldValue => Unshipped FieldType => OrderStatusEnum)FulfillmentChannel =>数组(FieldValue => MFN FieldType =>   FulfillmentChannelEnum)SalesChannel =>数组(FieldValue =>   Amazon.co.uk FieldType => string)OrderChannel =>数组(FieldValue   => FieldType => string)ShipServiceLevel => Array(FieldValue => Std UK Dom_2 FieldType => string)ShippingAddress =>数组(....

$ orders在(2013版)中看起来像这样:

  

服务响应   ================================================== =========================== ListOrdersResponse ListOrdersResult Created在2017-04-05T18:35:36Z订单数组([0]   => MarketplaceWebServiceOrders_Model_Order对象(_fields:protected =>数组(AmazonOrderId =>数组(FieldValue => 026-3851269-0939511 FieldType =>字符串)SellerOrderId =>数组(FieldValue => FieldType   => string)PurchaseDate =>数组(FieldValue => 2017-04-04T18:03:30Z F​​ieldType => string)LastUpdateDate =>数组(FieldValue =>   2017-04-04T18:33:45Z FieldType => string)OrderStatus =>阵列(   FieldValue =>未发货的FieldType => string)FulfillmentChannel =>   数组(FieldValue => MFN FieldType =>字符串)SalesChannel =>排列   (FieldValue => Amazon.co.uk FieldType => string)OrderChannel =>   Array(FieldValue => FieldType => string)ShipServiceLevel =>排列   (FieldValue => Std UK Dom_2 FieldType => string)ShippingAddress =>   阵列

使用2013版本,我收到错误:

  

PHP致命错误:在非对象上调用成员函数getOrder()   在/home/*****/public_html/****/ListOrdersSample.php第148行

这是上面粘贴的最后一行代码:

 $orderList = $orders->getOrder();

2013 $ orders看起来像一个带有对象的数组,但我不知道如何阅读它,因为我的编码对于数组和对象来说不是太强。

一旦我有$ orderList,我应该能够继续使用示例代码并执行以下操作:

 foreach ($orderList as $order) {
                            echo("                    Order\n");
                            if ($order->isSetAmazonOrderId()) 
                            {
                                echo("                        AmazonOrderId\n");
                                echo("                            " . $order->getAmazonOrderId() . "\n");
                            }

但不幸的是,由于致命的错误,我一直陷入第148行。

1 个答案:

答案 0 :(得分:1)

非常简单的修复

$orderList = $orders->getOrder(); //line 148

更改为:

$orderList = $orders;

它开始工作了。