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\Request\PutJson; |
8
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource; |
9
|
|
|
|
10
|
|
|
class MetafieldEndpoint extends AbstractEndpoint |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param int $customerId |
14
|
|
|
* @param array $query |
15
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
16
|
|
|
*/ |
17
|
|
|
public function findCustomerMetafields($customerId, array $query = array()) |
18
|
|
|
{ |
19
|
|
|
$request = new GetJson('/admin/customers/' . $customerId . '/metafields.json', $query); |
20
|
|
|
$response = $this->sendPaged($request, 'metafields'); |
21
|
|
|
return $this->createCollection($response); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array $query |
26
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
27
|
|
|
*/ |
28
|
|
|
public function findStoreMetafields(array $query = array()) |
29
|
|
|
{ |
30
|
|
|
$request = new GetJson('/admin/metafields.json', $query); |
31
|
|
|
$response = $this->sendPaged($request, 'metafields'); |
32
|
|
|
return $this->createCollection($response); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param int $productId |
37
|
|
|
* @param array $query |
38
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
39
|
|
|
*/ |
40
|
|
|
public function findProductMetafields($productId, array $query = array()) |
41
|
|
|
{ |
42
|
|
|
$request = new GetJson('/admin/products/' . $productId . '/metafields.json', $query); |
43
|
|
|
$response = $this->sendPaged($request, 'metafields'); |
44
|
|
|
return $this->createCollection($response); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param int $variantId |
49
|
|
|
* @param array $query |
50
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
51
|
|
|
*/ |
52
|
|
|
public function findVariantMetafields($variantId, array $query = array()) |
53
|
|
|
{ |
54
|
|
|
$request = new GetJson('/admin/variants/' . $variantId . '/metafields.json', $query); |
55
|
|
|
$response = $this->sendPaged($request, 'metafields'); |
56
|
|
|
return $this->createCollection($response); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param int $productImageId |
61
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
62
|
|
|
*/ |
63
|
|
|
public function findProductImageMetafields($productImageId) |
64
|
|
|
{ |
65
|
|
|
$params = array( |
66
|
|
|
'metafield[owner_id]' => $productImageId, |
67
|
|
|
'metafield[owner_resource]' => 'product_image' |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$request = new GetJson('/admin/metafields.json', $params); |
71
|
|
|
$response = $this->sendPaged($request, 'metafields'); |
72
|
|
|
return $this->createCollection($response); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param int $metafieldId |
77
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
78
|
|
|
*/ |
79
|
|
|
public function findOneCustomerMetafield($metafieldId, $customerId) |
80
|
|
|
{ |
81
|
|
|
$request = new GetJson('/admin/customers/' . $customerId . '/metafields/' . $metafieldId . '.json'); |
82
|
|
|
$response = $this->send($request); |
83
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int $metafieldId |
88
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
89
|
|
|
*/ |
90
|
|
|
public function findOneStoreMetafield($metafieldId) |
91
|
|
|
{ |
92
|
|
|
$request = new GetJson('/admin/metafields/' . $metafieldId . '.json'); |
93
|
|
|
$response = $this->send($request); |
94
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param int $metafieldId |
99
|
|
|
* @param int $productId |
100
|
|
|
* @return GenericResource |
101
|
|
|
*/ |
102
|
|
|
public function findOneProductMetafield($metafieldId, $productId) |
103
|
|
|
{ |
104
|
|
|
$request = new GetJson('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json'); |
105
|
|
|
$response = $this->send($request); |
106
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param int $customerId |
111
|
|
|
* @return int |
112
|
|
|
*/ |
113
|
|
|
public function countByCustomer($customerId) |
114
|
|
|
{ |
115
|
|
|
$request = new GetJson('/admin/customers/' . $customerId . '/metafields/count.json'); |
116
|
|
|
$response = $this->send($request); |
117
|
|
|
return $response->get('count'); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return int |
122
|
|
|
*/ |
123
|
|
|
public function countStoreMetafields() |
124
|
|
|
{ |
125
|
|
|
$request = new GetJson('/admin/metafields/count.json'); |
126
|
|
|
$response = $this->send($request); |
127
|
|
|
return $response->get('count'); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param int $productId |
132
|
|
|
* @return int |
133
|
|
|
*/ |
134
|
|
|
public function countByProduct($productId) |
135
|
|
|
{ |
136
|
|
|
$request = new GetJson('/admin/products/' . $productId . '/metafields/count.json'); |
137
|
|
|
$response = $this->send($request); |
138
|
|
|
return $response->get('count'); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int $customerId |
143
|
|
|
* @param GenericResource $metafield |
144
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
145
|
|
|
*/ |
146
|
|
|
public function createCustomerMetafield($customerId, GenericResource $metafield) |
147
|
|
|
{ |
148
|
|
|
$request = new PostJson('/admin/customers/' . $customerId . '/metafields.json', array('metafield' => $metafield->toArray())); |
149
|
|
|
$response = $this->send($request); |
150
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param GenericResource $metafield |
155
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
156
|
|
|
*/ |
157
|
|
|
public function createStoreMetafield(GenericResource $metafield) |
158
|
|
|
{ |
159
|
|
|
$request = new PostJson('/admin/metafields.json', array('metafield' => $metafield->toArray())); |
160
|
|
|
$response = $this->send($request); |
161
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param int $productId |
166
|
|
|
* @param GenericResource $metafield |
167
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
168
|
|
|
*/ |
169
|
|
|
public function createProductMetafield($productId, GenericResource $metafield) |
170
|
|
|
{ |
171
|
|
|
$request = new PostJson('/admin/products/' . $productId . '/metafields.json', array('metafield' => $metafield->toArray())); |
172
|
|
|
$response = $this->send($request); |
173
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param int $metafieldId |
178
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield |
179
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
180
|
|
|
*/ |
181
|
|
|
public function updateStoreMetafield($metafieldId, GenericResource $metafield) |
182
|
|
|
{ |
183
|
|
|
$request = new PutJson('/admin/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray())); |
184
|
|
|
$response = $this->send($request); |
185
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $metafieldId |
190
|
|
|
* @param int $customerId |
191
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield |
192
|
|
|
* @return GenericResource |
193
|
|
|
*/ |
194
|
|
|
public function updateCustomerMetafield($metafieldId, $customerId, GenericResource $metafield) |
195
|
|
|
{ |
196
|
|
|
$request = new PutJson('/admin/products/' . $customerId . '/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray())); |
197
|
|
|
$response = $this->send($request); |
198
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param int $metafieldId |
203
|
|
|
* @param int $productId |
204
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield |
205
|
|
|
* @return GenericResource |
206
|
|
|
*/ |
207
|
|
|
public function updateProductMetafield($metafieldId, $productId, GenericResource $metafield) |
208
|
|
|
{ |
209
|
|
|
$request = new PutJson('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray())); |
210
|
|
|
$response = $this->send($request); |
211
|
|
|
return $this->createEntity($response->get('metafield')); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param int $metafieldId |
216
|
|
|
* @param int $customerId |
217
|
|
|
*/ |
218
|
|
|
public function deleteCustomerMetafield($metafieldId, $customerId) |
219
|
|
|
{ |
220
|
|
|
$request = new DeleteParams('/admin/customers/' . $customerId . '/metafields/' . $metafieldId . '.json'); |
221
|
|
|
$this->send($request); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param int $metafieldId |
226
|
|
|
*/ |
227
|
|
|
public function deleteStoreMetafield($metafieldId) |
228
|
|
|
{ |
229
|
|
|
$request = new DeleteParams('/admin/metafields/' . $metafieldId . '.json'); |
230
|
|
|
$this->send($request); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param int $metafieldId |
235
|
|
|
* @param int $productId |
236
|
|
|
*/ |
237
|
|
|
public function deleteProductMetafield($metafieldId, $productId) |
238
|
|
|
{ |
239
|
|
|
$request = new DeleteParams('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json'); |
240
|
|
|
$this->send($request); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|