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
|
|
|
* @param float $id |
17
|
|
|
* @param array $fields |
18
|
|
|
* @return array |
19
|
|
|
*/ |
20
|
2 |
|
public function get(float $id, array $fields = []) |
21
|
|
|
{ |
22
|
2 |
|
$response = $this->request('GET', sprintf('/admin/customers/%s.json', $id), [ |
23
|
|
|
'query' => [ |
24
|
2 |
|
'fields' => $fields |
25
|
|
|
] |
26
|
|
|
]); |
27
|
|
|
|
28
|
1 |
|
return $response['customer']; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $query |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
1 |
|
public function all(array $query = []) |
36
|
|
|
{ |
37
|
1 |
|
$response = $this->request('GET', '/admin/customers.json', [ |
38
|
1 |
|
'query' => $query |
39
|
|
|
]); |
40
|
|
|
|
41
|
1 |
|
return $response['customers']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param array $query |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function search(array $query = []) |
49
|
|
|
{ |
50
|
|
|
$response = $this->request('GET', '/admin/customers/search.json', [ |
51
|
|
|
'query' => $query |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
return $response['customers']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $query |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
1 |
|
public function count(array $query = []) |
62
|
|
|
{ |
63
|
1 |
|
$response = $this->request('GET', '/admin/customers/count.json', [ |
64
|
1 |
|
'query' => $query |
65
|
|
|
]); |
66
|
|
|
|
67
|
1 |
|
return $response['count']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param array $params |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
2 |
|
public function create(array $params = []) |
75
|
|
|
{ |
76
|
2 |
|
$response = $this->request('POST', '/admin/customers.json', [ |
77
|
2 |
|
'body' => json_encode(['customer' => $params]) |
78
|
|
|
]); |
79
|
|
|
|
80
|
1 |
|
return $response['customer']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param float $id |
85
|
|
|
* @param array $params |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
1 |
|
public function update(float $id, array $params = []) |
89
|
|
|
{ |
90
|
1 |
|
$response = $this->request('PUT', sprintf('/admin/customers/%s.json', $id), [ |
91
|
1 |
|
'body' => json_encode(['customer' => $params]) |
92
|
|
|
]); |
93
|
|
|
|
94
|
1 |
|
return $response['customer']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param float $id |
99
|
|
|
*/ |
100
|
1 |
|
public function delete(float $id) |
101
|
|
|
{ |
102
|
1 |
|
$this->request('DELETE', sprintf('/admin/customers/%s.json', $id)); |
103
|
1 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param float $id |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
1 |
|
public function orders(float $id) |
110
|
|
|
{ |
111
|
1 |
|
$response = $this->request('GET', sprintf('/admin/customers/%s/orders.json', $id)); |
112
|
|
|
|
113
|
1 |
|
return $response['orders']; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|