1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ShopifyClient\Resource; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* https://help.shopify.com/api/reference/customer |
7
|
|
|
*/ |
8
|
|
|
class Customer extends AbstractResource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var bool |
12
|
|
|
*/ |
13
|
|
|
protected $countable = true; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var CustomerAddress |
17
|
|
|
*/ |
18
|
|
|
public $addresses; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param float $id |
22
|
|
|
* @param array $fields |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
2 |
|
public function get(float $id, array $fields = []) |
26
|
|
|
{ |
27
|
2 |
|
$response = $this->request('GET', sprintf('/admin/customers/%s.json', $id), [ |
28
|
|
|
'query' => [ |
29
|
2 |
|
'fields' => $fields |
30
|
|
|
] |
31
|
|
|
]); |
32
|
|
|
|
33
|
1 |
|
return $response['customer']; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param array $query |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
1 |
|
public function all(array $query = []) |
41
|
|
|
{ |
42
|
1 |
|
$response = $this->request('GET', '/admin/customers.json', [ |
43
|
1 |
|
'query' => $query |
44
|
|
|
]); |
45
|
|
|
|
46
|
1 |
|
return $response['customers']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array $query |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
1 |
|
public function search(array $query = []) |
54
|
|
|
{ |
55
|
1 |
|
$response = $this->request('GET', '/admin/customers/search.json', [ |
56
|
1 |
|
'query' => $query |
57
|
|
|
]); |
58
|
|
|
|
59
|
1 |
|
return $response['customers']; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param array $query |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
1 |
|
public function count(array $query = []) |
67
|
|
|
{ |
68
|
1 |
|
$response = $this->request('GET', '/admin/customers/count.json', [ |
69
|
1 |
|
'query' => $query |
70
|
|
|
]); |
71
|
|
|
|
72
|
1 |
|
return $response['count']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param array $params |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
2 |
|
public function create(array $params = []) |
80
|
|
|
{ |
81
|
2 |
|
$response = $this->request('POST', '/admin/customers.json', [ |
82
|
2 |
|
'body' => json_encode(['customer' => $params]) |
83
|
|
|
]); |
84
|
|
|
|
85
|
1 |
|
return $response['customer']; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param float $id |
90
|
|
|
* @param array $params |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
1 |
|
public function update(float $id, array $params = []) |
94
|
|
|
{ |
95
|
1 |
|
$response = $this->request('PUT', sprintf('/admin/customers/%s.json', $id), [ |
96
|
1 |
|
'body' => json_encode(['customer' => $params]) |
97
|
|
|
]); |
98
|
|
|
|
99
|
1 |
|
return $response['customer']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param float $id |
104
|
|
|
*/ |
105
|
1 |
|
public function delete(float $id) |
106
|
|
|
{ |
107
|
1 |
|
$this->request('DELETE', sprintf('/admin/customers/%s.json', $id)); |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param float $id |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
1 |
|
public function orders(float $id) |
115
|
|
|
{ |
116
|
1 |
|
$response = $this->request('GET', sprintf('/admin/customers/%s/orders.json', $id)); |
117
|
|
|
|
118
|
1 |
|
return $response['orders']; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|