Browse code

Add order related api methods

Benjamin Roth authored on13/11/2024 16:05:20
Showing1 changed files
... ...
@@ -164,6 +164,145 @@ class Shopware
164 164
         return $this->sendRequest('search/product',$options,'POST');
165 165
     }
166 166
 
167
+    public function findOrdersByFilter(array $filter, bool $blnShort=false): ResponseInterface
168
+    {
169
+        $options = [
170
+            'headers' => [
171
+                $this->getAuthentication(),
172
+                'Content-Type: application/json',
173
+                'Accept: application/json'
174
+            ],
175
+            'body' => json_encode([
176
+                'filter' => $filter,
177
+                'sort' => [
178
+                    [
179
+                        'field' => 'createdAt',
180
+                        'order' => 'ASC',
181
+                        'naturalSorting' => true
182
+                    ]
183
+                ],
184
+                'includes' => [
185
+                    'order' => ['id', 'orderNumber', 'createdAt', 'billingAddress', 'deliveries', 'lineItems','taxStatus','orderCustomer','amountTotal','shippingTotal','transactions'],
186
+                    'order_delivery' => ['shippingOrderAddress','shippingMethod'],
187
+                    'country' => ['name','iso'],
188
+                    'order_line_item' => ['position', 'quantity', 'label', 'unitPrice', 'totalPrice', 'price','priceDefinition', 'productId', 'product', 'type', 'payload'],
189
+                    'product' => ['ean','productNumber','name'],
190
+                    'payment_method' => ['id','name','shortName'],
191
+                    'shipping_method' => ['id','name'],
192
+                    'order_transaction' => ['amount','paymentMethod'],
193
+                ],
194
+                'associations' => [
195
+                    'transactions' => [
196
+                        'associations' => [
197
+                            'paymentMethod' => []
198
+                        ]
199
+                    ],
200
+                    'billingAddress' => [
201
+                        'associations' => [
202
+                            'country' => []
203
+                        ]
204
+                    ],
205
+                    'deliveries' => [
206
+                        'associations' => [
207
+                            'shippingOrderAddress' => [
208
+                                'associations' => [
209
+                                    'country' => []
210
+                                ]
211
+                            ],
212
+                            'shippingMethod' => []
213
+                        ]
214
+                    ],
215
+                    'lineItems' => [
216
+                        'associations' => [
217
+                            'product' => []
218
+                        ]
219
+                    ],
220
+                ]
221
+            ])
222
+        ];
223
+
224
+        if ($blnShort)
225
+        {
226
+            $options['body'] = json_encode(
227
+                array_merge(
228
+                    json_decode($options['body'],true),
229
+                    [
230
+                        'fields' => [
231
+                            'orderNumber'
232
+                        ]
233
+                    ]
234
+                )
235
+            );
236
+        }
237
+
238
+        return $this->sendRequest('search/order',$options,'POST');
239
+    }
240
+
241
+    public function getOrderAddressById(string $strId, bool $blnShort=false): ResponseInterface
242
+    {
243
+        $options = [
244
+            'headers' => [
245
+                $this->getAuthentication(),
246
+                'Content-Type: application/json',
247
+                'Accept: application/json'
248
+            ]
249
+        ];
250
+
251
+        return $this->sendRequest('order-address/'.$strId,$options,'GET');
252
+    }
253
+
254
+    public function getOrder(string $strId, ?string $pathSuffix=null): ResponseInterface
255
+    {
256
+        $options = [
257
+            'headers' => [
258
+                $this->getAuthentication(),
259
+                'Content-Type: application/json',
260
+                'Accept: application/json'
261
+            ]
262
+        ];
263
+
264
+        return $this->sendRequest('order/'.$strId.($pathSuffix ? '/'.$pathSuffix : ''),$options,'GET');
265
+    }
266
+
267
+    public function getOrderLineItemsByFilter(array $filter, bool $blnShort=false): ResponseInterface
268
+    {
269
+        $options = [
270
+            'headers' => [
271
+                $this->getAuthentication(),
272
+                'Content-Type: application/json',
273
+                'Accept: application/json'
274
+            ],
275
+            'body' => json_encode([
276
+                'filter' => $filter,
277
+                'sort' => [
278
+                    [
279
+                        'field' => 'createdAt',
280
+                        'order' => 'ASC',
281
+                        'naturalSorting' => true
282
+                    ]
283
+                ]
284
+            ])
285
+        ];
286
+
287
+        if ($blnShort)
288
+        {
289
+            $options['body'] = json_encode(
290
+                array_merge(
291
+                    json_decode($options['body'],true),
292
+                    [
293
+                        'fields' => [
294
+                            'id',
295
+                            'label',
296
+                            'quantity',
297
+                        ]
298
+                    ]
299
+                )
300
+            );
301
+        }
302
+
303
+        return $this->sendRequest('search/order-line-item',$options,'POST');
304
+    }
305
+
167 306
     public function queryAPI(string $strUrlFragment, ?string $strBody, string $strMethod = 'GET', bool $blnAuthenticate=true): ResponseInterface
168 307
     {
169 308
         $options = [