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