Completed
Push — master ( 963355...94aa33 )
by Joachim
12:06
created

Product::getProductRelations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Assert\Assert;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletable;
9
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
10
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
11
use Loevgaard\DandomainFoundation\Entity\Generated\CategoryInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...rated\CategoryInterface 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...
12
use Loevgaard\DandomainFoundation\Entity\Generated\CurrencyInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...rated\CurrencyInterface 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...
13
use Loevgaard\DandomainFoundation\Entity\Generated\ManufacturerInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...d\ManufacturerInterface 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...
14
use Loevgaard\DandomainFoundation\Entity\Generated\MediumInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...nerated\MediumInterface 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...
15
use Loevgaard\DandomainFoundation\Entity\Generated\PriceInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...enerated\PriceInterface 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...
16
use Loevgaard\DandomainFoundation\Entity\Generated\ProductInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...erated\ProductInterface 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...
17
use Loevgaard\DandomainFoundation\Entity\Generated\ProductRelationInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...roductRelationInterface 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...
18
use Loevgaard\DandomainFoundation\Entity\Generated\ProductTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...\Generated\ProductTrait 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...
19
use Loevgaard\DandomainFoundation\Entity\Generated\ProductTranslationInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...uctTranslationInterface 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...
20
use Loevgaard\DandomainFoundation\Entity\Generated\ProductTypeInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ed\ProductTypeInterface 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...
21
use Loevgaard\DandomainFoundation\Entity\Generated\SegmentInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...erated\SegmentInterface 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...
22
use Loevgaard\DandomainFoundation\Entity\Generated\VariantGroupInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...d\VariantGroupInterface 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...
23
use Loevgaard\DandomainFoundation\Entity\Generated\VariantInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...erated\VariantInterface 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...
24
25
/**
26
 * @ORM\Entity()
27
 * @ORM\Table(name="ldf_products", indexes={
28
 *     @ORM\Index(columns={"is_variant_master"})
29
 * })
30
 * @ORM\HasLifecycleCallbacks()
31
 * @method ProductTranslationInterface translate(string $locale = null, bool $fallbackToDefault = true)
32
 */
