1
|
|
|
<?php |
2
|
|
|
namespace Loevgaard\Dandomain\Api\Endpoint; |
3
|
|
|
|
4
|
|
|
use Assert\Assert; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help |
8
|
|
|
*/ |
9
|
|
|
class Product extends Endpoint |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProduct |
13
|
|
|
* |
14
|
|
|
* @param string $productNumber |
15
|
|
|
* @param int $siteId |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function getProduct(string $productNumber, int $siteId) : array |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0'); |
21
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
22
|
|
|
|
23
|
|
|
return (array)$this->master->doRequest( |
24
|
|
|
'GET', |
25
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/%s/%d', rawurlencode($productNumber), $siteId) |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductsInCategory |
31
|
|
|
* |
32
|
|
|
* @param int $categoryId |
33
|
|
|
* @param int $siteId |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function getProductsInCategory(int $categoryId, int $siteId) : array |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
Assert::that($categoryId)->greaterThan(0, 'The $categoryId has to be positive'); |
39
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
40
|
|
|
|
41
|
|
|
return (array)$this->master->doRequest( |
42
|
|
|
'GET', |
43
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Products/%d/%d', $categoryId, $siteId) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetCategories |
49
|
|
|
* |
50
|
|
|
* @param int $siteId |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function getCategories(int $siteId) : array |
54
|
|
|
{ |
55
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
56
|
|
|
|
57
|
|
|
return (array)$this->master->doRequest( |
58
|
|
|
'GET', |
59
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Categories/%d', $siteId) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetSubCategories |
65
|
|
|
* |
66
|
|
|
* @param int $categoryId |
67
|
|
|
* @param int $siteId |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function getSubCategories(int $categoryId, int $siteId) : array |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
Assert::that($categoryId)->greaterThan(0, 'The $categoryId has to be positive'); |
73
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
74
|
|
|
|
75
|
|
|
return (array)$this->master->doRequest( |
76
|
|
|
'GET', |
77
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Categories/%d/%d', $categoryId, $siteId) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductByMetadata |
83
|
|
|
* |
84
|
|
|
* @param string $productNumber |
85
|
|
|
* @param array $context |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function getProductByMetadata(string $productNumber, array $context) : array |
89
|
|
|
{ |
90
|
|
|
Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0'); |
91
|
|
|
Assert::that($context)->notEmpty(); |
92
|
|
|
|
93
|
|
|
return (array)$this->master->doRequest( |
94
|
|
|
'POST', |
95
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/%s', rawurlencode($productNumber)), |
96
|
|
|
$context |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductsInCategoryByMetadata |
102
|
|
|
* |
103
|
|
|
* @param int $categoryId |
104
|
|
|
* @param array $context |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getProductsInCategoryByMetadata(int $categoryId, array $context) : array |
108
|
|
|
{ |
109
|
|
|
Assert::that($categoryId)->greaterThan(0, 'The $categoryId has to be positive'); |
110
|
|
|
Assert::that($context)->notEmpty(); |
111
|
|
|
|
112
|
|
|
return (array)$this->master->doRequest( |
113
|
|
|
'POST', |
114
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Products/%d', $categoryId), |
115
|
|
|
$context |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetCategory |
121
|
|
|
* |
122
|
|
|
* @param int $categoryId |
123
|
|
|
* @param int $siteId |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
View Code Duplication |
public function getCategory(int $categoryId, int $siteId) : array |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
Assert::that($categoryId)->greaterThan(0, 'The $categoryId has to be positive'); |
129
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
130
|
|
|
|
131
|
|
|
return (array)$this->master->doRequest( |
132
|
|
|
'GET', |
133
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Category/%d/%d', $categoryId, $siteId) |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/FindProductNumbersByKeyword |
139
|
|
|
* |
140
|
|
|
* @param string $keyword |
141
|
|
|
* @param int $siteId |
142
|
|
|
* @return array |
143
|
|
|
*/ |
144
|
|
View Code Duplication |
public function findProductNumbersByKeyword(string $keyword, int $siteId) : array |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
Assert::that($keyword)->minLength(1, 'The length of $keyword has to be > 0'); |
147
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
148
|
|
|
|
149
|
|
|
return (array)$this->master->doRequest( |
150
|
|
|
'GET', |
151
|
|
|
sprintf( |
152
|
|
|
'/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/FindProductNumbersByKeyword/%s/%d', |
153
|
|
|
rawurlencode($keyword), |
154
|
|
|
$siteId |
155
|
|
|
) |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductsByBarcode |
161
|
|
|
* |
162
|
|
|
* @param string $barCode |
163
|
|
|
* @param int $siteId |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
|
View Code Duplication |
public function getProductsByBarcode(string $barCode, int $siteId) : array |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
Assert::that($barCode)->minLength(1, 'The length of $barCode has to be > 0'); |
169
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
170
|
|
|
|
171
|
|
|
return (array)$this->master->doRequest( |
172
|
|
|
'GET', |
173
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/ByBarcode/%s/%d', rawurlencode($barCode), $siteId) |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductsByModificationDate |
179
|
|
|
* |
180
|
|
|
* @param \DateTimeInterface $modificationDate |
181
|
|
|
* @param int $siteId |
182
|
|
|
* @return array |
183
|
|
|
*/ |
184
|
|
|
public function getProductsByModificationDate(\DateTimeInterface $modificationDate, int $siteId) : array |
185
|
|
|
{ |
186
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
187
|
|
|
|
188
|
|
|
return (array)$this->master->doRequest( |
189
|
|
|
'GET', |
190
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/ByModificationDate/%s/%d', $modificationDate->format('Y-m-d'), $siteId) |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/FindProductsByProductNumbers |
196
|
|
|
* |
197
|
|
|
* @param int $siteId |
198
|
|
|
* @param array $productNumbers |
199
|
|
|
* @param int $page |
200
|
|
|
* @param int $pageSize |
201
|
|
|
* @return array |
202
|
|
|
*/ |
203
|
|
|
public function findProductsByProductNumbers(int $siteId, array $productNumbers, int $page = 1, int $pageSize = 100) : array |
204
|
|
|
{ |
205
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
206
|
|
|
Assert::that($productNumbers)->notEmpty(); |
207
|
|
|
Assert::thatAll($productNumbers)->minLength(1, 'All product numbers in $productNumbers must have a length > 0'); |
208
|
|
|
Assert::that($page)->greaterThan(0, 'The $page has to be positive'); |
209
|
|
|
Assert::that($pageSize)->greaterThan(0, 'The $pageSize has to be positive'); |
210
|
|
|
|
211
|
|
|
$body = [ |
212
|
|
|
'Identifiers' => $productNumbers, |
213
|
|
|
'PageIndex' => $page, |
214
|
|
|
'Pagesize' => $pageSize |
215
|
|
|
]; |
216
|
|
|
|
217
|
|
|
return (array)$this->master->doRequest( |
218
|
|
|
'GET', |
219
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/FindProductsByProductNumbers/%d', $siteId), |
220
|
|
|
$body |
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @see http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductService/help/operations/GetProductsInModifiedInterval |
226
|
|
|
* |
227
|
|
|
* @param int $siteId |
228
|
|
|
* @param \DateTimeInterface $dateStart |
229
|
|
|
* @param \DateTimeInterface $dateEnd |
230
|
|
|
* @return array |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function getProductsInModifiedInterval(int $siteId, \DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) : array |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive'); |
235
|
|
|
Assert::that($dateStart)->lessThan($dateEnd, '$dateStart has to be before $dateEnd'); |
236
|
|
|
|
237
|
|
|
return (array)$this->master->doRequest( |
238
|
|
|
'GET', |
239
|
|
|
sprintf( |
240
|
|
|
'/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/GetByModifiedInterval/%d?start=%s&end=%s', |
241
|
|
|
$siteId, |
242
|
|
|
$dateStart->format('Y-m-d\TH:i:s'), |
243
|
|
|
$dateEnd->format('Y-m-d\TH:i:s') |
244
|
|
|
) |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.