|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Signifly\Shopify\REST\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Signifly\Shopify\REST\Cursor; |
|
7
|
|
|
use Signifly\Shopify\REST\Resources\ApiResource; |
|
8
|
|
|
use Signifly\Shopify\REST\Resources\CollectResource; |
|
9
|
|
|
use Signifly\Shopify\REST\Resources\CustomCollectionResource; |
|
10
|
|
|
use Signifly\Shopify\REST\Resources\ProductResource; |
|
11
|
|
|
use Signifly\Shopify\REST\Resources\SmartCollectionResource; |
|
12
|
|
|
use Signifly\Shopify\Shopify; |
|
13
|
|
|
|
|
14
|
|
|
/** @mixin Shopify */ |
|
15
|
|
|
trait ManagesCollections |
|
16
|
|
|
{ |
|
17
|
|
|
public function createCustomCollection(array $data): CustomCollectionResource |
|
18
|
|
|
{ |
|
19
|
|
|
$response = $this->post('custom_collections.json', ['custom_collection' => $data]); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
return new CustomCollectionResource($response['custom_collection'], $this); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getCustomCollectionsCount(array $params = []): int |
|
25
|
|
|
{ |
|
26
|
|
|
$response = $this->get('custom_collections/count.json', $params); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
return $response['count'] ?? 0; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function paginateCustomCollections(array $params): Cursor |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->cursor($this->getCustomCollections($params)); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getCustomCollections(array $params = []): Collection |
|
37
|
|
|
{ |
|
38
|
|
|
$response = $this->get('custom_collections.json', $params); |
|
39
|
|
|
|
|
40
|
|
|
return $this->transformCollection($response['custom_collections'], CustomCollectionResource::class); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getCustomCollection($collectionId): CustomCollectionResource |
|
44
|
|
|
{ |
|
45
|
|
|
$response = $this->get("custom_collections/{$collectionId}.json"); |
|
46
|
|
|
|
|
47
|
|
|
return new CustomCollectionResource($response['custom_collection'], $this); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function updateCustomCollection($collectionId, array $data): CustomCollectionResource |
|
51
|
|
|
{ |
|
52
|
|
|
$response = $this->put("custom_collections/{$collectionId}.json", ['custom_collection' => $data]); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
return new CustomCollectionResource($response['custom_collection'], $this); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function deleteCustomCollection($collectionId): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->delete("custom_collections/{$collectionId}.json"); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function createSmartCollection(array $data): SmartCollectionResource |
|
63
|
|
|
{ |
|
64
|
|
|
$response = $this->post('smart_collections.json', ['smart_collection' => $data]); |
|
65
|
|
|
|
|
66
|
|
|
return new SmartCollectionResource($response['smart_collection'], $this); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getSmartCollectionsCount(array $params = []): int |
|
70
|
|
|
{ |
|
71
|
|
|
$response = $this->get('smart_collections/count.json', $params); |
|
72
|
|
|
|
|
73
|
|
|
return $response['count'] ?? 0; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getSmartCollections(array $params = []): Collection |
|
77
|
|
|
{ |
|
78
|
|
|
$response = $this->get('smart_collections.json', $params); |
|
79
|
|
|
|
|
80
|
|
|
return $this->transformCollection($response['smart_collections'], SmartCollectionResource::class); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getSmartCollection($collectionId): SmartCollectionResource |
|
84
|
|
|
{ |
|
85
|
|
|
$response = $this->get("smart_collections/{$collectionId}.json"); |
|
86
|
|
|
|
|
87
|
|
|
return new SmartCollectionResource($response['smart_collection'], $this); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function updateSmartCollection($collectionId, array $data): SmartCollectionResource |
|
91
|
|
|
{ |
|
92
|
|
|
$response = $this->put("smart_collections/{$collectionId}.json", ['smart_collection' => $data]); |
|
93
|
|
|
|
|
94
|
|
|
return new SmartCollectionResource($response['smart_collection'], $this); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function deleteSmartCollection($collectionId): void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->delete("smart_collections/{$collectionId}.json"); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function reorderSmartCollection($collectionId, array $productIds) |
|
103
|
|
|
{ |
|
104
|
|
|
$response = $this->put("smart_collections/{$collectionId}/order.json", ['products' => $productIds]); |
|
105
|
|
|
|
|
106
|
|
|
return new SmartCollectionResource($response['smart_collection'], $this); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function createCollect(array $data): CollectResource |
|
110
|
|
|
{ |
|
111
|
|
|
$response = $this->post('collects.json', ['collect' => $data]); |
|
112
|
|
|
|
|
113
|
|
|
return new CollectResource($response['collect'], $this); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getCollectsCount(array $params = []): int |
|
117
|
|
|
{ |
|
118
|
|
|
$response = $this->get('collects/count.json', $params); |
|
119
|
|
|
|
|
120
|
|
|
return $response['count'] ?? 0; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getCollects(array $params = []): Collection |
|
124
|
|
|
{ |
|
125
|
|
|
$response = $this->get('collects.json', $params); |
|
126
|
|
|
|
|
127
|
|
|
return $this->transformCollection($response['collects'], CollectResource::class); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function deleteCollect($collectId): void |
|
131
|
|
|
{ |
|
132
|
|
|
$this->delete("collects/{$collectId}.json"); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getCollection($collectionId): ApiResource |
|
136
|
|
|
{ |
|
137
|
|
|
$response = $this->get("collections/{$collectionId}.json"); |
|
138
|
|
|
|
|
139
|
|
|
return new ApiResource($response['collection'], $this); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function getCollectionProducts($collectionId, array $params = []): Collection |
|
143
|
|
|
{ |
|
144
|
|
|
$response = $this->get("collections/{$collectionId}/products.json", $params); |
|
145
|
|
|
|
|
146
|
|
|
return $this->transformCollection($response['products'], ProductResource::class); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|