Passed
Branch master (d032f7)
by Aimeos
05:30
created

Standard   A

Complexity

Total Complexity 42

Size/Duplication

Total Lines 500
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 143
dl 0
loc 500
rs 9.0399
c 0
b 0
f 0
wmc 42

12 Methods

Rating   Name   Duplication   Size   Complexity  
F fromArray() 0 69 16
A copy() 0 27 4
A render() 0 25 1
A save() 0 38 4
A getListTypes() 0 9 1
A create() 0 27 4
A getSubClient() 0 76 1
A getListItems() 0 16 1
A get() 0 34 4
A toArray() 0 12 3
A getSubClientNames() 0 36 1
A getProductItems() 0 14 2

How to fix   Complexity   

Complex Class

Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.

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 ) );
0 ignored issues
show
Bug introduced by
It seems like $listIds can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

404
		$search = $listManager->createSearch()->setSlice( 0, count( /** @scrutinizer ignore-type */ $listIds ) );
Loading history...
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() );
0 ignored issues
show
Bug introduced by
The method setParentId() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Common\Item\Property\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Common\Item\Address\Standard or Aimeos\MShop\Order\Item\Status\Standard or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Common\Item\Address\Standard or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Common\Item\Address\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

418
			$litem->/** @scrutinizer ignore-call */ 
419
           setParentId( $item->getId() );
Loading history...
419
			$litem->setDomain( 'product' );
0 ignored issues
show
Bug introduced by
The method setDomain() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Tag\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

419
			$litem->/** @scrutinizer ignore-call */ 
420
           setDomain( 'product' );
Loading history...
420
421
			if( isset( $data['customer.lists.refid'][$idx] ) ) {
422
				$litem->setRefId( $this->getValue( $data, 'customer.lists.refid/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setRefId() does not exist on Aimeos\MShop\Common\Item\Iface. Did you maybe mean setId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

422
				$litem->/** @scrutinizer ignore-call */ 
423
            setRefId( $this->getValue( $data, 'customer.lists.refid/' . $idx ) );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
423
			}
424
425
			if( isset( $data['customer.lists.status'][$idx] ) ) {
426
				$litem->setStatus( $this->getValue( $data, 'customer.lists.status/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setStatus() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Common\Item\Status\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Base\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MAdmin\Job\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Subscription\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Locale\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

426
				$litem->/** @scrutinizer ignore-call */ 
427
            setStatus( $this->getValue( $data, 'customer.lists.status/' . $idx ) );
Loading history...
427
			}
428
429
			if( isset( $data['customer.lists.type'][$idx] ) ) {
430
				$litem->setType( $this->getValue( $data, 'customer.lists.type/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setType() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Order\Item\Base\Service\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Common\Item\Property\Standard or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Tag\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Stock\Item\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Order\Item\Base\Service\Base or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Order\Item\Base\Address\Standard or Aimeos\MShop\Order\Item\Standard or Aimeos\MShop\Order\Item\Status\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Base\Address\Iface or Aimeos\MShop\Order\Item\Base\Address\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

430
				$litem->/** @scrutinizer ignore-call */ 
431
            setType( $this->getValue( $data, 'customer.lists.type/' . $idx ) );
Loading history...
431
			}
432
433
			if( isset( $data['customer.lists.position'][$idx] ) ) {
434
				$litem->setPosition( $this->getValue( $data, 'customer.lists.position/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setPosition() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Locale\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Common\Item\Address\Standard or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Common\Item\Address\Standard or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Common\Item\Address\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

434
				$litem->/** @scrutinizer ignore-call */ 
435
            setPosition( $this->getValue( $data, 'customer.lists.position/' . $idx ) );
Loading history...
435
			}
436
437
			if( isset( $data['customer.lists.datestart'][$idx] ) ) {
438
				$litem->setDateStart( $this->getValue( $data, 'customer.lists.datestart/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setDateStart() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Product\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

438
				$litem->/** @scrutinizer ignore-call */ 
439
            setDateStart( $this->getValue( $data, 'customer.lists.datestart/' . $idx ) );
Loading history...
439
			}
440
441
			if( isset( $data['customer.lists.dateend'][$idx] ) ) {
442
				$litem->setDateEnd( $this->getValue( $data, 'customer.lists.dateend/' . $idx ) );
0 ignored issues
show
Bug introduced by
The method setDateEnd() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Subscription\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Product\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

442
				$litem->/** @scrutinizer ignore-call */ 
443
            setDateEnd( $this->getValue( $data, 'customer.lists.dateend/' . $idx ) );
Loading history...
443
			}
444
445
			if( isset( $data['customer.lists.config'][$idx] )
446
				&& ( $conf = json_decode( $this->getValue( $data, 'customer.lists.config/' . $idx ), true ) ) !== null
0 ignored issues
show
Bug introduced by
It seems like $this->getValue($data, '....lists.config/' . $idx) can also be of type string[]; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

446
				&& ( $conf = json_decode( /** @scrutinizer ignore-type */ $this->getValue( $data, 'customer.lists.config/' . $idx ), true ) ) !== null
Loading history...
447
			) {
448
				$litem->setConfig( $conf );
0 ignored issues
show
Bug introduced by
The method setConfig() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

448
				$litem->/** @scrutinizer ignore-call */ 
449
            setConfig( $conf );
Loading history...
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