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 SmartCollectionEndpoint 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/smart_collections.json', $query); |
19
|
|
|
$response = $this->sendPaged($request, 'smart_collections'); |
20
|
|
|
return $this->createCollection($response); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param array $query |
25
|
|
|
* @return int |
26
|
|
|
*/ |
27
|
|
|
public function countAll(array $query = array()) |
28
|
|
|
{ |
29
|
|
|
$request = new GetJson('/admin/smart_collections/count.json', $query); |
30
|
|
|
$response = $this->send($request); |
31
|
|
|
return $response->get('count'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $smartCollectionId |
36
|
|
|
* @param array $fields |
37
|
|
|
* @return GenericResource |
38
|
|
|
*/ |
39
|
|
|
public function findOne($smartCollectionId, array $fields = array()) |
40
|
|
|
{ |
41
|
|
|
$params = $fields ? array('params' => implode(',', $fields)) : array(); |
42
|
|
|
$request = new GetJson('/admin/smart_collections/' . $smartCollectionId . '.json', $params); |
43
|
|
|
$response = $this->send($request); |
44
|
|
|
return $this->createEntity($response->get('smart_collection')); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $smartCollection |
49
|
|
|
* @return GenericResource |
50
|
|
|
*/ |
51
|
|
|
public function create(GenericResource $smartCollection) |
52
|
|
|
{ |
53
|
|
|
$request = new PostJson('/admin/smart_collections.json', array('smart_collection' => $smartCollection->toArray())); |
54
|
|
|
$response = $this->send($request); |
55
|
|
|
return $this->createEntity($response->get('smart_collection')); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param int $smartCollectionId |
60
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $smartCollection |
61
|
|
|
* @return GenericResource |
62
|
|
|
*/ |
63
|
|
|
public function update($smartCollectionId, GenericResource $smartCollection) |
64
|
|
|
{ |
65
|
|
|
$request = new PutJson('/admin/smart_collections/' . $smartCollectionId . '.json', array('smart_collection' => $smartCollection->toArray())); |
66
|
|
|
$response = $this->send($request); |
67
|
|
|
return $this->createEntity($response->get('smart_collection')); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param int $smartCollectionId |
72
|
|
|
*/ |
73
|
|
|
public function delete($smartCollectionId) |
74
|
|
|
{ |
75
|
|
|
$request = new DeleteParams('/admin/smart_collections/' . $smartCollectionId . '.json'); |
76
|
|
|
$this->send($request); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param int $smartCollectionId |
81
|
|
|
* @param string $sort_order |
82
|
|
|
* @param array $productIds |
83
|
|
|
*/ |
84
|
|
|
public function setOrder($smartCollectionId, $sort_order = null, array $productIds = array()) |
85
|
|
|
{ |
86
|
|
|
$params = array(); |
87
|
|
|
|
88
|
|
|
if ($sort_order) { |
89
|
|
|
$params[] = 'sort_order=' . $sort_order; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
foreach ($productIds as $productId) { |
93
|
|
|
$params[] = 'products[]=' . $productId; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$url = '/admin/smart_collections/' . $smartCollectionId . '/order.json' . ($params ? '?' . implode('&', $params) : ''); |
97
|
|
|
|
98
|
|
|
$request = new PutJson($url); |
99
|
|
|
$this->send($request); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|