33
class Product extends AbstractEntity implements ProductInterface
34
{
35
    use ProductTrait;
36
    use Timestampable;
37
    use SoftDeletable;
38
    use Translatable;
39
40
    protected $hydrateConversions = [
41
        'id' => 'externalId'
42
    ];
43
44
    /**
45
     * @var int
46
     *
47
     * @ORM\Id
48
     * @ORM\GeneratedValue
49
     * @ORM\Column(type="integer")
50
     **/
51
    protected $id;
52
53
    /**
54
     * @var int
55
     *
56
     * @ORM\Column(type="integer", nullable=true, unique=true)
57
     */
58
    protected $externalId;
59
60
    /**
61
     * @var string|null
62
     *
63
     * @ORM\Column(nullable=true, type="string", length=191)
64
     */
65
    protected $barCodeNumber;
66
67
    /**
68
     * @var array|null
69
     *
70
     * @ORM\Column(nullable=true, type="json")
71
     */
72
    protected $categoryIdList;
73
74
    /**
75
     * @var string|null
76
     *
77
     * @ORM\Column(nullable=true, type="string", length=191)
78
     */
79
    protected $comments;
80
81
    /**
82
     * @var float|null
83
     *
84
     * @ORM\Column(nullable=true, type="decimal", precision=12, scale=2)
85
     */
86
    protected $costPrice;
87
88
    /**
89
     * @var \DateTimeImmutable|null
90
     *
91
     * @ORM\Column(nullable=true, type="datetime_immutable", options={"comment"="Created info from Dandomain"})
92
     */
93
    protected $created;
94
95
    /**
96
     * @var string|null
97
     *
98
     * @ORM\Column(nullable=true, type="string", length=191, options={"comment"="Created by info from Dandomain"})
99
     */
100
    protected $createdBy;
101
102
    /**
103
     * @var int|null
104
     *
105
     * @ORM\Column(nullable=true, type="integer")
106
     */
107
    protected $defaultCategoryId;
108
109
    /**
110
     * @var array|null
111
     *
112
     * @ORM\Column(nullable=true, type="json")
113
     */
114
    protected $disabledVariantIdList;
115
116
    /**
117
     * @var string|null
118
     *
119
     * @ORM\Column(nullable=true, type="string", length=191)
120
     */
121
    protected $edbPriserProductNumber;
122
123
    /**
124
     * @var string|null
125
     *
126
     * @ORM\Column(nullable=true, type="string", length=191)
127
     */
128
    protected $fileSaleLink;
129
130
    /**
131
     * @var string|null
132
     *
133
     * @ORM\Column(nullable=true, type="string", length=191)
134
     */
135
    protected $googleFeedCategory;
136
137
    /**
138
     * @var bool|null
139
     *
140
     * @ORM\Column(nullable=true, type="boolean")
141
     */
142
    protected $isGiftCertificate;
143
144
    /**
145
     * @var bool|null
146
     *
147
     * @ORM\Column(nullable=true, type="boolean")
148
     */
149
    protected $isModified;
150
151
    /**
152
     * @var bool|null
153
     *
154
     * @ORM\Column(nullable=true, type="boolean")
155
     */
156
    protected $isRateVariants;
157
158
    /**
159
     * @var bool|null
160
     *
161
     * @ORM\Column(nullable=true, type="boolean")
162
     */
163
    protected $isReviewVariants;
164
165
    /**
166
     * @var bool|null
167
     *
168
     * @ORM\Column(name="is_variant_master", nullable=true, type="boolean")
169
     */
170
    protected $isVariantMaster;
171
172
    /**
173
     * @var string|null
174
     *
175
     * @ORM\Column(nullable=true, type="string", length=191)
176
     */
177
    protected $locationNumber;
178
179
    /**
180
     * @var array|null
181
     *
182
     * @ORM\Column(nullable=true, type="json")
183
     */
184
    protected $manufacturereIdList;
185
186
    /**
187
     * @var int|null
188
     *
189
     * @ORM\Column(nullable=true, type="integer")
190
     */
191
    protected $maxBuyAmount;
192
193
    /**
194
     * @var int|null
195
     *
196
     * @ORM\Column(nullable=true, type="integer")
197
     */
198
    protected $minBuyAmount;
199
200
    /**
201
     * @var int|null
202
     *
203
     * @ORM\Column(nullable=true, type="integer")
204
     */
205
    protected $minBuyAmountB2B;
206
207
    /**
208
     * The product number
209
     *
210
     * @var string
211
     *
212
     * @ORM\Column(type="string", length=191)
213
     */
214
    protected $number;
215
216
    /**
217
     * @var string|null
218
     *
219
     * @ORM\Column(nullable=true, type="string", length=191)
220
     */
221
    protected $picture;
222
223
    /**
224
     * @var int|null
225
     *
226
     * @ORM\Column(nullable=true, type="integer")
227
     */
228
    protected $salesCount;
229
230
    /**
231
     * @var array|null
232
     *
233
     * @ORM\Column(nullable=true, type="json")
234
     */
235
    protected $segmentIdList;
236
237
    /**
238
     * @var int|null
239
     *
240
     * @ORM\Column(nullable=true, type="integer")
241
     */
242
    protected $sortOrder;
243
244
    /**
245
     * @var int|null
246
     *
247
     * @ORM\Column(nullable=true, type="integer")
248
     */
249
    protected $stockCount;
250
251
    /**
252
     * @var int|null
253
     *
254
     * @ORM\Column(nullable=true, type="integer")
255
     */
256
    protected $stockLimit;
257
258
    /**
259
     * @var int|null
260
     *
261
     * @ORM\Column(nullable=true, type="integer")
262
     */
263
    protected $typeId;
264
265
    /**
266
     * @var \DateTimeImmutable|null
267
     *
268
     * @ORM\Column(nullable=true, type="datetime_immutable", options={"comment"="Updated info from Dandomain"})
269
     */
270
    protected $updated;
271
272
    /**
273
     * @var string|null
274
     *
275
     * @ORM\Column(nullable=true, type="string", length=191, options={"comment"="Updated by info from Dandomain"})
276
     */
277
    protected $updatedBy;
278
279
    /**
280
     * @var array|null
281
     *
282
     * @ORM\Column(nullable=true, type="json")
283
     */
284
    protected $variantGroupIdList;
285
286
    /**
287
     * @var array|null
288
     *
289
     * @ORM\Column(nullable=true, type="json")
290
     */
291
    protected $variantIdList;
292
293
    /**
294
     * @var int|null
295
     *
296
     * @ORM\Column(nullable=true, type="string", length=191)
297
     */
298
    protected $variantMasterId;
299
300
    /**
301
     * @var string|null
302
     *
303
     * @ORM\Column(nullable=true, type="string", length=191)
304
     */
305
    protected $vendorNumber;
306
307
    /**
308
     * @var int|null
309
     *
310
     * @ORM\Column(nullable=true, type="integer")
311
     */
312
    protected $weight;
313
314
    /**
315
     * @var Category[]|ArrayCollection
316
     *
317
     * @ORM\ManyToMany(targetEntity="Category", inversedBy="products")
318
     * @ORM\JoinTable(name="ldf_products_categories")
319
     */
320
    protected $categories;
321
322
    /**
323
     * @var Variant[]|ArrayCollection
324
     */
325
    protected $disabledVariants;
326
327
    /**
328
     * @var Manufacturer[]|ArrayCollection
329
     *
330
     * @ORM\JoinTable(name="ldf_product_manufacturer")
331
     * @ORM\ManyToMany(cascade={"persist"}, inversedBy="products", targetEntity="Manufacturer")
332
     */
333
    protected $manufacturers;
334
335
    /**
336
     * @var Medium[]|ArrayCollection
337
     */
338
    protected $media;
339
340
    /**
341
     * @var PriceInterface[]|ArrayCollection
342
     *
343
     * @ORM\OneToMany(targetEntity="Price", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
344
     */
345
    protected $prices;
346
347
    /**
348
     * @var ProductRelation[]|ArrayCollection
349
     */
350
    protected $productRelations;
351
352
    /**
353
     * @var ProductType
354
     */
355
    protected $productType;
356
357
    /**
358
     * @var Segment[]|ArrayCollection
359
     */
360
    protected $segments;
361
362
    /**
363
     * @var VariantGroup[]|ArrayCollection
364
     *
365
     * @ORM\JoinTable(name="ldf_product_variant_group")
366
     * @ORM\ManyToMany(cascade={"persist"}, inversedBy="products", targetEntity="VariantGroup")
367
     */
368
    protected $variantGroups;
369
370
    /**
371
     * @var Variant[]|ArrayCollection
372
     */
373
    protected $variants;
374
375
    /**
376
     * This is the master for this product
377
     *
378
     * @var Product|null
379
     *
380
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="children")
381
     */
382
    protected $parent;
383
384
    /**
385
     * This is the children (i.e. variants) of this products
386
     *
387
     * @var Product[]|ArrayCollection
388
     *
389
     * @ORM\OneToMany(targetEntity="Product", mappedBy="parent")
390 12
     */
391
    protected $children;
392 12
393 12
    public function __construct()
394 12
    {
395 12
        $this->categories = new ArrayCollection();
396 12
        $this->disabledVariants = new ArrayCollection();
397 12
        $this->manufacturers = new ArrayCollection();
398 12
        $this->media = new ArrayCollection();
399 12
        $this->prices = new ArrayCollection();
400 12
        $this->productRelations = new ArrayCollection();
401 12
        $this->segments = new ArrayCollection();
402 12
        $this->variants = new ArrayCollection();
403
        $this->variantGroups = new ArrayCollection();
404
        $this->children = new ArrayCollection();
405
    }
406
407
    public function __toString()
408
    {
409
        return (string)$this->number;
410
    }
411
412
    /**
413
     * @ORM\PrePersist()
414
     * @ORM\PreUpdate()
415
     */
416
    public function validate()
417
    {
418
        Assert::that($this->number)
419
            ->string('The number needs to be string', 'number')
420
            ->maxLength(191, 'The number must have a max length of 191');
421
        Assert::thatNullOr($this->externalId)->integer('The external id can only be null or an integer', 'externalId');
422
423
        if (is_null($this->externalId)) {
0 ignored issues
show
introduced by
The condition is_null($this->externalId) can never be true.
Loading history...
424
            Assert::that($this->isDeleted())->true('The external id can only be null if the product is marked as deleted', 'externalId');
425 3
        }
426
    }
427 3
428 3
    public function hydrate(array $data, bool $useConversions = false, $scalarsOnly = true)
429
    {
430
        if (isset($data['created'])) {
431 3
            $data['created'] = $this->getDateTimeFromJson($data['created']);
432 3
        }
433
434
        if (isset($data['updated'])) {
435 3
            $data['updated'] = $this->getDateTimeFromJson($data['updated']);
436 3
        }
437
438
        parent::hydrate($data, $useConversions, $scalarsOnly);
439
    }
440
441
    /*
442
     * Collection/relation methods
443
     */
444
445
    public function addDisabledVariant(VariantInterface $variant) : ProductInterface
446
    {
447
        if (!$this->disabledVariants->contains($variant)) {
448
            $this->disabledVariants->add($variant);
449
        }
450
451
        return $this;
452
    }
453
454
    public function addMedium(MediumInterface $medium) : ProductInterface
455
    {
456
        if (!$this->media->contains($medium)) {
457
            $this->media->add($medium);
458
        }
459
460
        return $this;
461
    }
462
463
    public function addCategory(CategoryInterface $category) : ProductInterface
464
    {
465
        if (!$this->categories->contains($category)) {
466
            $this->categories->add($category);
467
        }
468
469
        return $this;
470
    }
471
472
    public function addManufacturer(ManufacturerInterface $manufacturer) : ProductInterface
473
    {
474
        if (!$this->hasManufacturer($manufacturer)) {
475
            $this->manufacturers->add($manufacturer);
476
        }
477
478
        return $this;
479
    }
480
481
    public function removeManufacturer(ManufacturerInterface $manufacturer) : bool
482
    {
483
        return $this->manufacturers->removeElement($manufacturer);
484
    }
485
486
    public function hasManufacturer(ManufacturerInterface $manufacturer) : bool
487
    {
488
        return $this->manufacturers->exists(function ($key, ManufacturerInterface $element) use ($manufacturer) {
489
            return $element->getExternalId() === $manufacturer->getExternalId();
490
        });
491
    }
492
493
    public function addVariantGroup(VariantGroupInterface $variantGroup) : ProductInterface
494
    {
495
        if (!$this->hasVariantGroup($variantGroup)) {
496
            $this->variantGroups->add($variantGroup);
497
        }
498
499
        return $this;
500
    }
501
502
    public function removeVariantGroup(VariantGroupInterface $variantGroup) : bool
503
    {
504
        return $this->variantGroups->removeElement($variantGroup);
505
    }
506
507
    public function hasVariantGroup($variantGroup) : bool
508
    {
509
        if ($variantGroup instanceof VariantGroupInterface) {
510
            $variantGroup = $variantGroup->getExternalId();
511
        }
512
513
        return $this->variantGroups->exists(function ($key, VariantGroupInterface $element) use ($variantGroup) {
514
            return $element->getExternalId() === $variantGroup;
515
        });
516
    }
517
518
    public function addPrice(PriceInterface $price) : ProductInterface
519
    {
520
        if(!$this->prices->contains($price)) {
521
            $this->prices->add($price);
522
        }
523
524
        return $this;
525
    }
526
527
    /**
528
     * @param PriceInterface[] $prices
529
     */
530
    public function updatePrices(array $prices) : void
531
    {
532
        $finalPrices = [];
533
534
        foreach ($prices as $price) {
535
            $existingPrice = $this->findPrice($price);
536
537
            if($existingPrice) {
538
                $existingPrice->copyProperties($price);
539
                $existingPrice->setProduct($this);
540
                $finalPrices[] = $existingPrice;
541
            } else {
542
                $this->addPrice($price);
543
                $price->setProduct($this);
544
                $finalPrices[] = $price;
545
            }
546
        }
547
548
        foreach ($this->prices as $price) {
549
            if(!in_array($price, $finalPrices, true)) {
550
                $this->removePrice($price);
551
            }
552
        }
553
    }
554
555
    public function removePrice(PriceInterface $price) : bool
556
    {
557
        $price->setProduct(null);
558
        return $this->prices->removeElement($price);
559
    }
560
561
    /**
562
     * This method will try to find a price based on the unique constraint defined in price
563
     *
564
     * @param PriceInterface $searchPrice
565
     * @return PriceInterface|null
566
     */
567
    protected function findPrice(PriceInterface $searchPrice) : ?PriceInterface
568
    {
569
        foreach ($this->prices as $price) {
570
            if($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
571
                return $price;
572
            }
573
        }
574
575
        return null;
576
    }
577
578
    /**
579
     * Will try to find a price based on currency
580
     *
581
     * @param string|\Money\Currency|CurrencyInterface $currency
582
     * @return PriceInterface|null
583
     */
584 6
    public function findPriceByCurrency($currency) : ?PriceInterface
585
    {
586 6
        if($currency instanceof \Money\Currency) {
587
            $currency = $currency->getCode();
588
        } elseif ($currency instanceof CurrencyInterface) {
0 ignored issues
show
introduced by
The condition $currency instanceof Loe...rated\CurrencyInterface can never be true since $currency is never a sub-type of Loevgaard\DandomainFound...rated\CurrencyInterface.
Loading history...
589
            $currency = $currency->getIsoCodeAlpha();
590
        }
591
592
        if(!is_string($currency)) {
0 ignored issues
show
introduced by
The condition ! is_string($currency) can never be true.
Loading history...
593 3
            throw new \InvalidArgumentException('$currency has to be a string');
594
        }
595 3
596 3
        foreach ($this->prices as $price) {
597
            if($price->getCurrency()->getIsoCodeAlpha() === $currency) {
598
                return $price;
599
            }
600
        }
601
602 6
        return null;
603
    }
604 6
605
    public function addProductRelation(ProductRelationInterface $productRelation) : ProductInterface
606
    {
607
        if (!$this->productRelations->contains($productRelation)) {
608
            $this->productRelations->add($productRelation);
609
        }
610
611 3
        return $this;
612
    }
613 3
614 3
    public function addSegment(SegmentInterface $segment) : ProductInterface
615
    {
616
        if (!$this->segments->contains($segment)) {
617
            $this->segments->add($segment);
618
        }
619
620 3
        return $this;
621
    }
622 3
623
    public function addVariant(VariantInterface $variant) : ProductInterface
624
    {
625
        if (!$this->variants->contains($variant)) {
626
            $this->variants->add($variant);
627
        }
628
629 3
        return $this;
630
    }
631 3
632 3
    public function addChild(ProductInterface $product) : ProductInterface
633
    {
634
        if (!$this->hasChild($product)) {
635
            $this->children->add($product);
636
            $product->setParent($this);
637
        }
638
639
        return $this;
640
    }
641
642
    public function removeChild(ProductInterface $product) : bool
643
    {
644
        $product->setParent(null);
645
        return $this->children->removeElement($product);
646
    }
647
648
    public function hasChild($product) : bool
649
    {
650
        if ($product instanceof ProductInterface) {
651
            $product = $product->getExternalId();
652
        }
653
654
        return $this->children->exists(function ($key, ProductInterface $element) use ($product) {
655
            return $element->getExternalId() === $product;
656 3
        });
657
    }
658 3
659
    /*
660
     * Getters / Setters
661
     */
662
    /**
663
     * @return int
664
     */
665 3
    public function getId(): int
666
    {
667 3
        return (int)$this->id;
668 3
    }
669
670
    /**
671
     * @param int $id
672
     * @return ProductInterface
673
     */
674 3
    public function setId(int $id)
675
    {
676 3
        $this->id = $id;
677
        return $this;
678
    }
679
680
    /**
681
     * @return int
682
     */
683 3
    public function getExternalId(): int
684
    {
685 3
        return (int)$this->externalId;
686 3
    }
687
688
    /**
689
     * @param int $externalId
690
     * @return ProductInterface
691
     */
692 3
    public function setExternalId(int $externalId)
693
    {
694 3
        $this->externalId = $externalId;
695
        return $this;
696
    }
697
698
    /**
699
     * @return null|string
700
     */
701 3
    public function getBarCodeNumber()
702
    {
703 3
        return $this->barCodeNumber;
704 3
    }
705
706
    /**
707
     * @param null|string $barCodeNumber
708
     * @return ProductInterface
709
     */
710 3
    public function setBarCodeNumber($barCodeNumber)
711
    {
712 3
        $this->barCodeNumber = $barCodeNumber;
713
        return $this;
714
    }
715
716
    /**
717
     * @return array|null
718
     */
719 3
    public function getCategoryIdList()
720
    {
721 3
        return $this->categoryIdList;
722 3
    }
723
724
    /**
725
     * @param array|null $categoryIdList
726
     * @return ProductInterface
727
     */
728 3
    public function setCategoryIdList($categoryIdList)
729
    {
730 3
        $this->categoryIdList = $categoryIdList;
731
        return $this;
732
    }
733
734
    /**
735
     * @return null|string
736
     */
737 3
    public function getComments()
738
    {
739 3
        return $this->comments;
740 3
    }
741
742
    /**
743
     * @param null|string $comments
744
     * @return ProductInterface
745
     */
746
    public function setComments($comments)
747
    {
748
        $this->comments = $comments;
749
        return $this;
750
    }
751
752
    /**
753
     * @return float|null
754
     */
755
    public function getCostPrice()
756
    {
757
        return $this->costPrice;
758
    }
759
760
    /**
761
     * @param float|null $costPrice
762
     * @return ProductInterface
763
     */
764 3
    public function setCostPrice($costPrice)
765
    {
766 3
        $this->costPrice = $costPrice;
767
        return $this;
768
    }
769
770
    /**
771
     * @return \DateTimeImmutable|null
772
     */
773 3
    public function getCreated()
774
    {
775 3
        return $this->created;
776 3
    }
777
778
    /**
779
     * @param \DateTimeImmutable|null $created
780
     * @return ProductInterface
781
     */
782 3
    public function setCreated($created)
783
    {
784 3
        $this->created = $created;
785
        return $this;
786
    }
787
788
    /**
789
     * @return null|string
790
     */
791 3
    public function getCreatedBy()
792
    {
793 3
        return $this->createdBy;
794 3
    }
795
796
    /**
797
     * @param null|string $createdBy
798
     * @return ProductInterface
799
     */
800 3
    public function setCreatedBy($createdBy)
801
    {
802 3
        $this->createdBy = $createdBy;
803
        return $this;
804
    }
805
806
    /**
807
     * @return int|null
808
     */
809 3
    public function getDefaultCategoryId()
810
    {
811 3
        return $this->defaultCategoryId;
812 3
    }
813
814
    /**
815
     * @param int|null $defaultCategoryId
816
     * @return ProductInterface
817
     */
818 3
    public function setDefaultCategoryId($defaultCategoryId)
819
    {
820 3
        $this->defaultCategoryId = $defaultCategoryId;
821
        return $this;
822
    }
823
824
    /**
825
     * @return array|null
826
     */
827 3
    public function getDisabledVariantIdList()
828
    {
829 3
        return $this->disabledVariantIdList;
830 3
    }
831
832
    /**
833
     * @param array|null $disabledVariantIdList
834
     * @return ProductInterface
835
     */
836 3
    public function setDisabledVariantIdList($disabledVariantIdList)
837
    {
838 3
        $this->disabledVariantIdList = $disabledVariantIdList;
839
        return $this;
840
    }
841
842
    /**
843
     * @return null|string
844
     */
845 3
    public function getEdbPriserProductNumber()
846
    {
847 3
        return $this->edbPriserProductNumber;
848 3
    }
849
850
    /**
851
     * @param null|string $edbPriserProductNumber
852
     * @return ProductInterface
853
     */
854 3
    public function setEdbPriserProductNumber($edbPriserProductNumber)
855
    {
856 3
        $this->edbPriserProductNumber = $edbPriserProductNumber;
857
        return $this;
858
    }
859
860
    /**
861
     * @return null|string
862
     */
863 3
    public function getFileSaleLink()
864
    {
865 3
        return $this->fileSaleLink;
866 3
    }
867
868
    /**
869
     * @param null|string $fileSaleLink
870
     * @return ProductInterface
871
     */
872 3
    public function setFileSaleLink($fileSaleLink)
873
    {
874 3
        $this->fileSaleLink = $fileSaleLink;
875
        return $this;
876
    }
877
878
    /**
879
     * @return null|string
880
     */
881 3
    public function getGoogleFeedCategory()
882
    {
883 3
        return $this->googleFeedCategory;
884 3
    }
885
886
    /**
887
     * @param null|string $googleFeedCategory
888
     * @return ProductInterface
889
     */
890 3
    public function setGoogleFeedCategory($googleFeedCategory)
891
    {
892 3
        $this->googleFeedCategory = $googleFeedCategory;
893
        return $this;
894
    }
895
896
    /**
897
     * @return bool|null
898
     */
899 3
    public function getIsGiftCertificate()
900
    {
901 3
        return $this->isGiftCertificate;
902 3
    }
903
904
    /**
905
     * @param bool|null $isGiftCertificate
906
     * @return ProductInterface
907
     */
908 3
    public function setIsGiftCertificate($isGiftCertificate)
909
    {
910 3
        $this->isGiftCertificate = $isGiftCertificate;
911
        return $this;
912
    }
913
914
    /**
915
     * @return bool|null
916
     */
917 3
    public function getIsModified()
918
    {
919 3
        return $this->isModified;
920 3
    }
921
922
    /**
923
     * @param bool|null $isModified
924
     * @return ProductInterface
925
     */
926
    public function setIsModified($isModified)
927
    {
928
        $this->isModified = $isModified;
929
        return $this;
930
    }
931
932
    /**
933
     * @return bool|null
934
     */
935
    public function getIsRateVariants()
936
    {
937
        return $this->isRateVariants;
938
    }
939
940
    /**
941
     * @param bool|null $isRateVariants
942
     * @return ProductInterface
943
     */
944 3
    public function setIsRateVariants($isRateVariants)
945
    {
946 3
        $this->isRateVariants = $isRateVariants;
947
        return $this;
948
    }
949
950
    /**
951
     * @return bool|null
952
     */
953 3
    public function getIsReviewVariants()
954
    {
955 3
        return $this->isReviewVariants;
956 3
    }
957
958
    /**
959
     * @param bool|null $isReviewVariants
960
     * @return ProductInterface
961
     */
962 3
    public function setIsReviewVariants($isReviewVariants)
963
    {
964 3
        $this->isReviewVariants = $isReviewVariants;
965
        return $this;
966
    }
967
968
    /**
969
     * @return bool|null
970
     */
971 3
    public function getIsVariantMaster()
972
    {
973 3
        return $this->isVariantMaster;
974 3
    }
975
976
    /**
977
     * @param bool|null $isVariantMaster
978
     * @return ProductInterface
979
     */
980 3
    public function setIsVariantMaster($isVariantMaster)
981
    {
982 3
        $this->isVariantMaster = $isVariantMaster;
983
        return $this;
984
    }
985
986
    /**
987
     * @return null|string
988
     */
989 3
    public function getLocationNumber()
990
    {
991 3
        return $this->locationNumber;
992 3
    }
993
994
    /**
995
     * @param null|string $locationNumber
996
     * @return ProductInterface
997
     */
998 3
    public function setLocationNumber($locationNumber)
999
    {
1000 3
        $this->locationNumber = $locationNumber;
1001
        return $this;
1002
    }
1003
1004
    /**
1005
     * @return array|null
1006
     */
1007 3
    public function getManufacturereIdList()
1008
    {
1009 3
        return $this->manufacturereIdList;
1010 3
    }
1011
1012
    /**
1013
     * @param array|null $manufacturereIdList
1014
     * @return ProductInterface
1015
     */
1016 3
    public function setManufacturereIdList($manufacturereIdList)
1017
    {
1018 3
        $this->manufacturereIdList = $manufacturereIdList;
1019
        return $this;
1020
    }
1021
1022
    /**
1023
     * @return int|null
1024
     */
1025 3
    public function getMaxBuyAmount()
1026
    {
1027 3
        return $this->maxBuyAmount;
1028 3
    }
1029
1030
    /**
1031
     * @param int|null $maxBuyAmount
1032
     * @return ProductInterface
1033
     */
1034 3
    public function setMaxBuyAmount($maxBuyAmount)
1035
    {
1036 3
        $this->maxBuyAmount = $maxBuyAmount;
1037
        return $this;
1038
    }
1039
1040
    /**
1041
     * @return int|null
1042
     */
1043 3
    public function getMinBuyAmount()
1044
    {
1045 3
        return $this->minBuyAmount;
1046 3
    }
1047
1048
    /**
1049
     * @param int|null $minBuyAmount
1050
     * @return ProductInterface
1051
     */
1052
    public function setMinBuyAmount($minBuyAmount)
1053
    {
1054
        $this->minBuyAmount = $minBuyAmount;
1055
        return $this;
1056
    }
1057
1058
    /**
1059
     * @return int|null
1060
     */
1061
    public function getMinBuyAmountB2B()
1062
    {
1063
        return $this->minBuyAmountB2B;
1064
    }
1065
1066
    /**
1067
     * @param int|null $minBuyAmountB2B
1068
     * @return ProductInterface
1069
     */
1070 3
    public function setMinBuyAmountB2B($minBuyAmountB2B)
1071
    {
1072 3
        $this->minBuyAmountB2B = $minBuyAmountB2B;
1073
        return $this;
1074
    }
1075
1076
    /**
1077
     * @return string
1078
     */
1079 3
    public function getNumber()
1080
    {
1081 3
        return (string)$this->number;
1082 3
    }
1083
1084
    /**
1085
     * @param string $number
1086
     * @return ProductInterface
1087
     */
1088 3
    public function setNumber(string $number)
1089
    {
1090 3
        $this->number = $number;
1091
        return $this;
1092
    }
1093
1094
    /**
1095
     * @return null|string
1096
     */
1097 3
    public function getPicture()
1098
    {
1099 3
        return $this->picture;
1100 3
    }
1101
1102
    /**
1103
     * @param null|string $picture
1104
     * @return ProductInterface
1105
     */
1106 3
    public function setPicture($picture)
1107
    {
1108 3
        $this->picture = $picture;
1109
        return $this;
1110
    }
1111
1112
    /**
1113
     * @return int|null
1114
     */
1115 3
    public function getSalesCount()
1116
    {
1117 3
        return $this->salesCount;
1118 3
    }
1119
1120
    /**
1121
     * @param int|null $salesCount
1122
     * @return ProductInterface
1123
     */
1124 3
    public function setSalesCount($salesCount)
1125
    {
1126 3
        $this->salesCount = $salesCount;
1127
        return $this;
1128
    }
1129
1130
    /**
1131
     * @return array|null
1132
     */
1133 3
    public function getSegmentIdList()
1134
    {
1135 3
        return $this->segmentIdList;
1136 3
    }
1137
1138
    /**
1139
     * @param array|null $segmentIdList
1140
     * @return ProductInterface
1141
     */
1142 3
    public function setSegmentIdList($segmentIdList)
1143
    {
1144 3
        $this->segmentIdList = $segmentIdList;
1145
        return $this;
1146
    }
1147
1148
    /**
1149
     * @return int|null
1150
     */
1151 3
    public function getSortOrder()
1152
    {
1153 3
        return $this->sortOrder;
1154 3
    }
1155
1156
    /**
1157
     * @param int|null $sortOrder
1158
     * @return ProductInterface
1159
     */
1160 3
    public function setSortOrder($sortOrder)
1161
    {
1162 3
        $this->sortOrder = $sortOrder;
1163
        return $this;
1164
    }
1165
1166
    /**
1167
     * @return int|null
1168
     */
1169 3
    public function getStockCount()
1170
    {
1171 3
        return $this->stockCount;
1172 3
    }
1173
1174
    /**
1175
     * @param int|null $stockCount
1176
     * @return ProductInterface
1177
     */
1178
    public function setStockCount($stockCount)
1179
    {
1180
        $this->stockCount = $stockCount;
1181
        return $this;
1182
    }
1183
1184
    /**
1185
     * @return int|null
1186
     */
1187
    public function getStockLimit()
1188
    {
1189
        return $this->stockLimit;
1190
    }
1191
1192
    /**
1193
     * @param int|null $stockLimit
1194
     * @return ProductInterface
1195
     */
1196
    public function setStockLimit($stockLimit)
1197
    {
1198
        $this->stockLimit = $stockLimit;
1199
        return $this;
1200
    }
1201
1202
    /**
1203
     * @return int|null
1204
     */
1205
    public function getTypeId()
1206
    {
1207
        return $this->typeId;
1208
    }
1209
1210
    /**
1211
     * @param int|null $typeId
1212
     * @return ProductInterface
1213
     */
1214 3
    public function setTypeId($typeId)
1215
    {
1216 3
        $this->typeId = $typeId;
1217
        return $this;
1218
    }
1219
1220
    /**
1221
     * @return \DateTimeImmutable|null
1222
     */
1223 3
    public function getUpdated()
1224
    {
1225 3
        return $this->updated;
1226 3
    }
1227
1228
    /**
1229
     * @param \DateTimeImmutable|null $updated
1230
     * @return ProductInterface
1231
     */
1232 3
    public function setUpdated($updated)
1233
    {
1234 3
        $this->updated = $updated;
1235
        return $this;
1236
    }
1237
1238
    /**
1239
     * @return null|string
1240
     */
1241 3
    public function getUpdatedBy()
1242
    {
1243 3
        return $this->updatedBy;
1244 3
    }
1245
1246
    /**
1247
     * @param null|string $updatedBy
1248
     * @return ProductInterface
1249
     */
1250 3
    public function setUpdatedBy($updatedBy)
1251
    {
1252 3
        $this->updatedBy = $updatedBy;
1253
        return $this;
1254
    }
1255
1256
    /**
1257
     * @return array|null
1258
     */
1259 3
    public function getVariantGroupIdList()
1260
    {
1261 3
        return $this->variantGroupIdList;
1262 3
    }
1263
1264
    /**
1265
     * @param array|null $variantGroupIdList
1266
     * @return ProductInterface
1267
     */
1268
    public function setVariantGroupIdList($variantGroupIdList)
1269
    {
1270
        $this->variantGroupIdList = $variantGroupIdList;
1271
        return $this;
1272
    }
1273
1274
    /**
1275
     * @return array|null
1276
     */
1277
    public function getVariantIdList()
1278
    {
1279
        return $this->variantIdList;
1280
    }
1281
1282
    /**
1283
     * @param array|null $variantIdList
1284
     * @return ProductInterface
1285
     */
1286
    public function setVariantIdList($variantIdList)
1287
    {
1288
        $this->variantIdList = $variantIdList;
1289
        return $this;
1290
    }
1291
1292
    /**
1293
     * @return int|null
1294
     */
1295
    public function getVariantMasterId()
1296
    {
1297
        return $this->variantMasterId;
1298
    }
1299
1300
    /**
1301
     * @param int|null $variantMasterId
1302
     * @return ProductInterface
1303
     */
1304
    public function setVariantMasterId($variantMasterId)
1305
    {
1306
        $this->variantMasterId = $variantMasterId;
1307
        return $this;
1308
    }
1309
1310
    /**
1311
     * @return null|string
1312
     */
1313
    public function getVendorNumber()
1314
    {
1315
        return $this->vendorNumber;
1316
    }
1317
1318
    /**
1319
     * @param null|string $vendorNumber
1320
     * @return ProductInterface
1321
     */
1322
    public function setVendorNumber($vendorNumber)
1323
    {
1324
        $this->vendorNumber = $vendorNumber;
1325
        return $this;
1326
    }
1327
1328
    /**
1329
     * @return int|null
1330
     */
1331
    public function getWeight()
1332
    {
1333
        return $this->weight;
1334
    }
1335
1336
    /**
1337
     * @param int|null $weight
1338
     * @return ProductInterface
1339
     */
1340
    public function setWeight($weight)
1341
    {
1342
        $this->weight = $weight;
1343
        return $this;
1344
    }
1345
1346
    /**
1347
     * @return ArrayCollection|Category[]
1348
     */
1349
    public function getCategories()
1350
    {
1351
        return $this->categories;
1352
    }
1353
1354
    /**
1355
     * @param ArrayCollection|Category[] $categories
1356
     * @return ProductInterface
1357
     */
1358
    public function setCategories($categories)
1359
    {
1360
        $this->categories = $categories;
1361
        return $this;
1362
    }
1363
1364
    /**
1365
     * @return ArrayCollection|Variant[]
1366
     */
1367
    public function getDisabledVariants()
1368
    {
1369
        return $this->disabledVariants;
1370
    }
1371
1372
    /**
1373
     * @param ArrayCollection|Variant[] $disabledVariants
1374
     * @return ProductInterface
1375
     */
1376
    public function setDisabledVariants($disabledVariants)
1377
    {
1378
        $this->disabledVariants = $disabledVariants;
1379
        return $this;
1380
    }
1381
1382
    /**
1383
     * @return ArrayCollection|Manufacturer[]
1384
     */
1385
    public function getManufacturers()
1386
    {
1387
        return $this->manufacturers;
1388
    }
1389
1390
    /**
1391
     * @param ArrayCollection|Manufacturer[] $manufacturers
1392
     * @return ProductInterface
1393
     */
1394
    public function setManufacturers($manufacturers)
1395
    {
1396
        $this->manufacturers = $manufacturers;
1397
        return $this;
1398
    }
1399
1400
    /**
1401
     * @return ArrayCollection|Medium[]
1402
     */
1403
    public function getMedia()
1404
    {
1405
        return $this->media;
1406
    }
1407
1408
    /**
1409
     * @param ArrayCollection|Medium[] $media
1410
     * @return ProductInterface
1411
     */
1412
    public function setMedia($media)
1413
    {
1414
        $this->media = $media;
1415
        return $this;
1416
    }
1417
1418
    /**
1419
     * @return ArrayCollection|Price[]
1420
     */
1421
    public function getPrices()
1422
    {
1423
        return $this->prices;
1424
    }
1425
1426
    /**
1427
     * @param ArrayCollection|Price[] $prices
1428
     * @return ProductInterface
1429
     */
1430
    public function setPrices($prices)
1431
    {
1432
        $this->prices = $prices;
1433
        return $this;
1434
    }
1435
1436
    /**
1437
     * @return ArrayCollection|ProductRelation[]
1438
     */
1439
    public function getProductRelations()
1440
    {
1441
        return $this->productRelations;
1442
    }
1443
1444
    /**
1445
     * @param ArrayCollection|ProductRelation[] $productRelations
1446
     * @return ProductInterface
1447
     */
1448
    public function setProductRelations($productRelations)
1449
    {
1450
        $this->productRelations = $productRelations;
1451
        return $this;
1452
    }
1453
1454
    /**
1455
     * @return ProductTypeInterface
1456
     */
1457
    public function getProductType(): ProductTypeInterface
1458
    {
1459
        return $this->productType;
1460
    }
1461
1462
    /**
1463
     * @param ProductType $productType
1464
     * @return ProductInterface
1465
     */
1466
    public function setProductType(ProductType $productType)
1467
    {
1468
        $this->productType = $productType;
1469
        return $this;
1470
    }
1471
1472
    /**
1473
     * @return ArrayCollection|Segment[]
1474
     */
1475
    public function getSegments()
1476
    {
1477
        return $this->segments;
1478
    }
1479
1480
    /**
1481
     * @param ArrayCollection|Segment[] $segments
1482
     * @return ProductInterface
1483
     */
1484
    public function setSegments($segments)
1485
    {
1486
        $this->segments = $segments;
1487
        return $this;
1488
    }
1489
1490
    /**
1491
     * @return ArrayCollection|VariantGroup[]
1492
     */
1493
    public function getVariantGroups()
1494
    {
1495
        return $this->variantGroups;
1496
    }
1497
1498
    /**
1499
     * @param ArrayCollection|VariantGroup[] $variantGroups
1500
     * @return ProductInterface
1501
     */
1502
    public function setVariantGroups($variantGroups)
1503
    {
1504
        $this->variantGroups = $variantGroups;
1505
        return $this;
1506
    }
1507
1508
    /**
1509
     * @return ArrayCollection|Variant[]
1510
     */
1511
    public function getVariants()
1512
    {
1513
        return $this->variants;
1514
    }
1515
1516
    /**
1517
     * @param ArrayCollection|Variant[] $variants
1518
     * @return ProductInterface
1519
     */
1520
    public function setVariants($variants)
1521
    {
1522
        $this->variants = $variants;
1523
        return $this;
1524
    }
1525
1526
    /**
1527
     * @return Product|null
1528
     */
1529
    public function getParent(): ?Product
1530
    {
1531
        return $this->parent;
1532
    }
1533
1534
    /**
1535
     * @param Product|null $parent
1536
     * @return Product
1537
     */
1538
    public function setParent(?Product $parent)
1539
    {
1540
        $this->parent = $parent;
1541
        return $this;
1542
    }
1543
1544
    /**
1545
     * @return ArrayCollection|Product[]
1546
     */
1547
    public function getChildren()
1548
    {
1549
        return $this->children;
1550
    }
1551
1552
    /**
1553
     * @param ArrayCollection|Product[] $children
1554
     * @return Product
1555
     */
1556
    public function setChildren($children)
1557
    {
1558
        $this->children = $children;
1559
        return $this;
1560
    }
1561
}
1562