|
1
|
|
|
<?php |
|
2
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint; |
|
3
|
|
|
|
|
4
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams; |
|
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson; |
|
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson; |
|
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource; |
|
8
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson; |
|
9
|
|
|
|
|
10
|
|
|
class CustomerEndpoint extends AbstractEndpoint |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param array $query |
|
14
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
|
15
|
|
|
*/ |
|
16
|
|
|
public function findAll(array $query = array()) |
|
17
|
|
|
{ |
|
18
|
|
|
$request = new GetJson('/admin/customers.json', $query); |
|
19
|
|
|
$response = $this->sendPaged($request, 'customers'); |
|
20
|
|
|
return $this->createCollection($response); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param int $customerId |
|
25
|
|
|
* @param array $fields |
|
26
|
|
|
* @return array|GenericResource[] |
|
27
|
|
|
*/ |
|
28
|
|
|
public function findOrdersForCustomer($customerId, array $fields = array()) |
|
29
|
|
|
{ |
|
30
|
|
|
$params = $fields ? array('fields' => implode(',', $fields)) : array(); |
|
31
|
|
|
$request = new GetJson('/admin/customers/' . $customerId . '.json', $params); |
|
32
|
|
|
$response = $this->sendPaged($request, 'customers'); |
|
33
|
|
|
return $this->createCollection($response); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $query |
|
38
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
|
39
|
|
|
*/ |
|
40
|
|
|
public function search(array $query = array()) |
|
41
|
|
|
{ |
|
42
|
|
|
$request = new GetJson('/admin/customers/search.json', $query); |
|
43
|
|
|
$response = $this->sendPaged($request, 'customers'); |
|
44
|
|
|
return $this->createCollection($response); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return int |
|
49
|
|
|
*/ |
|
50
|
|
|
public function countAll() |
|
51
|
|
|
{ |
|
52
|
|
|
$request = new GetJson('/admin/customers/count.json'); |
|
53
|
|
|
$response = $this->send($request); |
|
54
|
|
|
return $response->get('count'); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $customerId |
|
59
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
|
60
|
|
|
*/ |
|
61
|
|
|
public function findOne($customerId) |
|
62
|
|
|
{ |
|
63
|
|
|
$request = new GetJson('/admin/customers/' . $customerId . '.json'); |
|
64
|
|
|
$response = $this->send($request); |
|
65
|
|
|
return $this->createEntity($response->get('customer')); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $customer |
|
70
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
|
71
|
|
|
*/ |
|
72
|
|
|
public function create(GenericResource $customer) |
|
73
|
|
|
{ |
|
74
|
|
|
$request = new PostJson('/admin/customers.json', array('customer' => $customer->toArray())); |
|
75
|
|
|
$response = $this->send($request); |
|
76
|
|
|
return $this->createEntity($response->get('customer')); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $customerId |
|
81
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $customer |
|
82
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
|
83
|
|
|
*/ |
|
84
|
|
|
public function update($customerId, GenericResource $customer) |
|
85
|
|
|
{ |
|
86
|
|
|
$request = new PutJson('/admin/customers/' . $customerId . '.json', array('customer' => $customer->toArray())); |
|
87
|
|
|
$response = $this->send($request); |
|
88
|
|
|
return $this->createEntity($response->get('customer')); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param int $customerId |
|
93
|
|
|
*/ |
|
94
|
|
|
public function delete($customerId) |
|
95
|
|
|
{ |
|
96
|
|
|
$request = new DeleteParams('/admin/customers/' . $customerId . '.json'); |
|
97
|
|
|
$this->send($request); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|