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 ThemeEndpoint extends AbstractEndpoint |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param array $fields |
14
|
|
|
* @return array|GenericResource[] |
15
|
|
|
*/ |
16
|
|
|
public function findAll(array $fields = array()) |
17
|
|
|
{ |
18
|
|
|
$params = $fields ? array('fields' => implode(',', $fields)) : array(); |
19
|
|
|
$request = new GetJson('/admin/themes.json', $params); |
20
|
|
|
$response = $this->send($request); |
21
|
|
|
return $this->createCollection($response->get('themes')); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param int $themeId |
26
|
|
|
* @param array $fields |
27
|
|
|
* @return GenericResource |
28
|
|
|
*/ |
29
|
|
|
public function findOne($themeId, array $fields = array()) |
30
|
|
|
{ |
31
|
|
|
$params = $fields ? array('fields' => implode(',', $fields)) : array(); |
32
|
|
|
$request = new GetJson('/admin/themes/' . $themeId . '.json', $params); |
33
|
|
|
$response = $this->send($request); |
34
|
|
|
return $this->createEntity($response->get('theme')); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param GenericResource $theme |
39
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
40
|
|
|
*/ |
41
|
|
|
public function create(GenericResource $theme) |
42
|
|
|
{ |
43
|
|
|
$request = new PostJson('/admin/themes.json', array('theme' => $theme->toArray())); |
44
|
|
|
$response = $this->send($request); |
45
|
|
|
return $this->create($response->get('theme')); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param int $themeId |
50
|
|
|
* @param GenericResource $theme |
51
|
|
|
* @return GenericResource |
52
|
|
|
*/ |
53
|
|
|
public function update($themeId, $theme) |
54
|
|
|
{ |
55
|
|
|
$request = new PutJson('/admin/themes/' . $themeId . '.json', array('theme' => $theme->toArray())); |
56
|
|
|
$response = $this->send($request); |
57
|
|
|
return $this->create($response->get('theme')); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param int $themeId |
62
|
|
|
*/ |
63
|
|
|
public function delete($themeId) |
64
|
|
|
{ |
65
|
|
|
$request = new DeleteParams('/admin/themes/' . $themeId . '.json'); |
66
|
|
|
$this->send($request); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|