|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
|
6
|
|
|
* @package Admin |
|
7
|
|
|
* @subpackage JQAdm |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Admin\JQAdm\Customer\Product; |
|
12
|
|
|
|
|
13
|
|
|
sprintf( 'product' ); // for translation |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Default implementation of customer product JQAdm client. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Admin |
|
20
|
|
|
* @subpackage JQAdm |
|
21
|
|
|
*/ |
|
22
|
|
|
class Standard |
|
23
|
|
|
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base |
|
24
|
|
|
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface |
|
25
|
|
|
{ |
|
26
|
|
|
/** admin/jqadm/customer/product/name |
|
27
|
|
|
* Name of the product subpart used by the JQAdm customer implementation |
|
28
|
|
|
* |
|
29
|
|
|
* Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Customer\Address\Myname". |
|
30
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
|
31
|
|
|
* |
|
32
|
|
|
* @param string Last part of the JQAdm class name |
|
33
|
|
|
* @since 2017.06 |
|
34
|
|
|
* @category Developer |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Copies a resource |
|
40
|
|
|
* |
|
41
|
|
|
* @return string HTML output |
|
42
|
|
|
*/ |
|
43
|
|
|
public function copy() |
|
44
|
|
|
{ |
|
45
|
|
|
$view = $this->getView(); |
|
46
|
|
|
|
|
47
|
|
|
try |
|
48
|
|
|
{ |
|
49
|
|
|
$view->productListTypes = $this->getListTypes(); |
|
50
|
|
|
$view->productBody = ''; |
|
51
|
|
|
|
|
52
|
|
|
foreach( $this->getSubClients() as $client ) { |
|
53
|
|
|
$view->productBody .= $client->copy(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
57
|
|
|
{ |
|
58
|
|
|
$error = array( 'customer-product' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
59
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
60
|
|
|
$this->logException( $e ); |
|
61
|
|
|
} |
|
62
|
|
|
catch( \Exception $e ) |
|
63
|
|
|
{ |
|
64
|
|
|
$error = array( 'customer-product' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
|
65
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
66
|
|
|
$this->logException( $e ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->render( $view ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Creates a new resource |
|
75
|
|
|
* |
|
76
|
|
|
* @return string HTML output |
|
77
|
|
|
*/ |
|
78
|
|
|
public function create() |
|
79
|
|
|
{ |
|
80
|
|
|
$view = $this->getView(); |
|
81
|
|
|
|
|
82
|
|
|
try |
|
83
|
|
|
{ |
|
84
|
|
|
$view->productListTypes = $this->getListTypes(); |
|
85
|
|
|
$view->productBody = ''; |
|
86
|
|
|
|
|
87
|
|
|
foreach( $this->getSubClients() as $client ) { |
|
88
|
|
|
$view->productBody .= $client->create(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
92
|
|
|
{ |
|
93
|
|
|
$error = array( 'customer-product' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
94
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
95
|
|
|
$this->logException( $e ); |
|
96
|
|
|
} |
|
97
|
|
|
catch( \Exception $e ) |
|
98
|
|
|
{ |
|
99
|
|
|
$error = array( 'customer-product' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
|
100
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
101
|
|
|
$this->logException( $e ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->render( $view ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Returns a single resource |
|
110
|
|
|
* |
|
111
|
|
|
* @return string HTML output |
|
112
|
|
|
*/ |
|
113
|
|
|
public function get() |
|
114
|
|
|
{ |
|
115
|
|
|
$view = $this->getView(); |
|
116
|
|
|
|
|
117
|
|
|
try |
|
118
|
|
|
{ |
|
119
|
|
|
$total = 0; |
|
120
|
|
|
$params = $this->storeSearchParams( $view->param( 'up', [] ), 'customerproduct' ); |
|
121
|
|
|
$listItems = $this->getListItems( $view->item, $params, $total ); |
|
122
|
|
|
|
|
123
|
|
|
$view->productItems = $this->getProductItems( $listItems ); |
|
124
|
|
|
$view->productData = $this->toArray( $listItems ); |
|
125
|
|
|
$view->productListTypes = $this->getListTypes(); |
|
126
|
|
|
$view->productTotal = $total; |
|
127
|
|
|
$view->productBody = ''; |
|
128
|
|
|
|
|
129
|
|
|
foreach( $this->getSubClients() as $client ) { |
|
130
|
|
|
$view->productBody .= $client->search(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
134
|
|
|
{ |
|
135
|
|
|
$error = array( 'customer-product' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
136
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
137
|
|
|
$this->logException( $e ); |
|
138
|
|
|
} |
|
139
|
|
|
catch( \Exception $e ) |
|
140
|
|
|
{ |
|
141
|
|
|
$error = array( 'customer-product' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
|
142
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
143
|
|
|
$this->logException( $e ); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $this->render( $view ); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Saves the data |
|
152
|
|
|
*/ |
|
153
|
|
|
public function save() |
|
154
|
|
|
{ |
|
155
|
|
|
$view = $this->getView(); |
|
156
|
|
|
$context = $this->getContext(); |
|
157
|
|
|
|
|
158
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
159
|
|
|
|
|
160
|
|
|
$manager->begin(); |
|
161
|
|
|
|
|
162
|
|
|
try |
|
163
|
|
|
{ |
|
164
|
|
|
$this->storeSearchParams( $view->param( 'up', [] ), 'customerproduct' ); |
|
165
|
|
|
$this->fromArray( $view->item, $view->param( 'product', [] ) ); |
|
166
|
|
|
$view->productBody = ''; |
|
167
|
|
|
|
|
168
|
|
|
foreach( $this->getSubClients() as $client ) { |
|
169
|
|
|
$view->productBody .= $client->save(); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$manager->commit(); |
|
173
|
|
|
return; |
|
174
|
|
|
} |
|
175
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
176
|
|
|
{ |
|
177
|
|
|
$error = array( 'customer-item-media' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
|
178
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
179
|
|
|
$this->logException( $e ); |
|
180
|
|
|
} |
|
181
|
|
|
catch( \Exception $e ) |
|
182
|
|
|
{ |
|
183
|
|
|
$error = array( 'customer-item-media' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
|
184
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
|
185
|
|
|
$this->logException( $e ); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
$manager->rollback(); |
|
189
|
|
|
|
|
190
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Returns the sub-client given by its name. |
|
196
|
|
|
* |
|
197
|
|
|
* @param string $type Name of the client type |
|
198
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
|
199
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getSubClient( $type, $name = null ) |
|
202
|
|
|
{ |
|
203
|
|
|
/** admin/jqadm/customer/product/decorators/excludes |
|
204
|
|
|
* Excludes decorators added by the "common" option from the customer JQAdm client |
|
205
|
|
|
* |
|
206
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
207
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
208
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
209
|
|
|
* modify what is returned to the caller. |
|
210
|
|
|
* |
|
211
|
|
|
* This option allows you to remove a decorator added via |
|
212
|
|
|
* "admin/jqadm/common/decorators/default" before they are wrapped |
|
213
|
|
|
* around the JQAdm client. |
|
214
|
|
|
* |
|
215
|
|
|
* admin/jqadm/customer/product/decorators/excludes = array( 'decorator1' ) |
|
216
|
|
|
* |
|
217
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
218
|
|
|
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via |
|
219
|
|
|
* "admin/jqadm/common/decorators/default" to the JQAdm client. |
|
220
|
|
|
* |
|
221
|
|
|
* @param array List of decorator names |
|
222
|
|
|
* @since 2017.07 |
|
223
|
|
|
* @category Developer |
|
224
|
|
|
* @see admin/jqadm/common/decorators/default |
|
225
|
|
|
* @see admin/jqadm/customer/product/decorators/global |
|
226
|
|
|
* @see admin/jqadm/customer/product/decorators/local |
|
227
|
|
|
*/ |
|
228
|
|
|
|
|
229
|
|
|
/** admin/jqadm/customer/product/decorators/global |
|
230
|
|
|
* Adds a list of globally available decorators only to the customer JQAdm client |
|
231
|
|
|
* |
|
232
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
233
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
234
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
235
|
|
|
* modify what is returned to the caller. |
|
236
|
|
|
* |
|
237
|
|
|
* This option allows you to wrap global decorators |
|
238
|
|
|
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. |
|
239
|
|
|
* |
|
240
|
|
|
* admin/jqadm/customer/product/decorators/global = array( 'decorator1' ) |
|
241
|
|
|
* |
|
242
|
|
|
* This would add the decorator named "decorator1" defined by |
|
243
|
|
|
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. |
|
244
|
|
|
* |
|
245
|
|
|
* @param array List of decorator names |
|
246
|
|
|
* @since 2017.07 |
|
247
|
|
|
* @category Developer |
|
248
|
|
|
* @see admin/jqadm/common/decorators/default |
|
249
|
|
|
* @see admin/jqadm/customer/product/decorators/excludes |
|
250
|
|
|
* @see admin/jqadm/customer/product/decorators/local |
|
251
|
|
|
*/ |
|
252
|
|
|
|
|
253
|
|
|
/** admin/jqadm/customer/product/decorators/local |
|
254
|
|
|
* Adds a list of local decorators only to the customer JQAdm client |
|
255
|
|
|
* |
|
256
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
257
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
258
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
259
|
|
|
* modify what is returned to the caller. |
|
260
|
|
|
* |
|
261
|
|
|
* This option allows you to wrap local decorators |
|
262
|
|
|
* ("\Aimeos\Admin\JQAdm\Customer\Decorator\*") around the JQAdm client. |
|
263
|
|
|
* |
|
264
|
|
|
* admin/jqadm/customer/product/decorators/local = array( 'decorator2' ) |
|
265
|
|
|
* |
|
266
|
|
|
* This would add the decorator named "decorator2" defined by |
|
267
|
|
|
* "\Aimeos\Admin\JQAdm\Customer\Decorator\Decorator2" only to the JQAdm client. |
|
268
|
|
|
* |
|
269
|
|
|
* @param array List of decorator names |
|
270
|
|
|
* @since 2017.07 |
|
271
|
|
|
* @category Developer |
|
272
|
|
|
* @see admin/jqadm/common/decorators/default |
|
273
|
|
|
* @see admin/jqadm/customer/product/decorators/excludes |
|
274
|
|
|
* @see admin/jqadm/customer/product/decorators/global |
|
275
|
|
|
*/ |
|
276
|
|
|
return $this->createSubClient( 'customer/product/' . $type, $name ); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Returns the customer list items referencing the products |
|
282
|
|
|
* |
|
283
|
|
|
* @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
|
284
|
|
|
* @param array $params Associative list of GET/POST parameters |
|
285
|
|
|
* @param integer $total Value/result parameter that will contain the item total afterwards |
|
286
|
|
|
* @return \Aimeos\MShop\Common\Item\List\Iface[] Customer list items referencing the products |
|
287
|
|
|
*/ |
|
288
|
|
|
protected function getListItems( \Aimeos\MShop\Customer\Item\Iface $item, array $params = [], &$total ) |
|
289
|
|
|
{ |
|
290
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/lists' ); |
|
291
|
|
|
|
|
292
|
|
|
$search = $manager->createSearch(); |
|
293
|
|
|
$search->setSortations( [$search->sort( '-', 'customer.lists.ctime' )] ); |
|
294
|
|
|
|
|
295
|
|
|
$search = $this->initCriteria( $search, $params ); |
|
296
|
|
|
$expr = [ |
|
297
|
|
|
$search->getConditions(), |
|
298
|
|
|
$search->compare( '==', 'customer.lists.parentid', $item->getId() ), |
|
299
|
|
|
$search->compare( '==', 'customer.lists.domain', 'product' ), |
|
300
|
|
|
]; |
|
301
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
|
302
|
|
|
|
|
303
|
|
|
return $manager->searchItems( $search, [], $total ); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Returns the available product list types |
|
309
|
|
|
* |
|
310
|
|
|
* @return \Aimeos\MShop\Common\Item\Type\Iface[] Associative list of type IDs as keys and type codes as values |
|
311
|
|
|
*/ |
|
312
|
|
|
protected function getListTypes() |
|
313
|
|
|
{ |
|
314
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/lists/type' ); |
|
315
|
|
|
|
|
316
|
|
|
$search = $manager->createSearch( true )->setSlice( 0, 10000 ); |
|
317
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.type.domain', 'product' ) ); |
|
318
|
|
|
$search->setSortations( [$search->sort( '+', 'customer.lists.type.position' )] ); |
|
319
|
|
|
|
|
320
|
|
|
return $this->map( $manager->searchItems( $search ) ); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* Returns the product items referenced by the given list items |
|
326
|
|
|
* |
|
327
|
|
|
* @param \Aimeos\MShop\Common\Item\List\Iface[] $listItems Customer list items referencing the products |
|
328
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface[] Associative list of product IDs as keys and items as values |
|
329
|
|
|
*/ |
|
330
|
|
|
protected function getProductItems( array $listItems ) |
|
331
|
|
|
{ |
|
332
|
|
|
$list = []; |
|
333
|
|
|
|
|
334
|
|
|
foreach( $listItems as $listItem ) { |
|
335
|
|
|
$list[] = $listItem->getRefId(); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'product' ); |
|
339
|
|
|
|
|
340
|
|
|
$search = $manager->createSearch()->setSlice( 0, count( $list ) ); |
|
341
|
|
|
$search->setConditions( $search->compare( '==', 'product.id', $list ) ); |
|
342
|
|
|
|
|
343
|
|
|
return $manager->searchItems( $search ); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* Returns the list of sub-client names configured for the client. |
|
349
|
|
|
* |
|
350
|
|
|
* @return array List of JQAdm client names |
|
351
|
|
|
*/ |
|
352
|
|
|
protected function getSubClientNames() |
|
353
|
|
|
{ |
|
354
|
|
|
/** admin/jqadm/customer/product/standard/subparts |
|
355
|
|
|
* List of JQAdm sub-clients rendered within the customer product section |
|
356
|
|
|
* |
|
357
|
|
|
* The output of the frontend is composed of the code generated by the JQAdm |
|
358
|
|
|
* clients. Each JQAdm client can consist of serveral (or none) sub-clients |
|
359
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
|
360
|
|
|
* sub-clients can contain JQAdm clients themselves and therefore a |
|
361
|
|
|
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates |
|
362
|
|
|
* the output that is placed inside the container of its parent. |
|
363
|
|
|
* |
|
364
|
|
|
* At first, always the JQAdm code generated by the parent is printed, then |
|
365
|
|
|
* the JQAdm code of its sub-clients. The product of the JQAdm sub-clients |
|
366
|
|
|
* determines the product of the output of these sub-clients inside the parent |
|
367
|
|
|
* container. If the configured list of clients is |
|
368
|
|
|
* |
|
369
|
|
|
* array( "subclient1", "subclient2" ) |
|
370
|
|
|
* |
|
371
|
|
|
* you can easily change the product of the output by reproducting the subparts: |
|
372
|
|
|
* |
|
373
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) |
|
374
|
|
|
* |
|
375
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
|
376
|
|
|
* |
|
377
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1" ) |
|
378
|
|
|
* |
|
379
|
|
|
* As the clients only generates structural JQAdm, the layout defined via CSS |
|
380
|
|
|
* should support adding, removing or reproducting content by a fluid like |
|
381
|
|
|
* design. |
|
382
|
|
|
* |
|
383
|
|
|
* @param array List of sub-client names |
|
384
|
|
|
* @since 2017.07 |
|
385
|
|
|
* @category Developer |
|
386
|
|
|
*/ |
|
387
|
|
|
return $this->getContext()->getConfig()->get( 'admin/jqadm/customer/product/standard/subparts', [] ); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Creates new and updates existing items using the data array |
|
393
|
|
|
* |
|
394
|
|
|
* @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object without referenced domain items |
|
395
|
|
|
* @param string[] $data Data array |
|
396
|
|
|
*/ |
|
397
|
|
|
protected function fromArray( \Aimeos\MShop\Customer\Item\Iface $item, array $data ) |
|
398
|
|
|
{ |
|
399
|
|
|
$context = $this->getContext(); |
|
400
|
|
|
$listIds = $this->getValue( $data, 'customer.lists.id', [] ); |
|
401
|
|
|
|
|
402
|
|
|
$listManager = \Aimeos\MShop::create( $context, 'customer/lists' ); |
|
403
|
|
|
|
|
404
|
|
|
$search = $listManager->createSearch()->setSlice( 0, count( $listIds ) ); |
|
|
|
|
|
|
405
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.id', $listIds ) ); |
|
406
|
|
|
|
|
407
|
|
|
$listItems = $listManager->searchItems( $search ); |
|
408
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
foreach( (array) $listIds as $idx => $listid ) |
|
411
|
|
|
{ |
|
412
|
|
|
if( isset( $listItems[$listid] ) ) { |
|
413
|
|
|
$litem = $listItems[$listid]; |
|
414
|
|
|
} else { |
|
415
|
|
|
$litem = $listManager->createItem(); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
$litem->setParentId( $item->getId() ); |
|
|
|
|
|
|
419
|
|
|
$litem->setDomain( 'product' ); |
|
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
if( isset( $data['customer.lists.refid'][$idx] ) ) { |
|
422
|
|
|
$litem->setRefId( $this->getValue( $data, 'customer.lists.refid/' . $idx ) ); |
|
|
|
|
|
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
if( isset( $data['customer.lists.status'][$idx] ) ) { |
|
426
|
|
|
$litem->setStatus( $this->getValue( $data, 'customer.lists.status/' . $idx ) ); |
|
|
|
|
|
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
if( isset( $data['customer.lists.type'][$idx] ) ) { |
|
430
|
|
|
$litem->setType( $this->getValue( $data, 'customer.lists.type/' . $idx ) ); |
|
|
|
|
|
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
if( isset( $data['customer.lists.position'][$idx] ) ) { |
|
434
|
|
|
$litem->setPosition( $this->getValue( $data, 'customer.lists.position/' . $idx ) ); |
|
|
|
|
|
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
if( isset( $data['customer.lists.datestart'][$idx] ) ) { |
|
438
|
|
|
$litem->setDateStart( $this->getValue( $data, 'customer.lists.datestart/' . $idx ) ); |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
if( isset( $data['customer.lists.dateend'][$idx] ) ) { |
|
442
|
|
|
$litem->setDateEnd( $this->getValue( $data, 'customer.lists.dateend/' . $idx ) ); |
|
|
|
|
|
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
if( isset( $data['customer.lists.config'][$idx] ) |
|
446
|
|
|
&& ( $conf = json_decode( $this->getValue( $data, 'customer.lists.config/' . $idx ), true ) ) !== null |
|
|
|
|
|
|
447
|
|
|
) { |
|
448
|
|
|
$litem->setConfig( $conf ); |
|
|
|
|
|
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
if( $litem->getId() === null && isset( $data['config'][$idx]['key'] ) ) |
|
452
|
|
|
{ |
|
453
|
|
|
$conf = []; |
|
454
|
|
|
|
|
455
|
|
|
foreach( (array) $data['config'][$idx]['key'] as $pos => $key ) |
|
456
|
|
|
{ |
|
457
|
|
|
if( trim( $key ) !== '' && isset( $data['config'][$idx]['val'][$pos] ) ) { |
|
458
|
|
|
$conf[$key] = $data['config'][$idx]['val'][$pos]; |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
$litem->setConfig( $conf ); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
$listManager->saveItem( $litem, false ); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Constructs the data array for the view from the given item |
|
472
|
|
|
* |
|
473
|
|
|
* @param \Aimeos\MShop\Common\Item\Lists\Iface[] $listItems Customer list items referencing the products |
|
474
|
|
|
* @return string[] Multi-dimensional associative list of item data |
|
475
|
|
|
*/ |
|
476
|
|
|
protected function toArray( array $listItems ) |
|
477
|
|
|
{ |
|
478
|
|
|
$data = []; |
|
479
|
|
|
|
|
480
|
|
|
foreach( $listItems as $listItem ) |
|
481
|
|
|
{ |
|
482
|
|
|
foreach( $listItem->toArray( true ) as $key => $value ) { |
|
483
|
|
|
$data[$key][] = $value; |
|
484
|
|
|
} |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
return $data; |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* Returns the rendered template including the view data |
|
493
|
|
|
* |
|
494
|
|
|
* @param \Aimeos\MW\View\Iface $view View object with data assigned |
|
495
|
|
|
* @return string HTML output |
|
496
|
|
|
*/ |
|
497
|
|
|
protected function render( \Aimeos\MW\View\Iface $view ) |
|
498
|
|
|
{ |
|
499
|
|
|
/** admin/jqadm/customer/product/template-item |
|
500
|
|
|
* Relative path to the HTML body template of the product subpart for customers. |
|
501
|
|
|
* |
|
502
|
|
|
* The template file contains the HTML code and processing instructions |
|
503
|
|
|
* to generate the result shown in the body of the frontend. The |
|
504
|
|
|
* configuration string is the path to the template file relative |
|
505
|
|
|
* to the templates directory (usually in admin/jqadm/templates). |
|
506
|
|
|
* |
|
507
|
|
|
* You can overwrite the template file configuration in extensions and |
|
508
|
|
|
* provide alternative templates. These alternative templates should be |
|
509
|
|
|
* named like the default one but with the string "default" replaced by |
|
510
|
|
|
* an unique name. You may use the name of your project for this. If |
|
511
|
|
|
* you've implemented an alternative client class as well, "default" |
|
512
|
|
|
* should be replaced by the name of the new class. |
|
513
|
|
|
* |
|
514
|
|
|
* @param string Relative path to the template creating the HTML code |
|
515
|
|
|
* @since 2016.04 |
|
516
|
|
|
* @category Developer |
|
517
|
|
|
*/ |
|
518
|
|
|
$tplconf = 'admin/jqadm/customer/product/template-item'; |
|
519
|
|
|
$default = 'customer/item-product-standard'; |
|
520
|
|
|
|
|
521
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
|
522
|
|
|
} |
|
523
|
|
|
} |
|
524
|
|
|
|