Passed
Push — master ( b7d1bc...bd1bc5 )
by Joachim
11:57
created

Product::findCategory()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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