1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Looxis\LaravelAmazonMWS; |
4
|
|
|
|
5
|
|
|
class MWSOrders |
6
|
|
|
{ |
7
|
|
|
const VERSION = '2013-09-01'; |
8
|
|
|
|
9
|
|
|
protected $client; |
10
|
|
|
|
11
|
|
|
public function __construct(MWSClient $client) |
12
|
|
|
{ |
13
|
|
|
$this->client = $client; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function list($params = []) |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
//TODO |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function get($ids) |
22
|
|
|
{ |
23
|
|
|
$ids = is_array($ids) ? $ids : func_get_args(); |
24
|
|
|
$params = []; |
25
|
|
|
|
26
|
|
|
foreach ($ids as $key => $id) { |
27
|
|
|
$keyName = 'AmazonOrderId.Id.'.($key + 1); |
28
|
|
|
$params[$keyName] = $id; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$response = $this->client->post('GetOrder', '/Orders/'.self::VERSION, self::VERSION, $params); |
32
|
|
|
|
33
|
|
|
return $this->parseResponse($response, 'GetOrderResult', 'Orders.Order'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getItems($id) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$response = $this->client->post('ListOrderItems', '/Orders/' . self::VERSION, self::VERSION); |
39
|
|
|
|
40
|
|
|
return $this->parseResponse($response, 'ListOrderItemsResult', 'OrderItems.OrderItem'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function parseResponse($response, $resultTypeName, $dataName) |
44
|
|
|
{ |
45
|
|
|
$requestId = data_get($response, 'ResponseMetadata.RequestId'); |
46
|
|
|
$orders = data_get($response, $resultTypeName. '.' . $dataName); |
47
|
|
|
$nextToken = data_get($response, $resultTypeName. '.NextToken'); |
48
|
|
|
|
49
|
|
|
$data = [ |
50
|
|
|
'request_id' => $requestId, |
51
|
|
|
'data' => $orders, |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
if ($nextToken) { |
55
|
|
|
$data['next_token'] = $nextToken; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($resultTypeName == 'ListOrderItemsResult') { |
59
|
|
|
$data['order_id'] = data_get($response, $resultTypeName . '.AmazonOrderId'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $data; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.