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\PutJson; |
7
|
|
|
|
8
|
|
|
class AssetEndpoint extends AbstractEndpoint |
9
|
|
|
{ |
10
|
|
|
public function findByTheme($themeId, array $fields = array()) |
11
|
|
|
{ |
12
|
|
|
$params = array(); |
13
|
|
|
|
14
|
|
|
if ($fields) { |
|
|
|
|
15
|
|
|
$params['fields'] = implode(',', $fields); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$request = new GetJson('/admin/themes/' . $themeId . '/assets.json', $params); |
19
|
|
|
$response = $this->send($request); |
20
|
|
|
return $response->get('assets'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param int $themeId |
25
|
|
|
* @param string $assetPath |
26
|
|
|
* @return GenericEntity |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
public function findOne($themeId, $assetPath) |
29
|
|
|
{ |
30
|
|
|
$params = array( |
31
|
|
|
'asset[key]' => $assetPath, |
32
|
|
|
'theme_id' => $themeId |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$request = new GetJson('/admin/themes/' . $themeId . '/assets.json', $params); |
36
|
|
|
$response = $this->send($request); |
37
|
|
|
return $this->createEntity($response->get('asset')); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param int $themeId |
42
|
|
|
* @param string $assetPath |
43
|
|
|
* @param string $templateContent |
44
|
|
|
* @return GenericEntity |
45
|
|
|
*/ |
46
|
|
|
public function uploadTemplate($themeId, $assetPath, $templateContent) |
47
|
|
|
{ |
48
|
|
|
$params = array( |
49
|
|
|
'asset' => array( |
50
|
|
|
'key' => $assetPath, |
51
|
|
|
'value' => $templateContent |
52
|
|
|
) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params); |
56
|
|
|
$response = $this->send($request); |
57
|
|
|
return $this->createEntity($response->get('asset')); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param int $themeId |
62
|
|
|
* @param string $assetPath |
63
|
|
|
* @param string $binary |
64
|
|
|
* @return GenericEntity |
65
|
|
|
*/ |
66
|
|
|
public function uploadBinaryFile($themeId, $assetPath, $binary) |
67
|
|
|
{ |
68
|
|
|
$params = array( |
69
|
|
|
'asset' => array( |
70
|
|
|
'key' => $assetPath, |
71
|
|
|
'attachment' => base64_encode($binary) |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params); |
76
|
|
|
$response = $this->send($request); |
77
|
|
|
return $this->createEntity($response->get('asset')); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $themeId |
82
|
|
|
* @param string $assetPath |
83
|
|
|
* @param string $remoteFileUrl |
84
|
|
|
* @return GenericEntity |
85
|
|
|
*/ |
86
|
|
|
public function uploadRemoteFile($themeId, $assetPath, $remoteFileUrl) |
87
|
|
|
{ |
88
|
|
|
$params = array( |
89
|
|
|
'asset' => array( |
90
|
|
|
'key' => $assetPath, |
91
|
|
|
'src' => $remoteFileUrl |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params); |
96
|
|
|
$response = $this->send($request); |
97
|
|
|
return $this->createEntity($response->get('asset')); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param int $themeId |
102
|
|
|
* @param string $assetPath |
103
|
|
|
* @param string $copySourcePath |
104
|
|
|
* @return GenericEntity |
105
|
|
|
*/ |
106
|
|
|
public function copy($themeId, $assetPath, $copySourcePath) |
107
|
|
|
{ |
108
|
|
|
$params = array( |
109
|
|
|
'asset' => array( |
110
|
|
|
'key' => $assetPath, |
111
|
|
|
'source_key' => $copySourcePath |
112
|
|
|
) |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$request = new PutJson('/admin/themes/' . $themeId . '/assets.json', $params); |
116
|
|
|
$response = $this->send($request); |
117
|
|
|
return $this->createEntity($response->get('asset')); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int $themeId |
122
|
|
|
* @param string $assetPath |
123
|
|
|
*/ |
124
|
|
|
public function delete($themeId, $assetPath) |
125
|
|
|
{ |
126
|
|
|
$params = array( |
127
|
|
|
'asset[key]' => $assetPath, |
128
|
|
|
'theme_id' => $themeId |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$request = new DeleteParams('/admin/themes/' . $themeId . '/assets.json', $params); |
132
|
|
|
$this->send($request); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.