Standard::fromArray()   D
last analyzed

Complexity

Conditions 39
Paths 32

Size

Total Lines 46
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
c 0
b 0
f 0
dl 0
loc 46
rs 4.1666
cc 39
nc 32
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 * @package MShop
7
 * @subpackage Order
8
 */
9
10
11
namespace Aimeos\MShop\Order\Item\Product;
12
13
14
/**
15
 * Default order product item implementation.
16
 *
17
 * @package MShop
18
 * @subpackage Order
19
 */
20
class Standard extends Base implements Iface
21
{
22
	use \Aimeos\MShop\Common\Item\TypeRef\Traits;
23
24
25
	/**
26
	 * Clones internal objects of the order product item.
27
	 */
28
	public function __clone()
29
	{
30
		$this->set( '.attributes', map( $this->get( '.attributes', [] ) )->clone() );
31
		$this->set( '.products', map( $this->get( '.products', [] ) )->clone() );
32
		$this->set( '.price', clone $this->get( '.price' ) );
33
34
		parent::__clone();
35
	}
36
37
38
	/**
39
	 * Returns the associated parent product item
40
	 *
41
	 * @return \Aimeos\MShop\Product\Item\Iface|null Product item
42
	 */
43
	public function getParentProductItem() : ?\Aimeos\MShop\Product\Item\Iface
44
	{
45
		return $this->get( '.parentproduct' );
46
	}
47
48
49
	/**
50
	 * Returns the associated product item
51
	 *
52
	 * @return \Aimeos\MShop\Product\Item\Iface|null Product item
53
	 */
54
	public function getProductItem() : ?\Aimeos\MShop\Product\Item\Iface
55
	{
56
		return $this->get( '.product' );
57
	}
58
59
60
	/**
61
	 * Returns the associated supplier item
62
	 *
63
	 * @return \Aimeos\MShop\Supplier\Item\Iface|null Supplier item
64
	 */
65
	public function getSupplierItem() : ?\Aimeos\MShop\Supplier\Item\Iface
66
	{
67
		return $this->get( '.supplier' );
68
	}
69
70
71
	/**
72
	 * Returns the price item for the product.
73
	 *
74
	 * @return \Aimeos\MShop\Price\Item\Iface Price item with price, costs and rebate
75
	 */
76
	public function getPrice() : \Aimeos\MShop\Price\Item\Iface
77
	{
78
		return $this->get( '.price' );
79
	}
80
81
82
	/**
83
	 * Sets the price item for the product.
84
	 *
85
	 * @param \Aimeos\MShop\Price\Item\Iface $price Price item containing price and additional costs
86
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
87
	 */
88
	public function setPrice( \Aimeos\MShop\Price\Item\Iface $price ) : \Aimeos\MShop\Order\Item\Product\Iface
89
	{
90
		return $this->set( '.price', $price );
91
	}
92
93
94
	/**
95
	 * Returns all of sub-product items
96
	 *
97
	 * @return \Aimeos\Map List of product items implementing \Aimeos\MShop\Order\Item\Product\Iface
98
	 */
99
	public function getProducts() : \Aimeos\Map
100
	{
101
		return $this->get( '.products', map() );
102
	}
103
104
105
	/**
106
	 * Sets all sub-product items
107
	 *
108
	 * @param \Aimeos\MShop\Order\Item\Product\Iface[] $products List of product items
109
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
110
	 */
111
	public function setProducts( iterable $products ) : \Aimeos\MShop\Order\Item\Product\Iface
112
	{
113
		( $products = map( $products ) )->implements( \Aimeos\MShop\Order\Item\Product\Iface::class, true );
114
		return $this->set( '.products', $products );
115
	}
116
117
118
	/**
119
	 * Returns the ID of the site the item is stored
120
	 *
121
	 * @return string Site ID (or null if not available)
122
	 */
123
	public function getSiteId() : string
124
	{
125
		return $this->get( 'order.product.siteid', '' );
126
	}
127
128
129
	/**
130
	 * Sets the site ID of the item.
131
	 *
132
	 * @param string $value Unique site ID of the item
133
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
134
	 */
135
	public function setSiteId( string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
136
	{
137
		return $this->set( 'order.product.siteid', $value );
138
	}
139
140
141
	/**
142
	 * Returns the base ID.
143
	 *
144
	 * @return string|null Base ID
145
	 */
146
	public function getParentId() : ?string
147
	{
148
		return $this->get( 'order.product.parentid' );
149
	}
150
151
152
	/**
153
	 * Sets the base order ID the product belongs to.
154
	 *
155
	 * @param string|null $value New order base ID
156
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
157
	 */
158
	public function setParentId( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
159
	{
160
		return $this->set( 'order.product.parentid', $value );
161
	}
162
163
164
	/**
165
	 * Returns the order address ID the product should be shipped to
166
	 *
167
	 * @return string|null Order address ID
168
	 */
169
	public function getOrderAddressId() : ?string
170
	{
171
		return $this->get( 'order.product.orderaddressid' );
172
	}
173
174
175
	/**
176
	 * Sets the order address ID the product should be shipped to
177
	 *
178
	 * @param string|null $value Order address ID
179
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
180
	 */
181
	public function setOrderAddressId( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
182
	{
183
		return $this->set( 'order.product.orderaddressid', $value );
184
	}
185
186
187
	/**
188
	 * Returns the parent ID of the ordered product if there is one.
189
	 * This ID relates to another product of the same order and provides a relation for e.g. sub-products in bundles.
190
	 *
191
	 * @return string|null Order product ID
192
	 */
193
	public function getOrderProductId() : ?string
194
	{
195
		return $this->get( 'order.product.orderproductid' );
196
	}
197
198
199
	/**
200
	 * Sets the parent ID of the ordered product.
201
	 * This ID relates to another product of the same order and provides a relation for e.g. sub-products in bundles.
202
	 *
203
	 * @param string|null $value Order product ID
204
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
205
	 */
206
	public function setOrderProductId( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
207
	{
208
		return $this->set( 'order.product.orderproductid', $value );
209
	}
210
211
212
	/**
213
	 * Returns the vendor.
214
	 *
215
	 * @return string Vendor name
216
	 */
217
	public function getVendor() : string
218
	{
219
		return $this->get( 'order.product.vendor', '' );
220
	}
221
222
223
	/**
224
	 * Sets the vendor.
225
	 *
226
	 * @param string|null $value Vendor name
227
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
228
	 */
229
	public function setVendor( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
230
	{
231
		return $this->set( 'order.product.vendor', (string) $value );
232
	}
233
234
235
	/**
236
	 * Returns the product ID the customer has selected.
237
	 *
238
	 * @return string Original product ID
239
	 */
240
	public function getProductId() : string
241
	{
242
		return $this->get( 'order.product.productid', '' );
243
	}
244
245
246
	/**
247
	 * Sets the ID of a product the customer has selected.
248
	 *
249
	 * @param string|null $id Product Code ID
250
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
251
	 */
252
	public function setProductId( ?string $id ) : \Aimeos\MShop\Order\Item\Product\Iface
253
	{
254
		return $this->set( 'order.product.productid', (string) $id );
255
	}
256
257
258
	/**
259
	 * Returns the product ID of the parent product.
260
	 *
261
	 * @return string Product ID of the parent product
262
	 */
263
	public function getParentProductId() : string
264
	{
265
		return $this->get( 'order.product.parentproductid', '' );
266
	}
267
268
269
	/**
270
	 * Sets the ID of the parent product the customer has selected.
271
	 *
272
	 * @param string|null $id Product ID of the parent product
273
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
274
	 */
275
	public function setParentProductId( ?string $id ) : \Aimeos\MShop\Order\Item\Product\Iface
276
	{
277
		return $this->set( 'order.product.parentproductid', (string) $id );
278
	}
279
280
281
	/**
282
	 * Returns the product code the customer has selected.
283
	 *
284
	 * @return string Product code
285
	 */
286
	public function getProductCode() : string
287
	{
288
		return $this->get( 'order.product.prodcode', '' );
289
	}
290
291
292
	/**
293
	 * Sets the code of a product the customer has selected.
294
	 *
295
	 * @param string $code Product code
296
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
297
	 */
298
	public function setProductCode( string $code ) : \Aimeos\MShop\Order\Item\Product\Iface
299
	{
300
		return $this->set( 'order.product.prodcode', \Aimeos\Utils::code( $code ) );
301
	}
302
303
304
	/**
305
	 * Returns the code of the stock type the product should be retrieved from.
306
	 *
307
	 * @return string Stock type
308
	 */
309
	public function getStockType() : string
310
	{
311
		return $this->get( 'order.product.stocktype', 'default' );
312
	}
313
314
315
	/**
316
	 * Sets the code of the stock type the product should be retrieved from.
317
	 *
318
	 * @param string|null $code Stock type
319
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
320
	 */
321
	public function setStockType( ?string $code ) : \Aimeos\MShop\Order\Item\Product\Iface
322
	{
323
		return $this->set( 'order.product.stocktype', \Aimeos\Utils::code( (string) $code ) );
324
	}
325
326
327
	/**
328
	 * Returns the localized name of the product.
329
	 *
330
	 * @param string|null $type Type the name is used for, e.g. "url"
331
	 * @return string Returns the localized name of the product
332
	 */
333
	public function getName( ?string $type = null ) : string
334
	{
335
		if( $type === 'url' ) {
336
			return \Aimeos\Base\Str::slug( $this->get( 'order.product.name', '' ) ?: $this->getProductCode() );
337
		}
338
339
		return $this->get( 'order.product.name', '' );
340
	}
341
342
343
	/**
344
	 * Sets the localized name of the product.
345
	 *
346
	 * @param string|null $value Localized name of the product
347
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
348
	 */
349
	public function setName( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
350
	{
351
		return $this->set( 'order.product.name', (string) $value );
352
	}
353
354
355
	/**
356
	 * Returns the localized description of the product.
357
	 *
358
	 * @return string Returns the localized description of the product
359
	 */
360
	public function getDescription() : string
361
	{
362
		return $this->get( 'order.product.description', '' );
363
	}
364
365
366
	/**
367
	 * Sets the localized description of the product.
368
	 *
369
	 * @param string|null $value Localized description of the product
370
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
371
	 */
372
	public function setDescription( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
373
	{
374
		return $this->set( 'order.product.description', (string) $value );
375
	}
376
377
378
	/**
379
	 * Returns the location of the media.
380
	 *
381
	 * @return string Location of the media
382
	 */
383
	public function getMediaUrl() : string
384
	{
385
		return $this->get( 'order.product.mediaurl', '' );
386
	}
387
388
389
	/**
390
	 * Sets the media url of the product the customer has added.
391
	 *
392
	 * @param string|null $value Location of the media/picture
393
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
394
	 */
395
	public function setMediaUrl( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
396
	{
397
		return $this->set( 'order.product.mediaurl', (string) $value );
398
	}
399
400
401
	/**
402
	 * Returns the URL target specific for that product
403
	 *
404
	 * @return string URL target specific for that product
405
	 */
406
	public function getTarget() : string
407
	{
408
		return $this->get( 'order.product.target', '' );
409
	}
410
411
412
	/**
413
	 * Sets the URL target specific for that product
414
	 *
415
	 * @param string|null $value New URL target specific for that product
416
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
417
	 */
418
	public function setTarget( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
419
	{
420
		return $this->set( 'order.product.target', (string) $value );
421
	}
422
423
424
	/**
425
	 * Returns the expected delivery time frame
426
	 *
427
	 * @return string Expected delivery time frame
428
	 */
429
	public function getTimeframe() : string
430
	{
431
		return $this->get( 'order.product.timeframe', '' );
432
	}
433
434
435
	/**
436
	 * Sets the expected delivery time frame
437
	 *
438
	 * @param string|null $timeframe Expected delivery time frame
439
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
440
	 */
441
	public function setTimeframe( ?string $timeframe ) : \Aimeos\MShop\Order\Item\Product\Iface
442
	{
443
		return $this->set( 'order.product.timeframe', (string) $timeframe );
444
	}
445
446
447
	/**
448
	 * Returns the amount of products the customer has added.
449
	 *
450
	 * @return float Amount of products
451
	 */
452
	public function getQuantity() : float
453
	{
454
		return (float) $this->get( 'order.product.quantity', 1 );
455
	}
456
457
458
	/**
459
	 * Sets the amount of products the customer has added.
460
	 *
461
	 * @param float $quantity Amount of products
462
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
463
	 */
464
	public function setQuantity( float $quantity ) : \Aimeos\MShop\Order\Item\Product\Iface
465
	{
466
		if( $quantity <= 0 || $quantity > 2147483647 ) {
467
			throw new \Aimeos\MShop\Order\Exception( sprintf( 'Quantity must be greater than 0 and must not exceed 2147483647' ) );
468
		}
469
470
		return $this->set( 'order.product.quantity', $quantity );
471
	}
472
473
474
	/**
475
	 * Returns the number of packages not yet delivered to the customer.
476
	 *
477
	 * @return float Amount of product packages
478
	 */
479
	public function getQuantityOpen() : float
480
	{
481
		return (float) $this->get( 'order.product.qtyopen', $this->getQuantity() );
482
	}
483
484
485
	/**
486
	 * Sets the number of product packages not yet delivered to the customer.
487
	 *
488
	 * @param float $quantity Amount of product packages
489
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
490
	 */
491
	public function setQuantityOpen( float $quantity ) : \Aimeos\MShop\Order\Item\Product\Iface
492
	{
493
		if( $quantity < 0 || $quantity > $this->getQuantity() ) {
494
			throw new \Aimeos\MShop\Order\Exception( sprintf( 'Quantity must be 0 or greater and must not exceed ordered quantity' ) );
495
		}
496
497
		return $this->set( 'order.product.qtyopen', $quantity );
498
	}
499
500
501
	/**
502
	 * Returns the quantity scale of the product.
503
	 *
504
	 * @return float Minimum quantity value
505
	 */
506
	public function getScale() : float
507
	{
508
		return (float) $this->get( 'order.product.scale', 1 );
509
	}
510
511
512
	/**
513
	 * Sets the quantity scale of the product.
514
	 *
515
	 * @param float $quantity Minimum quantity value
516
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
517
	 */
518
	public function setScale( float $quantity ) : \Aimeos\MShop\Order\Item\Product\Iface
519
	{
520
		if( $quantity <= 0 ) {
521
			throw new \Aimeos\MShop\Order\Exception( sprintf( 'Quantity scale must be greater than 0' ) );
522
		}
523
524
		return $this->set( 'order.product.scale', $quantity );
525
	}
526
527
528
	/**
529
	 * 	Returns the flags for the product item.
530
	 *
531
	 * @return int Flags, e.g. for immutable products
532
	 */
533
	public function getFlags() : int
534
	{
535
		return $this->get( 'order.product.flags', \Aimeos\MShop\Order\Item\Product\Base::FLAG_NONE );
536
	}
537
538
539
	/**
540
	 * Sets the new value for the product item flags.
541
	 *
542
	 * @param int $value Flags, e.g. for immutable products
543
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
544
	 */
545
	public function setFlags( int $value ) : \Aimeos\MShop\Order\Item\Product\Iface
546
	{
547
		return $this->set( 'order.product.flags', $this->checkFlags( $value ) );
548
	}
549
550
551
	/**
552
	 * Returns the position of the product in the order.
553
	 *
554
	 * @return int|null Product position in the order from 0-n
555
	 */
556
	public function getPosition() : ?int
557
	{
558
		return $this->get( 'order.product.position' );
559
	}
560
561
562
	/**
563
	 * Sets the position of the product within the list of ordered products.
564
	 *
565
	 * @param int|null $value Product position in the order from 0-n or null for resetting the position
566
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
567
	 * @throws \Aimeos\MShop\Order\Exception If the position is invalid
568
	 */
569
	public function setPosition( ?int $value ) : \Aimeos\MShop\Order\Item\Product\Iface
570
	{
571
		if( $value < 0 ) {
572
			throw new \Aimeos\MShop\Order\Exception( sprintf( 'Order product position "%1$s" must be greater than 0', $value ) );
573
		}
574
575
		return $this->set( 'order.product.position', $value );
576
	}
577
578
579
	/**
580
	 * Returns the current delivery status of the order product item.
581
	 *
582
	 * The returned status values are the STAT_* constants from the \Aimeos\MShop\Order\Item\Base class
583
	 *
584
	 * @return int Delivery status of the product
585
	 */
586
	public function getStatusDelivery() : int
587
	{
588
		return $this->get( 'order.product.statusdelivery', -1 );
589
	}
590
591
592
	/**
593
	 * Sets the new delivery status of the order product item.
594
	 *
595
	 * Possible status values are the STAT_* constants from the \Aimeos\MShop\Order\Item\Base class
596
	 *
597
	 * @param int $value New delivery status of the product
598
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
599
	 */
600
	public function setStatusDelivery( int $value ) : \Aimeos\MShop\Order\Item\Product\Iface
601
	{
602
		return $this->set( 'order.product.statusdelivery', $value );
603
	}
604
605
606
	/**
607
	 * Returns the current payment status of the order product item.
608
	 *
609
	 * The returned status values are the PAY_* constants from the \Aimeos\MShop\Order\Item\Base class
610
	 *
611
	 * @return int Payment status of the product
612
	 */
613
	public function getStatusPayment() : int
614
	{
615
		return $this->get( 'order.product.statuspayment', -1 );
616
	}
617
618
619
	/**
620
	 * Sets the new payment status of the order product item.
621
	 *
622
	 * Possible status values are the PAY_* constants from the \Aimeos\MShop\Order\Item\Base class
623
	 *
624
	 * @param int $value New payment status of the product
625
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
626
	 */
627
	public function setStatusPayment( int $value ) : \Aimeos\MShop\Order\Item\Product\Iface
628
	{
629
		return $this->set( 'order.product.statuspayment', $value );
630
	}
631
632
633
	/**
634
	 * Returns the notes for the ordered product.
635
	 *
636
	 * @return string Notes for the ordered product
637
	 */
638
	public function getNotes() : string
639
	{
640
		return $this->get( 'order.product.notes', '' );
641
	}
642
643
644
	/**
645
	 * Sets the notes for the ordered product.
646
	 *
647
	 * @param string|null $value Notes for the ordered product
648
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order base product item for chaining method calls
649
	 */
650
	public function setNotes( ?string $value ) : \Aimeos\MShop\Order\Item\Product\Iface
651
	{
652
		return $this->set( 'order.product.notes', (string) $value );
653
	}
654
655
656
	/*
657
	 * Sets the item values from the given array and removes that entries from the list
658
	 *
659
	 * @param array &$list Associative list of item keys and their values
660
	 * @param bool True to set private properties too, false for public only
661
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order product item for chaining method calls
662
	 */
663
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
664
	{
665
		$price = $this->getPrice();
666
		$item = parent::fromArray( $list, $private );
667
668
		foreach( $list as $key => $value )
669
		{
670
			switch( $key )
671
			{
672
				case 'order.product.siteid': !$private ?: $item->setSiteId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setSiteId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

672
				case 'order.product.siteid': !$private ?: $item->/** @scrutinizer ignore-call */ setSiteId( $value ); break;
Loading history...
673
				case 'order.product.parentid': !$private ?: $item->setParentId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setParentId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

673
				case 'order.product.parentid': !$private ?: $item->/** @scrutinizer ignore-call */ setParentId( $value ); break;
Loading history...
674
				case 'order.product.orderproductid': !$private ?: $item->setOrderProductId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setOrderProductId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

674
				case 'order.product.orderproductid': !$private ?: $item->/** @scrutinizer ignore-call */ setOrderProductId( $value ); break;
Loading history...
675
				case 'order.product.orderaddressid': !$private ?: $item->setOrderAddressId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setOrderAddressId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

675
				case 'order.product.orderaddressid': !$private ?: $item->/** @scrutinizer ignore-call */ setOrderAddressId( $value ); break;
Loading history...
676
				case 'order.product.position': !$private ?: $item->setPosition( (int) $value ); break;
0 ignored issues
show
Bug introduced by
The method setPosition() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

676
				case 'order.product.position': !$private ?: $item->/** @scrutinizer ignore-call */ setPosition( (int) $value ); break;
Loading history...
677
				case 'order.product.flags': !$private ?: $item->setFlags( (int) $value ); break;
0 ignored issues
show
Bug introduced by
The method setFlags() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

677
				case 'order.product.flags': !$private ?: $item->/** @scrutinizer ignore-call */ setFlags( (int) $value ); break;
Loading history...
678
				case 'order.product.target': !$private ?: $item->setTarget( $value ); break;
0 ignored issues
show
Bug introduced by
The method setTarget() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

678
				case 'order.product.target': !$private ?: $item->/** @scrutinizer ignore-call */ setTarget( $value ); break;
Loading history...
679
				case 'order.product.parentproductid': $item->setParentProductId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setParentProductId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

679
				case 'order.product.parentproductid': $item->/** @scrutinizer ignore-call */ setParentProductId( $value ); break;
Loading history...
680
				case 'order.product.productid': $item->setProductId( $value ); break;
0 ignored issues
show
Bug introduced by
The method setProductId() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

680
				case 'order.product.productid': $item->/** @scrutinizer ignore-call */ setProductId( $value ); break;
Loading history...
681
				case 'order.product.prodcode': $item->setProductCode( $value ); break;
0 ignored issues
show
Bug introduced by
The method setProductCode() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

681
				case 'order.product.prodcode': $item->/** @scrutinizer ignore-call */ setProductCode( $value ); break;
Loading history...
682
				case 'order.product.vendor': $item->setVendor( $value ); break;
0 ignored issues
show
Bug introduced by
The method setVendor() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

682
				case 'order.product.vendor': $item->/** @scrutinizer ignore-call */ setVendor( $value ); break;
Loading history...
683
				case 'order.product.stocktype': $item->setStockType( $value ); break;
0 ignored issues
show
Bug introduced by
The method setStockType() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

683
				case 'order.product.stocktype': $item->/** @scrutinizer ignore-call */ setStockType( $value ); break;
Loading history...
684
				case 'order.product.type': $item->setType( $value ); break;
0 ignored issues
show
Bug introduced by
The method setType() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

684
				case 'order.product.type': $item->/** @scrutinizer ignore-call */ setType( $value ); break;
Loading history...
685
				case 'order.product.currencyid': $price = $price->setCurrencyId( $value ); break;
686
				case 'order.product.price': $price = $price->setValue( $value ); break;
687
				case 'order.product.costs': $price = $price->setCosts( $value ); break;
688
				case 'order.product.rebate': $price = $price->setRebate( $value ); break;
689
				case 'order.product.taxrates': $price = $price->setTaxRates( $value ); break;
690
				case 'order.product.taxvalue': $price = $price->setTaxValue( $value ); break;
691
				case 'order.product.taxflag': $price = $price->setTaxFlag( $value ); break;
692
				case 'order.product.name': $item->setName( $value ); break;
0 ignored issues
show
Bug introduced by
The method setName() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

692
				case 'order.product.name': $item->/** @scrutinizer ignore-call */ setName( $value ); break;
Loading history...
693
				case 'order.product.description': $item->setDescription( $value ); break;
0 ignored issues
show
Bug introduced by
The method setDescription() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

693
				case 'order.product.description': $item->/** @scrutinizer ignore-call */ setDescription( $value ); break;
Loading history...
694
				case 'order.product.mediaurl': $item->setMediaUrl( $value ); break;
0 ignored issues
show
Bug introduced by
The method setMediaUrl() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

694
				case 'order.product.mediaurl': $item->/** @scrutinizer ignore-call */ setMediaUrl( $value ); break;
Loading history...
695
				case 'order.product.timeframe': $item->setTimeFrame( $value ); break;
0 ignored issues
show
Bug introduced by
The method setTimeFrame() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

695
				case 'order.product.timeframe': $item->/** @scrutinizer ignore-call */ setTimeFrame( $value ); break;
Loading history...
696
				case 'order.product.scale': $item->setScale( (float) $value ); break;
0 ignored issues
show
Bug introduced by
The method setScale() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

696
				case 'order.product.scale': $item->/** @scrutinizer ignore-call */ setScale( (float) $value ); break;
Loading history...
697
				case 'order.product.quantity': $item->setQuantity( (float) $value ); break;
0 ignored issues
show
Bug introduced by
The method setQuantity() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

697
				case 'order.product.quantity': $item->/** @scrutinizer ignore-call */ setQuantity( (float) $value ); break;
Loading history...
698
				case 'order.product.qtyopen': $item->setQuantityOpen( (float) $value ); break;
0 ignored issues
show
Bug introduced by
The method setQuantityOpen() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

698
				case 'order.product.qtyopen': $item->/** @scrutinizer ignore-call */ setQuantityOpen( (float) $value ); break;
Loading history...
699
				case 'order.product.notes': $item->setNotes( (string) $value ); break;
0 ignored issues
show
Bug introduced by
The method setNotes() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

699
				case 'order.product.notes': $item->/** @scrutinizer ignore-call */ setNotes( (string) $value ); break;
Loading history...
700
				case 'order.product.statusdelivery': $item->setStatusDelivery( (int) $value ); break;
0 ignored issues
show
Bug introduced by
The method setStatusDelivery() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

700
				case 'order.product.statusdelivery': $item->/** @scrutinizer ignore-call */ setStatusDelivery( (int) $value ); break;
Loading history...
701
				case 'order.product.statuspayment': $item->setStatusPayment( (int) $value ); break;
0 ignored issues
show
Bug introduced by
The method setStatusPayment() does not exist on Aimeos\MShop\Order\Item\Product\Base. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

701
				case 'order.product.statuspayment': $item->/** @scrutinizer ignore-call */ setStatusPayment( (int) $value ); break;
Loading history...
702
				default: continue 2;
703
			}
704
705
			unset( $list[$key] );
706
		}
707
708
		return $item;
709
	}
710
711
712
	/**
713
	 * Returns the item values as associative list.
714
	 *
715
	 * @param bool True to return private properties, false for public only
716
	 * @return array Associative list of item properties and their values
717
	 */
718
	public function toArray( bool $private = false ) : array
719
	{
720
		$price = $this->getPrice();
721
		$list = parent::toArray( $private );
722
723
		$list['order.product.type'] = $this->getType();
724
		$list['order.product.stocktype'] = $this->getStockType();
725
		$list['order.product.prodcode'] = $this->getProductCode();
726
		$list['order.product.productid'] = $this->getProductId();
727
		$list['order.product.parentproductid'] = $this->getParentProductId();
728
		$list['order.product.vendor'] = $this->getVendor();
729
		$list['order.product.scale'] = $this->getScale();
730
		$list['order.product.quantity'] = $this->getQuantity();
731
		$list['order.product.qtyopen'] = $this->getQuantityOpen();
732
		$list['order.product.currencyid'] = $price->getCurrencyId();
733
		$list['order.product.price'] = $price->getValue();
734
		$list['order.product.costs'] = $price->getCosts();
735
		$list['order.product.rebate'] = $price->getRebate();
736
		$list['order.product.taxrates'] = $price->getTaxRates();
737
		$list['order.product.taxvalue'] = $price->getTaxValue();
738
		$list['order.product.taxflag'] = $price->getTaxFlag();
739
		$list['order.product.name'] = $this->getName();
740
		$list['order.product.description'] = $this->getDescription();
741
		$list['order.product.mediaurl'] = $this->getMediaUrl();
742
		$list['order.product.timeframe'] = $this->getTimeFrame();
743
		$list['order.product.position'] = $this->getPosition();
744
		$list['order.product.notes'] = $this->getNotes();
745
		$list['order.product.statuspayment'] = $this->getStatusPayment();
746
		$list['order.product.statusdelivery'] = $this->getStatusDelivery();
747
748
		if( $private === true )
749
		{
750
			$list['order.product.parentid'] = $this->getParentId();
751
			$list['order.product.orderproductid'] = $this->getOrderProductId();
752
			$list['order.product.orderaddressid'] = $this->getOrderAddressId();
753
			$list['order.product.target'] = $this->getTarget();
754
			$list['order.product.flags'] = $this->getFlags();
755
		}
756
757
		return $list;
758
	}
759
760
	/**
761
	 * Compares the properties of the given order product item with its own ones.
762
	 *
763
	 * @param \Aimeos\MShop\Order\Item\Product\Iface $item Order product item
764
	 * @return bool True if the item properties are equal, false if not
765
	 * @since 2015.10
766
	 */
767
	public function compare( \Aimeos\MShop\Order\Item\Product\Iface $item ) : bool
768
	{
769
		if( $this->getFlags() === $item->getFlags()
770
			&& $this->getName() === $item->getName()
771
			&& $this->getSiteId() === $item->getSiteId()
772
			&& $this->getStockType() === $item->getStockType()
773
			&& $this->getProductCode() === $item->getProductCode()
774
			&& $this->getOrderAddressId() === $item->getOrderAddressId()
775
		) {
776
			return true;
777
		}
778
779
		return false;
780
	}
781
782
783
	/**
784
	 * Copys all data from a given product item.
785
	 *
786
	 * @param \Aimeos\MShop\Product\Item\Iface $product Product item to copy from
787
	 * @return \Aimeos\MShop\Order\Item\Product\Iface Order product item for chaining method calls
788
	 */
789
	public function copyFrom( \Aimeos\MShop\Product\Item\Iface $product ) : \Aimeos\MShop\Order\Item\Product\Iface
790
	{
791
		$values = $product->toArray();
792
		$this->fromArray( $values );
793
794
		$this->setSiteId( $product->getSiteId() );
795
		$this->setProductCode( $product->getCode() );
796
		$this->setProductId( $product->getId() );
797
		$this->setType( $product->getType() );
798
		$this->setScale( $product->getScale() );
799
		$this->setTarget( $product->getTarget() );
800
		$this->setName( $product->getName() );
801
802
		if( $item = $product->getRefItems( 'text', 'basket', 'default' )->first() ) {
803
			$this->setDescription( $item->getContent() );
804
		}
805
806
		if( $item = $product->getRefItems( 'media', 'default', 'default' )->first() ) {
807
			$this->setMediaUrl( $item->getPreview() );
808
		}
809
810
		if( $item = $product->getSiteItem() ) {
811
			$this->setVendor( $item->getLabel() );
812
		}
813
814
		if( self::macro( 'copyFrom' ) ) {
815
			$this->call( 'copyFrom', $product );
816
		}
817
818
		return $this->setModified();
819
	}
820
}
821