1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
6
|
|
|
* @package Admin |
7
|
|
|
* @subpackage JQAdm |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Admin\JQAdm\Order; |
12
|
|
|
|
13
|
|
|
sprintf( 'sales' ); // for translation |
14
|
|
|
sprintf( 'order' ); // for translation |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Default implementation of order JQAdm client. |
19
|
|
|
* |
20
|
|
|
* @package Admin |
21
|
|
|
* @subpackage JQAdm |
22
|
|
|
*/ |
23
|
|
|
class Standard |
24
|
|
|
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base |
25
|
|
|
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface |
26
|
|
|
{ |
27
|
|
|
/** admin/jqadm/order/name |
28
|
|
|
* Class name of the used account favorite client implementation |
29
|
|
|
* |
30
|
|
|
* Each default admin client can be replace by an alternative imlementation. |
31
|
|
|
* To use this implementation, you have to set the last part of the class |
32
|
|
|
* name as configuration value so the client factory knows which class it |
33
|
|
|
* has to instantiate. |
34
|
|
|
* |
35
|
|
|
* For example, if the name of the default class is |
36
|
|
|
* |
37
|
|
|
* \Aimeos\Admin\JQAdm\Order\Standard |
38
|
|
|
* |
39
|
|
|
* and you want to replace it with your own version named |
40
|
|
|
* |
41
|
|
|
* \Aimeos\Admin\JQAdm\Order\Myfavorite |
42
|
|
|
* |
43
|
|
|
* then you have to set the this configuration option: |
44
|
|
|
* |
45
|
|
|
* admin/jqadm/order/name = Myfavorite |
46
|
|
|
* |
47
|
|
|
* The value is the last part of your own class name and it's case sensitive, |
48
|
|
|
* so take care that the configuration value is exactly named like the last |
49
|
|
|
* part of the class name. |
50
|
|
|
* |
51
|
|
|
* The allowed characters of the class name are A-Z, a-z and 0-9. No other |
52
|
|
|
* characters are possible! You should always start the last part of the class |
53
|
|
|
* name with an upper case character and continue only with lower case characters |
54
|
|
|
* or numbers. Avoid chamel case names like "MyFavorite"! |
55
|
|
|
* |
56
|
|
|
* @param string Last part of the class name |
57
|
|
|
* @since 2016.01 |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Adds the required data used in the template |
63
|
|
|
* |
64
|
|
|
* @param \Aimeos\Base\View\Iface $view View object |
65
|
|
|
* @return \Aimeos\Base\View\Iface View object with assigned parameters |
66
|
|
|
*/ |
67
|
|
|
public function data( \Aimeos\Base\View\Iface $view ) : \Aimeos\Base\View\Iface |
68
|
|
|
{ |
69
|
|
|
$codes = []; |
70
|
|
|
|
71
|
|
|
foreach( $this->context()->config()->get( 'common/countries', [] ) as $code ) { |
72
|
|
|
$codes[$code] = $view->translate( 'country', $code ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
asort( $codes ); |
76
|
|
|
|
77
|
|
|
$view->itemSubparts = $this->getSubClientNames(); |
78
|
|
|
$view->countries = $codes; |
79
|
|
|
return $view; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Batch update of a resource |
85
|
|
|
* |
86
|
|
|
* @return string|null Output to display |
87
|
|
|
*/ |
88
|
|
|
public function batch() : ?string |
89
|
|
|
{ |
90
|
|
|
return $this->batchBase( 'order' ); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Copies a resource |
96
|
|
|
* |
97
|
|
|
* @return string|null HTML output |
98
|
|
|
*/ |
99
|
|
|
public function copy() : ?string |
100
|
|
|
{ |
101
|
|
|
$context = $this->context(); |
102
|
|
|
$view = $this->object()->data( $this->view() ); |
103
|
|
|
|
104
|
|
|
try |
105
|
|
|
{ |
106
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) |
107
|
|
|
{ |
108
|
|
|
$msg = $context->translate( 'admin', 'Required parameter "%1$s" is missing' ); |
109
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, 'id' ) ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order' ); |
113
|
|
|
$refs = $context->config()->get( 'mshop/order/manager/subdomains', [] ); |
114
|
|
|
|
115
|
|
|
$view->item = $manager->get( $id, $refs ); |
116
|
|
|
$view->itemData = $this->toArray( $view->item, true ); |
117
|
|
|
$view->itemBody = parent::copy(); |
118
|
|
|
} |
119
|
|
|
catch( \Exception $e ) |
120
|
|
|
{ |
121
|
|
|
$this->report( $e, 'copy' ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $this->render( $view ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Creates a new resource |
130
|
|
|
* |
131
|
|
|
* @return string|null HTML output |
132
|
|
|
*/ |
133
|
|
|
public function create() : ?string |
134
|
|
|
{ |
135
|
|
|
$view = $this->object()->data( $this->view() ); |
136
|
|
|
|
137
|
|
|
try |
138
|
|
|
{ |
139
|
|
|
$data = $view->param( 'item', [] ); |
140
|
|
|
|
141
|
|
|
if( !isset( $view->item ) ) { |
142
|
|
|
$view->item = \Aimeos\MShop::create( $this->context(), 'order' )->create(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$data['order.siteid'] = $view->item->getSiteId(); |
146
|
|
|
|
147
|
|
|
$view->itemData = array_replace_recursive( $this->toArray( $view->item ), $data ); |
148
|
|
|
$view->itemBody = parent::create(); |
149
|
|
|
} |
150
|
|
|
catch( \Exception $e ) |
151
|
|
|
{ |
152
|
|
|
$this->report( $e, 'create' ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $this->render( $view ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Exports a resource |
161
|
|
|
* |
162
|
|
|
* @return string Admin output to display |
163
|
|
|
*/ |
164
|
|
|
public function export() : ?string |
165
|
|
|
{ |
166
|
|
|
$view = $this->view(); |
167
|
|
|
$context = $this->context(); |
168
|
|
|
|
169
|
|
|
try |
170
|
|
|
{ |
171
|
|
|
$params = $this->storeFilter( $view->param(), 'order' ); |
172
|
|
|
$msg = ['sitecode' => $context->locale()->getSiteItem()->getCode()]; |
173
|
|
|
|
174
|
|
|
if( isset( $params['filter'] ) ) { |
175
|
|
|
$msg['filter'] = $this->getCriteriaConditions( (array) $params['filter'] ); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if( isset( $params['sort'] ) ) { |
179
|
|
|
$msg['sort'] = (array) $params['sort']; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$queue = $view->param( 'queue', 'order-export' ); |
183
|
|
|
$mq = $context->queue( 'mq-admin', $queue ); |
184
|
|
|
$mq->add( json_encode( $msg ) ); |
185
|
|
|
|
186
|
|
|
$msg = $context->translate( 'admin', 'Your export will be available in a few minutes for download' ); |
187
|
|
|
$view->info = $view->get( 'info', [] ) + ['order-item' => $msg]; |
188
|
|
|
} |
189
|
|
|
catch( \Exception $e ) |
190
|
|
|
{ |
191
|
|
|
$this->report( $e, 'export' ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
return $this->search(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns a single resource |
200
|
|
|
* |
201
|
|
|
* @return string|null HTML output |
202
|
|
|
*/ |
203
|
|
|
public function get() : ?string |
204
|
|
|
{ |
205
|
|
|
$context = $this->context(); |
206
|
|
|
$view = $this->object()->data( $this->view() ); |
207
|
|
|
|
208
|
|
|
try |
209
|
|
|
{ |
210
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) |
211
|
|
|
{ |
212
|
|
|
$msg = $context->translate( 'admin', 'Required parameter "%1$s" is missing' ); |
213
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( $msg, 'id' ) ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order' ); |
217
|
|
|
$refs = $context->config()->get( 'mshop/order/manager/subdomains', [] ); |
218
|
|
|
|
219
|
|
|
$view->item = $manager->get( $id, $refs ); |
220
|
|
|
$view->itemData = $this->toArray( $view->item ); |
221
|
|
|
$view->itemBody = parent::get(); |
222
|
|
|
} |
223
|
|
|
catch( \Exception $e ) |
224
|
|
|
{ |
225
|
|
|
$this->report( $e, 'get' ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
return $this->render( $view ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Saves the data |
234
|
|
|
* |
235
|
|
|
* @return string|null HTML output |
236
|
|
|
*/ |
237
|
|
|
public function save() : ?string |
238
|
|
|
{ |
239
|
|
|
$view = $this->view(); |
240
|
|
|
|
241
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'order' ); |
242
|
|
|
$manager->begin(); |
243
|
|
|
|
244
|
|
|
try |
245
|
|
|
{ |
246
|
|
|
$item = $this->fromArray( $view->param( 'item', [] ) ); |
247
|
|
|
$view->item = $item->getId() ? $item : $manager->save( clone $item ); |
248
|
|
|
$view->itemBody = parent::save(); |
249
|
|
|
|
250
|
|
|
$manager->save( clone $view->item ); |
251
|
|
|
$manager->commit(); |
252
|
|
|
|
253
|
|
|
return $this->redirect( 'order', $view->param( 'next' ), $view->item->getId(), 'save' ); |
|
|
|
|
254
|
|
|
} |
255
|
|
|
catch( \Exception $e ) |
256
|
|
|
{ |
257
|
|
|
$manager->rollback(); |
258
|
|
|
$this->report( $e, 'save' ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
return $this->create(); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Returns a list of resource according to the conditions |
267
|
|
|
* |
268
|
|
|
* @return string|null HTML output |
269
|
|
|
*/ |
270
|
|
|
public function search() : ?string |
271
|
|
|
{ |
272
|
|
|
$view = $this->view(); |
273
|
|
|
|
274
|
|
|
try |
275
|
|
|
{ |
276
|
|
|
$total = 0; |
277
|
|
|
$context = $this->context(); |
278
|
|
|
$refs = $context->config()->get( 'mshop/order/manager/subdomains', [] ); |
279
|
|
|
|
280
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order' ); |
281
|
|
|
$params = $this->storeFilter( $view->param(), 'order' ); |
282
|
|
|
|
283
|
|
|
$search = $manager->filter( false, true )->order( '-order.id' ); |
284
|
|
|
$search = $this->initCriteria( $search, $params ); |
285
|
|
|
|
286
|
|
|
$view->items = $manager->search( $search, $refs, $total ); |
287
|
|
|
$view->filterAttributes = $manager->getSearchAttributes( true ); |
288
|
|
|
$view->filterOperators = $search->getOperators(); |
289
|
|
|
$view->itemBody = parent::search(); |
290
|
|
|
$view->total = $total; |
291
|
|
|
} |
292
|
|
|
catch( \Exception $e ) |
293
|
|
|
{ |
294
|
|
|
$this->report( $e, 'search' ); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** admin/jqadm/order/template-list |
298
|
|
|
* Relative path to the HTML body template for the order list. |
299
|
|
|
* |
300
|
|
|
* The template file contains the HTML code and processing instructions |
301
|
|
|
* to generate the result shown in the body of the frontend. The |
302
|
|
|
* configuration string is the path to the template file relative |
303
|
|
|
* to the templates directory (usually in templates/admin/jqadm). |
304
|
|
|
* |
305
|
|
|
* You can overwrite the template file configuration in extensions and |
306
|
|
|
* provide alternative templates. These alternative templates should be |
307
|
|
|
* named like the default one but with the string "default" replaced by |
308
|
|
|
* an unique name. You may use the name of your project for this. If |
309
|
|
|
* you've implemented an alternative client class as well, "default" |
310
|
|
|
* should be replaced by the name of the new class. |
311
|
|
|
* |
312
|
|
|
* @param string Relative path to the template creating the HTML code |
313
|
|
|
* @since 2016.04 |
314
|
|
|
*/ |
315
|
|
|
$tplconf = 'admin/jqadm/order/template-list'; |
316
|
|
|
$default = 'order/list'; |
317
|
|
|
|
318
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Returns the sub-client given by its name. |
324
|
|
|
* |
325
|
|
|
* @param string $type Name of the client type |
326
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
327
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
328
|
|
|
*/ |
329
|
|
|
public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Admin\JQAdm\Iface |
330
|
|
|
{ |
331
|
|
|
/** admin/jqadm/order/decorators/excludes |
332
|
|
|
* Excludes decorators added by the "common" option from the order JQAdm client |
333
|
|
|
* |
334
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
335
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
336
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
337
|
|
|
* modify what is returned to the caller. |
338
|
|
|
* |
339
|
|
|
* This option allows you to remove a decorator added via |
340
|
|
|
* "client/jqadm/common/decorators/default" before they are wrapped |
341
|
|
|
* around the JQAdm client. |
342
|
|
|
* |
343
|
|
|
* admin/jqadm/order/decorators/excludes = array( 'decorator1' ) |
344
|
|
|
* |
345
|
|
|
* This would remove the decorator named "decorator1" from the list of |
346
|
|
|
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via |
347
|
|
|
* "client/jqadm/common/decorators/default" to the JQAdm client. |
348
|
|
|
* |
349
|
|
|
* @param array List of decorator names |
350
|
|
|
* @since 2016.01 |
351
|
|
|
* @see admin/jqadm/common/decorators/default |
352
|
|
|
* @see admin/jqadm/order/decorators/global |
353
|
|
|
* @see admin/jqadm/order/decorators/local |
354
|
|
|
*/ |
355
|
|
|
|
356
|
|
|
/** admin/jqadm/order/decorators/global |
357
|
|
|
* Adds a list of globally available decorators only to the order JQAdm client |
358
|
|
|
* |
359
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
360
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
361
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
362
|
|
|
* modify what is returned to the caller. |
363
|
|
|
* |
364
|
|
|
* This option allows you to wrap global decorators |
365
|
|
|
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. |
366
|
|
|
* |
367
|
|
|
* admin/jqadm/order/decorators/global = array( 'decorator1' ) |
368
|
|
|
* |
369
|
|
|
* This would add the decorator named "decorator1" defined by |
370
|
|
|
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. |
371
|
|
|
* |
372
|
|
|
* @param array List of decorator names |
373
|
|
|
* @since 2016.01 |
374
|
|
|
* @see admin/jqadm/common/decorators/default |
375
|
|
|
* @see admin/jqadm/order/decorators/excludes |
376
|
|
|
* @see admin/jqadm/order/decorators/local |
377
|
|
|
*/ |
378
|
|
|
|
379
|
|
|
/** admin/jqadm/order/decorators/local |
380
|
|
|
* Adds a list of local decorators only to the order JQAdm client |
381
|
|
|
* |
382
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
383
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
384
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
385
|
|
|
* modify what is returned to the caller. |
386
|
|
|
* |
387
|
|
|
* This option allows you to wrap local decorators |
388
|
|
|
* ("\Aimeos\Admin\JQAdm\Order\Decorator\*") around the JQAdm client. |
389
|
|
|
* |
390
|
|
|
* admin/jqadm/order/decorators/local = array( 'decorator2' ) |
391
|
|
|
* |
392
|
|
|
* This would add the decorator named "decorator2" defined by |
393
|
|
|
* "\Aimeos\Admin\JQAdm\Order\Decorator\Decorator2" only to the JQAdm client. |
394
|
|
|
* |
395
|
|
|
* @param array List of decorator names |
396
|
|
|
* @since 2016.01 |
397
|
|
|
* @see admin/jqadm/common/decorators/default |
398
|
|
|
* @see admin/jqadm/order/decorators/excludes |
399
|
|
|
* @see admin/jqadm/order/decorators/global |
400
|
|
|
*/ |
401
|
|
|
return $this->createSubClient( 'order/' . $type, $name ); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Returns the allowed keys for updating the item of the given type |
407
|
|
|
* |
408
|
|
|
* @param string $type Type of the item, e.g. "order/product" |
409
|
|
|
* @param array $entry Associative list of key/value pairs |
410
|
|
|
* @return array Reduced list of key/value pairs |
411
|
|
|
*/ |
412
|
|
|
protected function allowed( string $type, array $entry ) : array |
413
|
|
|
{ |
414
|
|
|
if( $type === 'order/product' ) |
415
|
|
|
{ |
416
|
|
|
$allowed = array_flip( [ |
417
|
|
|
'order.product.statusdelivery', |
418
|
|
|
'order.product.statuspayment', |
419
|
|
|
'order.product.qtyopen', |
420
|
|
|
'order.product.timeframe', |
421
|
|
|
'order.product.notes', |
422
|
|
|
] ); |
423
|
|
|
|
424
|
|
|
return array_intersect_key( $entry, $allowed ); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return []; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Modifies the used attributes from the passed list of order service attributes |
433
|
|
|
* |
434
|
|
|
* @param string $type Type of the attribute items, e.g. "order/service/attribute" |
435
|
|
|
* @param \Aimeos\Map $attrItems List of attribute items |
436
|
|
|
* @return \Aimeos\Map Modified list of attribute items |
437
|
|
|
*/ |
438
|
|
|
protected function attributes( string $type, \Aimeos\Map $attrItems ) : \Aimeos\Map |
439
|
|
|
{ |
440
|
|
|
return $attrItems; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Returns the list of sub-client names configured for the client. |
446
|
|
|
* |
447
|
|
|
* @return array List of JQAdm client names |
448
|
|
|
*/ |
449
|
|
|
protected function getSubClientNames() : array |
450
|
|
|
{ |
451
|
|
|
/** admin/jqadm/order/subparts |
452
|
|
|
* List of JQAdm sub-clients rendered within the order section |
453
|
|
|
* |
454
|
|
|
* The output of the frontend is composed of the code generated by the JQAdm |
455
|
|
|
* clients. Each JQAdm client can consist of serveral (or none) sub-clients |
456
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
457
|
|
|
* sub-clients can contain JQAdm clients themselves and therefore a |
458
|
|
|
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates |
459
|
|
|
* the output that is placed inside the container of its parent. |
460
|
|
|
* |
461
|
|
|
* At first, always the JQAdm code generated by the parent is printed, then |
462
|
|
|
* the JQAdm code of its sub-clients. The order of the JQAdm sub-clients |
463
|
|
|
* determines the order of the output of these sub-clients inside the parent |
464
|
|
|
* container. If the configured list of clients is |
465
|
|
|
* |
466
|
|
|
* array( "subclient1", "subclient2" ) |
467
|
|
|
* |
468
|
|
|
* you can easily change the order of the output by reordering the subparts: |
469
|
|
|
* |
470
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) |
471
|
|
|
* |
472
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
473
|
|
|
* |
474
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1" ) |
475
|
|
|
* |
476
|
|
|
* As the clients only generates structural JQAdm, the layout defined via CSS |
477
|
|
|
* should support adding, removing or reordering content by a fluid like |
478
|
|
|
* design. |
479
|
|
|
* |
480
|
|
|
* @param array List of sub-client names |
481
|
|
|
* @since 2016.01 |
482
|
|
|
*/ |
483
|
|
|
return $this->context()->config()->get( 'admin/jqadm/order/subparts', [] ); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Creates new and updates existing items using the data array |
489
|
|
|
* |
490
|
|
|
* @param array $data Data array |
491
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface New order item object |
492
|
|
|
*/ |
493
|
|
|
protected function fromArray( array $data ) : \Aimeos\MShop\Order\Item\Iface |
494
|
|
|
{ |
495
|
|
|
$context = $this->context(); |
496
|
|
|
|
497
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order' ); |
498
|
|
|
$attrManager = \Aimeos\MShop::create( $context, 'order/service/attribute' ); |
499
|
|
|
|
500
|
|
|
if( isset( $data['order.id'] ) ) { |
501
|
|
|
$refs = $context->config()->get( 'mshop/order/manager/subdomains', [] ); |
502
|
|
|
$basket = $manager->get( $data['order.id'], $refs )->off(); |
503
|
|
|
} else { |
504
|
|
|
$basket = $manager->create()->off(); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
$basket->fromArray( $data, true ); |
508
|
|
|
|
509
|
|
|
foreach( $basket->getProducts() as $pos => $product ) |
510
|
|
|
{ |
511
|
|
|
$list = $this->allowed( 'order/product', $data['product'][$pos] ); |
512
|
|
|
$product->fromArray( $list ); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
foreach( $basket->getAddresses() as $type => $addresses ) |
516
|
|
|
{ |
517
|
|
|
foreach( $addresses as $pos => $address ) |
518
|
|
|
{ |
519
|
|
|
if( isset( $data['address'][$type][$pos] ) ) { |
520
|
|
|
$list = (array) $data['address'][$type][$pos]; |
521
|
|
|
$basket->addAddress( $address->fromArray( $list, true ), $type, $pos ); |
522
|
|
|
} else { |
523
|
|
|
$basket->deleteAddress( $type, $pos ); |
524
|
|
|
} |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
foreach( $basket->getServices() as $type => $services ) |
529
|
|
|
{ |
530
|
|
|
foreach( $services as $service ) |
531
|
|
|
{ |
532
|
|
|
$serviceId = $service->getId(); |
533
|
|
|
$attrItems = $this->attributes( 'order/service/attribute', $service->getAttributeItems() ); |
534
|
|
|
|
535
|
|
|
foreach( $data['service'][$type][$serviceId] ?? [] as $idx => $entry ) |
536
|
|
|
{ |
537
|
|
|
$entry = array_filter( $entry ); |
538
|
|
|
$id = $entry['order.service.attribute.id'] ?? ''; |
539
|
|
|
$attrItem = $attrItems[$id] ?? $attrManager->create(); |
540
|
|
|
|
541
|
|
|
$value = $entry['order.service.attribute.value'] ?? ''; |
542
|
|
|
$entry['order.service.attribute.value'] = json_decode( $value, true ) ?? $value; |
543
|
|
|
|
544
|
|
|
$attrManager->save( $attrItem->fromArray( $entry, true )->setParentId( $service->getId() ) ); |
545
|
|
|
unset( $attrItems[$id] ); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
$attrManager->delete( $attrItems ); |
549
|
|
|
} |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
return $basket; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Constructs the data array for the view from the given item |
558
|
|
|
* |
559
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $item Order item object |
560
|
|
|
* @return string[] Multi-dimensional associative list of item data |
561
|
|
|
*/ |
562
|
|
|
protected function toArray( \Aimeos\MShop\Order\Item\Iface $item, bool $copy = false ) : array |
563
|
|
|
{ |
564
|
|
|
$siteId = $this->context()->locale()->getSiteId(); |
565
|
|
|
$data = $item->toArray( true ); |
566
|
|
|
|
567
|
|
|
if( $item->getCustomerId() != '' ) |
568
|
|
|
{ |
569
|
|
|
try { |
570
|
|
|
$data += \Aimeos\MShop::create( $this->context(), 'customer' )->get( $item->getCustomerId() )->toArray(); |
571
|
|
|
} catch( \Exception $e ) {}; |
|
|
|
|
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
|
575
|
|
|
if( $copy === true ) |
576
|
|
|
{ |
577
|
|
|
$data['order.siteid'] = $siteId; |
578
|
|
|
$data['order.id'] = ''; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
foreach( $item->getAddresses() as $type => $addresses ) |
582
|
|
|
{ |
583
|
|
|
foreach( $addresses as $pos => $addrItem ) |
584
|
|
|
{ |
585
|
|
|
$data['address'][$type][$pos] = $addrItem->toArray( true ); |
586
|
|
|
|
587
|
|
|
if( $copy === true ) |
588
|
|
|
{ |
589
|
|
|
$data['address'][$type][$pos]['order.address.siteid'] = $siteId; |
590
|
|
|
$data['address'][$type][$pos]['order.address.id'] = ''; |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
foreach( $item->getProducts() as $pos => $productItem ) |
596
|
|
|
{ |
597
|
|
|
$data['product'][$pos] = $productItem->toArray( true ); |
598
|
|
|
$data['product'][$pos]['attributes'] = []; |
599
|
|
|
|
600
|
|
|
foreach( $productItem->getAttributeItems() as $attrItem ) |
601
|
|
|
{ |
602
|
|
|
$entry = $attrItem->toArray( true ); |
603
|
|
|
|
604
|
|
|
if( $copy === true ) |
605
|
|
|
{ |
606
|
|
|
$entry['order.product.attribute.siteid'] = $siteId; |
607
|
|
|
$entry['order.product.attribute.id'] = ''; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
$data['product'][$pos]['attributes'][] = $entry; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
if( $copy === true ) |
614
|
|
|
{ |
615
|
|
|
$data['product'][$pos]['order.product.siteid'] = $siteId; |
616
|
|
|
$data['product'][$pos]['order.product.id'] = ''; |
617
|
|
|
} |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
foreach( $item->getServices() as $type => $services ) |
621
|
|
|
{ |
622
|
|
|
foreach( $services as $serviceItem ) |
623
|
|
|
{ |
624
|
|
|
$serviceId = $serviceItem->getId(); |
625
|
|
|
$data['service'][$type][$serviceId] = $serviceItem->toArray( true ); |
626
|
|
|
$data['service'][$type][$serviceId]['attributes'] = []; |
627
|
|
|
|
628
|
|
|
foreach( $this->attributes( 'order/service/attribute', $serviceItem->getAttributeItems() ) as $attrItem ) |
629
|
|
|
{ |
630
|
|
|
$entry = $attrItem->toArray( true ); |
631
|
|
|
|
632
|
|
|
if( $copy === true ) |
633
|
|
|
{ |
634
|
|
|
$entry['order.service.attribute.siteid'] = $siteId; |
635
|
|
|
$entry['order.service.attribute.id'] = ''; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
$data['service'][$type][$serviceId]['attributes'][] = $entry; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
if( $copy === true ) |
642
|
|
|
{ |
643
|
|
|
$data['service'][$type][$serviceId]['order.service.siteid'] = $siteId; |
644
|
|
|
$data['service'][$type][$serviceId]['order.service.id'] = ''; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
return $data; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* Returns the rendered template including the view data |
655
|
|
|
* |
656
|
|
|
* @param \Aimeos\Base\View\Iface $view View object with data assigned |
657
|
|
|
* @return string HTML output |
658
|
|
|
*/ |
659
|
|
|
protected function render( \Aimeos\Base\View\Iface $view ) : string |
660
|
|
|
{ |
661
|
|
|
/** admin/jqadm/order/template-item |
662
|
|
|
* Relative path to the HTML body template for the order item. |
663
|
|
|
* |
664
|
|
|
* The template file contains the HTML code and processing instructions |
665
|
|
|
* to generate the result shown in the body of the frontend. The |
666
|
|
|
* configuration string is the path to the template file relative |
667
|
|
|
* to the templates directory (usually in templates/admin/jqadm). |
668
|
|
|
* |
669
|
|
|
* You can overwrite the template file configuration in extensions and |
670
|
|
|
* provide alternative templates. These alternative templates should be |
671
|
|
|
* named like the default one but with the string "default" replaced by |
672
|
|
|
* an unique name. You may use the name of your project for this. If |
673
|
|
|
* you've implemented an alternative client class as well, "default" |
674
|
|
|
* should be replaced by the name of the new class. |
675
|
|
|
* |
676
|
|
|
* @param string Relative path to the template creating the HTML code |
677
|
|
|
* @since 2016.04 |
678
|
|
|
*/ |
679
|
|
|
$tplconf = 'admin/jqadm/order/template-item'; |
680
|
|
|
$default = 'order/item'; |
681
|
|
|
|
682
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
683
|
|
|
} |
684
|
|
|
} |
685
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.