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

Standard::create()   B

Complexity

Conditions 6
Paths 38

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 38
nop 0
dl 0
loc 41
rs 8.9137
c 0
b 0
f 0
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\Catalog;
12
13
sprintf( 'catalog' ); // for translation
14
15
16
/**
17
 * Default implementation of catalog 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
	/**
27
	 * Copies a resource
28
	 *
29
	 * @return string HTML output
30
	 */
31
	public function copy()
32
	{
33
		$view = $this->getView();
34
		$context = $this->getContext();
35
36
		try
37
		{
38
			if( ( $id = $view->param( 'id' ) ) === null ) {
39
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
40
			}
41
42
			$manager = \Aimeos\MShop::create( $context, 'catalog' );
43
			$view->item = $manager->getItem( $id, $this->getDomains() );
44
45
			$view->itemData = $this->toArray( $view->item, true );
46
			$view->itemSubparts = $this->getSubClientNames();
47
			$view->itemRootId = $this->getRootId();
48
			$view->itemBody = '';
49
50
			foreach( $this->getSubClients() as $idx => $client )
51
			{
52
				$view->tabindex = ++$idx + 1;
53
				$view->itemBody .= $client->copy();
54
			}
55
		}
56
		catch( \Aimeos\MShop\Exception $e )
57
		{
58
			$error = array( 'catalog-item' => $context->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( 'catalog-item' => $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
		$context = $this->getContext();
82
83
		try
84
		{
85
			$data = $view->param( 'item', [] );
86
87
			if( !isset( $view->item ) ) {
88
				$view->item = \Aimeos\MShop::create( $context, 'catalog' )->createItem();
89
			}
90
91
			$data['catalog.siteid'] = $view->item->getSiteId();
92
			$data['catalog.parentid'] = $view->item->getParentId() ?: $view->param( 'item/catalog.parentid' );
93
94
			$view->itemSubparts = $this->getSubClientNames();
95
			$view->itemRootId = $this->getRootId();
96
			$view->itemData = $data;
97
			$view->itemBody = '';
98
99
			foreach( $this->getSubClients() as $idx => $client )
100
			{
101
				$view->tabindex = ++$idx + 1;
102
				$view->itemBody .= $client->create();
103
			}
104
		}
105
		catch( \Aimeos\MShop\Exception $e )
106
		{
107
			$error = array( 'catalog-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
108
			$view->errors = $view->get( 'errors', [] ) + $error;
109
			$this->logException( $e );
110
		}
111
		catch( \Exception $e )
112
		{
113
			$error = array( 'catalog-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
114
			$view->errors = $view->get( 'errors', [] ) + $error;
115
			$this->logException( $e );
116
		}
117
118
		return $this->render( $view );
119
	}
120
121
122
	/**
123
	 * Deletes a resource
124
	 *
125
	 * @return string|null HTML output
126
	 */
127
	public function delete()
128
	{
129
		$view = $this->getView();
130
		$context = $this->getContext();
131
132
		$manager = \Aimeos\MShop::create( $context, 'catalog' );
133
		$manager->begin();
134
135
		try
136
		{
137
			if( ( $id = $view->param( 'id' ) ) === null ) {
138
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
139
			}
140
141
			$view->item = $manager->getItem( $id, $this->getDomains() );
142
143
			foreach( $this->getSubClients() as $client ) {
144
				$client->delete();
145
			}
146
147
			$manager->saveItem( $view->item );
148
			$manager->deleteItem( $id );
149
			$manager->commit();
150
151
			$this->nextAction( $view, 'search', 'catalog', null, 'delete' );
152
			return;
153
		}
154
		catch( \Aimeos\MShop\Exception $e )
155
		{
156
			$error = array( 'catalog-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
157
			$view->errors = $view->get( 'errors', [] ) + $error;
158
			$this->logException( $e );
159
		}
160
		catch( \Exception $e )
161
		{
162
			$error = array( 'catalog-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
163
			$view->errors = $view->get( 'errors', [] ) + $error;
164
			$this->logException( $e );
165
		}
166
167
		$manager->rollback();
168
169
		return $this->search();
170
	}
171
172
173
	/**
174
	 * Returns a single resource
175
	 *
176
	 * @return string HTML output
177
	 */
178
	public function get()
179
	{
180
		$view = $this->getView();
181
		$context = $this->getContext();
182
183
		try
184
		{
185
			if( ( $id = $view->param( 'id' ) ) === null ) {
186
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
187
			}
188
189
			$manager = \Aimeos\MShop::create( $context, 'catalog' );
190
191
			$view->item = $manager->getItem( $id, $this->getDomains() );
192
			$view->itemSubparts = $this->getSubClientNames();
193
			$view->itemData = $this->toArray( $view->item );
194
			$view->itemRootId = $this->getRootId();
195
			$view->itemBody = '';
196
197
			foreach( $this->getSubClients() as $idx => $client )
198
			{
199
				$view->tabindex = ++$idx + 1;
200
				$view->itemBody .= $client->get();
201
			}
202
		}
203
		catch( \Aimeos\MShop\Exception $e )
204
		{
205
			$error = array( 'catalog-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
206
			$view->errors = $view->get( 'errors', [] ) + $error;
207
			$this->logException( $e );
208
		}
209
		catch( \Exception $e )
210
		{
211
			$error = array( 'catalog-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
212
			$view->errors = $view->get( 'errors', [] ) + $error;
213
			$this->logException( $e );
214
		}
215
216
		return $this->render( $view );
217
	}
218
219
220
	/**
221
	 * Saves the data
222
	 *
223
	 * @return string HTML output
224
	 */
225
	public function save()
226
	{
227
		$view = $this->getView();
228
		$context = $this->getContext();
229
230
		$manager = \Aimeos\MShop::create( $context, 'catalog' );
231
		$manager->begin();
232
233
		try
234
		{
235
			$item = $this->fromArray( $view->param( 'item', [] ) );
236
			$view->item = $item->getId() ? $item : $manager->saveItem( $item );
237
			$view->itemBody = '';
238
239
			foreach( $this->getSubClients() as $client ) {
240
				$view->itemBody .= $client->save();
241
			}
242
243
			$manager->saveItem( clone $view->item );
244
			$manager->commit();
245
246
			$this->nextAction( $view, $view->param( 'next' ), 'catalog', $view->item->getId(), 'save' );
247
			return;
248
		}
249
		catch( \Aimeos\Admin\JQAdm\Exception $e )
250
		{
251
			// fall through to create
252
		}
253
		catch( \Aimeos\MShop\Exception $e )
254
		{
255
			$error = array( 'catalog-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
256
			$view->errors = $view->get( 'errors', [] ) + $error;
257
			$this->logException( $e );
258
		}
259
		catch( \Exception $e )
260
		{
261
			$error = array( 'catalog-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
262
			$view->errors = $view->get( 'errors', [] ) + $error;
263
			$this->logException( $e );
264
		}
265
266
		$manager->rollback();
267
268
		return $this->create();
269
	}
270
271
272
	/**
273
	 * Returns the catalog root node
274
	 *
275
	 * @return string HTML output
276
	 */
277
	public function search()
278
	{
279
		$view = $this->getView();
280
		$context = $this->getContext();
281
282
		try
283
		{
284
			$view->item = \Aimeos\MShop::create( $context, 'catalog' )->createItem();
285
			$view->itemRootId = $this->getRootId();
286
			$view->itemBody = '';
287
		}
288
		catch( \Aimeos\MShop\Exception $e )
289
		{
290
			$error = array( 'catalog-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
291
			$view->errors = $view->get( 'errors', [] ) + $error;
292
			$this->logException( $e );
293
		}
294
		catch( \Exception $e )
295
		{
296
			$error = array( 'catalog-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
297
			$view->errors = $view->get( 'errors', [] ) + $error;
298
			$this->logException( $e );
299
		}
300
301
		return $this->render( $view );
302
	}
303
304
305
	/**
306
	 * Returns the sub-client given by its name.
307
	 *
308
	 * @param string $type Name of the client type
309
	 * @param string|null $name Name of the sub-client (Default if null)
310
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
311
	 */
312
	public function getSubClient( $type, $name = null )
313
	{
314
		/** admin/jqadm/catalog/decorators/excludes
315
		 * Excludes decorators added by the "common" option from the catalog JQAdm client
316
		 *
317
		 * Decorators extend the functionality of a class by adding new aspects
318
		 * (e.g. log what is currently done), executing the methods of the underlying
319
		 * class only in certain conditions (e.g. only for logged in users) or
320
		 * modify what is returned to the caller.
321
		 *
322
		 * This option allows you to remove a decorator added via
323
		 * "client/jqadm/common/decorators/default" before they are wrapped
324
		 * around the JQAdm client.
325
		 *
326
		 *  admin/jqadm/catalog/decorators/excludes = array( 'decorator1' )
327
		 *
328
		 * This would remove the decorator named "decorator1" from the list of
329
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
330
		 * "client/jqadm/common/decorators/default" to the JQAdm client.
331
		 *
332
		 * @param array List of decorator names
333
		 * @since 2016.01
334
		 * @category Developer
335
		 * @see admin/jqadm/common/decorators/default
336
		 * @see admin/jqadm/catalog/decorators/global
337
		 * @see admin/jqadm/catalog/decorators/local
338
		 */
339
340
		/** admin/jqadm/catalog/decorators/global
341
		 * Adds a list of globally available decorators only to the catalog JQAdm client
342
		 *
343
		 * Decorators extend the functionality of a class by adding new aspects
344
		 * (e.g. log what is currently done), executing the methods of the underlying
345
		 * class only in certain conditions (e.g. only for logged in users) or
346
		 * modify what is returned to the caller.
347
		 *
348
		 * This option allows you to wrap global decorators
349
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
350
		 *
351
		 *  admin/jqadm/catalog/decorators/global = array( 'decorator1' )
352
		 *
353
		 * This would add the decorator named "decorator1" defined by
354
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
355
		 *
356
		 * @param array List of decorator names
357
		 * @since 2016.01
358
		 * @category Developer
359
		 * @see admin/jqadm/common/decorators/default
360
		 * @see admin/jqadm/catalog/decorators/excludes
361
		 * @see admin/jqadm/catalog/decorators/local
362
		 */
363
364
		/** admin/jqadm/catalog/decorators/local
365
		 * Adds a list of local decorators only to the catalog JQAdm client
366
		 *
367
		 * Decorators extend the functionality of a class by adding new aspects
368
		 * (e.g. log what is currently done), executing the methods of the underlying
369
		 * class only in certain conditions (e.g. only for logged in users) or
370
		 * modify what is returned to the caller.
371
		 *
372
		 * This option allows you to wrap local decorators
373
		 * ("\Aimeos\Admin\JQAdm\Catalog\Decorator\*") around the JQAdm client.
374
		 *
375
		 *  admin/jqadm/catalog/decorators/local = array( 'decorator2' )
376
		 *
377
		 * This would add the decorator named "decorator2" defined by
378
		 * "\Aimeos\Admin\JQAdm\Catalog\Decorator\Decorator2" only to the JQAdm client.
379
		 *
380
		 * @param array List of decorator names
381
		 * @since 2016.01
382
		 * @category Developer
383
		 * @see admin/jqadm/common/decorators/default
384
		 * @see admin/jqadm/catalog/decorators/excludes
385
		 * @see admin/jqadm/catalog/decorators/global
386
		 */
387
		return $this->createSubClient( 'catalog/' . $type, $name );
388
	}
389
390
391
	/**
392
	 * Returns the domain names whose items should be fetched too
393
	 *
394
	 * @return string[] List of domain names
395
	 */
396
	protected function getDomains()
397
	{
398
		/** admin/jqadm/catalog/domains
399
		 * List of domain items that should be fetched along with the catalog
400
		 *
401
		 * If you need to display additional content, you can configure your own
402
		 * list of domains (attribute, media, price, catalog, text, etc. are
403
		 * domains) whose items are fetched from the storage.
404
		 *
405
		 * @param array List of domain names
406
		 * @since 2016.01
407
		 * @category Developer
408
		 */
409
		$domains = array( 'media', 'text' );
410
411
		return $this->getContext()->getConfig()->get( 'admin/jqadm/catalog/domains', $domains );
412
	}
413
414
415
	/**
416
	 * Returns the IDs of the root category
417
	 *
418
	 * @return string|null ID of the root category
419
	 */
420
	protected function getRootId()
421
	{
422
		$manager = \Aimeos\MShop::create( $this->getContext(), 'catalog' );
423
424
		try {
425
			return $manager->getTree( null, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE )->getId();
1 ignored issue
show
Bug introduced by
The method getTree() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

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

425
			return $manager->/** @scrutinizer ignore-call */ getTree( null, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE )->getId();
Loading history...
426
		} catch( \Exception $e ) {
427
			return null;
428
		}
429
	}
430
431
432
	/**
433
	 * Returns the list of sub-client names configured for the client.
434
	 *
435
	 * @return array List of JQAdm client names
436
	 */
437
	protected function getSubClientNames()
438
	{
439
		/** admin/jqadm/catalog/standard/subparts
440
		 * List of JQAdm sub-clients rendered within the catalog section
441
		 *
442
		 * The output of the frontend is composed of the code generated by the JQAdm
443
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
444
		 * that are responsible for rendering certain sub-parts of the output. The
445
		 * sub-clients can contain JQAdm clients themselves and therefore a
446
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
447
		 * the output that is placed inside the container of its parent.
448
		 *
449
		 * At first, always the JQAdm code generated by the parent is printed, then
450
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
451
		 * determines the order of the output of these sub-clients inside the parent
452
		 * container. If the configured list of clients is
453
		 *
454
		 *  array( "subclient1", "subclient2" )
455
		 *
456
		 * you can easily change the order of the output by reordering the subparts:
457
		 *
458
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
459
		 *
460
		 * You can also remove one or more parts if they shouldn't be rendered:
461
		 *
462
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
463
		 *
464
		 * As the clients only generates structural JQAdm, the layout defined via CSS
465
		 * should support adding, removing or reordering content by a fluid like
466
		 * design.
467
		 *
468
		 * @param array List of sub-client names
469
		 * @since 2016.01
470
		 * @category Developer
471
		 */
472
		return $this->getContext()->getConfig()->get( 'admin/jqadm/catalog/standard/subparts', [] );
473
	}
474
475
476
	/**
477
	 * Creates new and updates existing items using the data array
478
	 *
479
	 * @param string[] Data array
0 ignored issues
show
Bug introduced by
The type Aimeos\Admin\JQAdm\Catalog\Data was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
480
	 * @return \Aimeos\MShop\Catalog\Item\Iface New catalog item object
481
	 */
482
	protected function fromArray( array $data )
483
	{
484
		$conf = [];
485
486
		if( isset( $data['config']['key'] ) )
487
		{
488
			foreach( (array) $data['config']['key'] as $idx => $key )
489
			{
490
				if( trim( $key ) !== '' && isset( $data['config']['val'][$idx] ) ) {
491
					$conf[$key] = $data['config']['val'][$idx];
492
				}
493
			}
494
		}
495
496
		$manager = \Aimeos\MShop::create( $this->getContext(), 'catalog' );
497
498
		if( isset( $data['catalog.id'] ) && $data['catalog.id'] != '' ) {
499
			$item = $manager->getItem( $data['catalog.id'], $this->getDomains() );
500
		} else {
501
			$item = $manager->createItem();
502
		}
503
504
		$item->fromArray( $data );
505
		$item->setConfig( $conf );
0 ignored issues
show
Bug introduced by
The method setConfig() does not exist on 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

505
		$item->/** @scrutinizer ignore-call */ 
506
         setConfig( $conf );

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...
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

505
		$item->/** @scrutinizer ignore-call */ 
506
         setConfig( $conf );
Loading history...
506
507
		if( $item->getId() == null ) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $item->getId() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
508
			return $manager->insertItem( $item, $data['catalog.parentid'] ?: null );
1 ignored issue
show
Bug introduced by
The method insertItem() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

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

508
			return $manager->/** @scrutinizer ignore-call */ insertItem( $item, $data['catalog.parentid'] ?: null );
Loading history...
509
		}
510
511
		return $item;
512
	}
513
514
515
	/**
516
	 * Constructs the data array for the view from the given item
517
	 *
518
	 * @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item object
519
	 * @return string[] Multi-dimensional associative list of item data
520
	 */
521
	protected function toArray( \Aimeos\MShop\Catalog\Item\Iface $item, $copy = false )
522
	{
523
		$data = $item->toArray( true );
524
		$data['config'] = [];
525
526
		if( $copy === true )
527
		{
528
			$data['catalog.id'] = '';
529
			$data['catalog.siteid'] = $item->getSiteId();
530
			$data['catalog.code'] = $data['catalog.code'] . '_copy';
531
		}
532
533
		foreach( $item->getConfig() as $key => $value )
534
		{
535
			$data['config']['key'][] = $key;
536
			$data['config']['val'][] = $value;
537
		}
538
539
		return $data;
540
	}
541
542
543
	/**
544
	 * Returns the rendered template including the view data
545
	 *
546
	 * @param \Aimeos\MW\View\Iface $view View object with data assigned
547
	 * @return string HTML output
548
	 */
549
	protected function render( \Aimeos\MW\View\Iface $view )
550
	{
551
		/** admin/jqadm/catalog/template-item
552
		 * Relative path to the HTML body template for the catalog item.
553
		 *
554
		 * The template file contains the HTML code and processing instructions
555
		 * to generate the result shown in the body of the frontend. The
556
		 * configuration string is the path to the template file relative
557
		 * to the templates directory (usually in admin/jqadm/templates).
558
		 *
559
		 * You can overwrite the template file configuration in extensions and
560
		 * provide alternative templates. These alternative templates should be
561
		 * named like the default one but with the string "default" replaced by
562
		 * an unique name. You may use the name of your project for this. If
563
		 * you've implemented an alternative client class as well, "default"
564
		 * should be replaced by the name of the new class.
565
		 *
566
		 * @param string Relative path to the template creating the HTML code
567
		 * @since 2016.04
568
		 * @category Developer
569
		 */
570
		$tplconf = 'admin/jqadm/catalog/template-item';
571
		$default = 'catalog/item-standard';
572
573
		return $view->render( $view->config( $tplconf, $default ) );
574
	}
575
}
576