Completed
Push — master ( 6fc36f...2a3f70 )
by Joachim
52:46 queued 37:35
created

Product::clearVariantGroups()   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(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="string", length=191)
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")
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\JoinTable(name="ldf_product_manufacturer")
335
     * @ORM\ManyToMany(cascade={"persist"}, inversedBy="products", targetEntity="Manufacturer")
336
     */
337
    protected $manufacturers;
338
339
    /**
340
     * @var Medium[]|ArrayCollection
341
     */
342
    protected $media;
343
344
    /**
345
     * Some products in Dandomain doesn't have prices because they are not really products, i.e. discounts, shipping info etc
346
     * Dandomain treat these as products on an order, which of course is wrong, but we handle them.
347
     *
348
     * @var bool
349
     *
350
     * @ORM\Column(type="boolean")
351
     */
352
    protected $priceLess;
353
354
    /**
355
     * @var PriceInterface[]|ArrayCollection
356
     *
357
     * @ORM\OneToMany(targetEntity="Price", mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
358
     */
359
    protected $prices;
360
361
    /**
362
     * @var ProductRelation[]|ArrayCollection
363
     */
364
    protected $productRelations;
365
366
    /**
367
     * @var ProductType
368
     */
369
    protected $productType;
370
371
    /**
372
     * @var Segment[]|ArrayCollection
373
     */
374
    protected $segments;
375
376
    /**
377
     * @var VariantGroup[]|ArrayCollection
378
     *
379
     * @ORM\JoinTable(name="ldf_product_variant_group")
380
     * @ORM\ManyToMany(cascade={"persist"}, inversedBy="products", targetEntity="VariantGroup")
381
     */
382
    protected $variantGroups;
383
384
    /**
385
     * @var Variant[]|ArrayCollection
386
     */
387
    protected $variants;
388
389
    /**
390 12
     * This is the master for this product.
391
     *
392 12
     * @var Product|null
393 12
     *
394 12
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="children")
395 12
     */
396 12
    protected $parent;
397 12
398 12
    /**
399 12
     * This is the children (i.e. variants) of this products.
400 12
     *
401 12
     * @var Product[]|ArrayCollection
402 12
     *
403
     * @ORM\OneToMany(targetEntity="Product", mappedBy="parent")
404
     */
405
    protected $children;
406
407
    public function __construct()
408
    {
409
        $this->priceLess = false;
410
        $this->categories = new ArrayCollection();
411
        $this->disabledVariants = new ArrayCollection();
412
        $this->manufacturers = new ArrayCollection();
413
        $this->media = new ArrayCollection();
414
        $this->prices = new ArrayCollection();
415
        $this->productRelations = new ArrayCollection();
416
        $this->segments = new ArrayCollection();
417
        $this->variants = new ArrayCollection();
418
        $this->variantGroups = new ArrayCollection();
419
        $this->children = new ArrayCollection();
420
    }
421
422
    public function __toString()
423
    {
424
        return (string) $this->number;
425 3
    }
426
427 3
    /**
428 3
     * @ORM\PrePersist()
429
     * @ORM\PreUpdate()
430
     */
431 3
    public function validate()
432 3
    {
433
        Assert::that($this->number)
434
            ->string('The number needs to be string', 'number')
435 3
            ->maxLength(191, 'The number must have a max length of 191');
436 3
        Assert::thatNullOr($this->externalId)->integer('The external id can only be null or an integer', 'externalId');
437
438
        if (is_null($this->externalId)) {
0 ignored issues
show
introduced by
The condition is_null($this->externalId) can never be true.
Loading history...
439
            Assert::that($this->isDeleted())->true('The external id can only be null if the product is marked as deleted', 'externalId');
440
        }
441
442
        if (!$this->priceLess) {
443
            Assert::that($this->prices->count())->greaterThan(0, 'When the product is not "price less" the product needs to have at least one price');
444
        }
445
    }
446
447
    public function hydrate(array $data, bool $useConversions = false, $scalarsOnly = true)
448
    {
449
        if (isset($data['created'])) {
450
            $data['created'] = $this->getDateTimeFromJson($data['created']);
451
        }
452
453
        if (isset($data['updated'])) {
454
            $data['updated'] = $this->getDateTimeFromJson($data['updated']);
455
        }
456
457
        parent::hydrate($data, $useConversions, $scalarsOnly);
458
    }
459
460
    /*
461
     * Collection/relation methods
462
     */
463
464
    public function addDisabledVariant(VariantInterface $variant): ProductInterface
465
    {
466
        if (!$this->disabledVariants->contains($variant)) {
467
            $this->disabledVariants->add($variant);
468
        }
469
470
        return $this;
471
    }
472
473
    public function addMedium(MediumInterface $medium): ProductInterface
474
    {
475
        if (!$this->media->contains($medium)) {
476
            $this->media->add($medium);
477
        }
478
479
        return $this;
480
    }
481
482
    public function addCategory(CategoryInterface $category): ProductInterface
483
    {
484
        if (!$this->categories->contains($category)) {
485
            $this->categories->add($category);
486
        }
487
488
        return $this;
489
    }
490
491
    public function addManufacturer(ManufacturerInterface $manufacturer): ProductInterface
492
    {
493
        if (!$this->hasManufacturer($manufacturer)) {
494
            $this->manufacturers->add($manufacturer);
495
        }
496
497
        return $this;
498
    }
499
500
    public function removeManufacturer(ManufacturerInterface $manufacturer): bool
501
    {
502
        return $this->manufacturers->removeElement($manufacturer);
503
    }
504
505
    public function hasManufacturer(ManufacturerInterface $manufacturer): bool
506
    {
507
        return $this->manufacturers->exists(function ($key, ManufacturerInterface $element) use ($manufacturer) {
508
            return $element->getExternalId() === $manufacturer->getExternalId();
509
        });
510
    }
511
512
    public function addVariantGroup(VariantGroupInterface $variantGroup): ProductInterface
513
    {
514
        if (!$this->hasVariantGroup($variantGroup)) {
515
            $this->variantGroups->add($variantGroup);
516
        }
517
518
        return $this;
519
    }
520
521
    public function removeVariantGroup(VariantGroupInterface $variantGroup): bool
522
    {
523
        return $this->variantGroups->removeElement($variantGroup);
524
    }
525
526
    public function clearVariantGroups() : void
527
    {
528
        $this->variantGroups->clear();
529
    }
530
531
    public function hasVariantGroup($variantGroup): bool
532
    {
533
        if ($variantGroup instanceof VariantGroupInterface) {
534
            $variantGroup = $variantGroup->getExternalId();
535
        }
536
537
        return $this->variantGroups->exists(function ($key, VariantGroupInterface $element) use ($variantGroup) {
538
            return $element->getExternalId() === $variantGroup;
539
        });
540
    }
541
542
    public function addPrice(PriceInterface $price): ProductInterface
543
    {
544
        if (!$this->prices->contains($price)) {
545
            $this->prices->add($price);
546
            $price->setProduct($this);
547
        }
548
549
        return $this;
550
    }
551
552
    /**
553
     * @param PriceInterface[] $prices
554
     */
555
    public function updatePrices(array $prices): void
556
    {
557
        // this holds the final array of prices, whether updated or added
558
        $finalPrices = [];
559
560
        foreach ($prices as $price) {
561
            $existingPrice = $this->findPrice($price);
562
563
            if ($existingPrice) {
564
                $existingPrice->copyProperties($price);
565
                $existingPrice->setProduct($this);
566
                $finalPrices[] = $existingPrice;
567
            } else {
568
                $this->addPrice($price);
569
                $price->setProduct($this);
570
                $finalPrices[] = $price;
571
            }
572
        }
573
574
        foreach ($this->prices as $price) {
575
            if (!in_array($price, $finalPrices, true)) {
576
                $this->removePrice($price);
577
            }
578
        }
579
    }
580
581
    public function removePrice(PriceInterface $price): bool
582
    {
583
        $price->setProduct(null);
584 6
585
        return $this->prices->removeElement($price);
586 6
    }
587
588
    /**
589
     * Will try to find a price based on currency.
590
     *
591
     * @param string|\Money\Currency|CurrencyInterface $currency
592
     *
593 3
     * @return PriceInterface|null
594
     */
595 3
    public function findPriceByCurrency($currency): ?PriceInterface
596 3
    {
597
        if ($currency instanceof \Money\Currency) {
598
            $currency = $currency->getCode();
599
        } 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...
600
            $currency = $currency->getIsoCodeAlpha();
601
        }
602 6
603
        if (!is_string($currency)) {
0 ignored issues
show
introduced by
The condition ! is_string($currency) can never be true.
Loading history...
604 6
            throw new \InvalidArgumentException('$currency has to be a string');
605
        }
606
607
        foreach ($this->prices as $price) {
608
            if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
609
                return $price;
610
            }
611 3
        }
612
613 3
        return null;
614 3
    }
615
616
    public function addProductRelation(ProductRelationInterface $productRelation): ProductInterface
617
    {
618
        if (!$this->productRelations->contains($productRelation)) {
619
            $this->productRelations->add($productRelation);
620 3
        }
621
622 3
        return $this;
623
    }
624
625
    public function addSegment(SegmentInterface $segment): ProductInterface
626
    {
627
        if (!$this->segments->contains($segment)) {
628
            $this->segments->add($segment);
629 3
        }
630
631 3
        return $this;
632 3
    }
633
634
    public function addVariant(VariantInterface $variant): ProductInterface
635
    {
636
        if (!$this->variants->contains($variant)) {
637
            $this->variants->add($variant);
638
        }
639
640
        return $this;
641
    }
642
643
    public function addChild(ProductInterface $product): ProductInterface
644
    {
645
        if (!$this->hasChild($product)) {
646
            $this->children->add($product);
647
            $product->setParent($this);
648
        }
649
650
        return $this;
651
    }
652
653
    public function removeChild(ProductInterface $product): bool
654
    {
655
        $product->setParent(null);
656 3
657
        return $this->children->removeElement($product);
658 3
    }
659
660
    public function hasChild($product): bool
661
    {
662
        if ($product instanceof ProductInterface) {
663
            $product = $product->getExternalId();
664
        }
665 3
666
        return $this->children->exists(function ($key, ProductInterface $element) use ($product) {
667 3
            return $element->getExternalId() === $product;
668 3
        });
669
    }
670
671
    /*
672
     * Getters / Setters
673
     */
674 3
675
    /**
676 3
     * @return int
677
     */
678
    public function getId(): int
679
    {
680
        return (int) $this->id;
681
    }
682
683 3
    /**
684
     * @param int $id
685 3
     *
686 3
     * @return ProductInterface
687
     */
688
    public function setId(int $id)
689
    {
690
        $this->id = $id;
691
692 3
        return $this;
693
    }
694 3
695
    /**
696
     * @return int
697
     */
698
    public function getExternalId(): int
699
    {
700
        return (int) $this->externalId;
701 3
    }
702
703 3
    /**
704 3
     * @param int $externalId
705
     *
706
     * @return ProductInterface
707
     */
708
    public function setExternalId(int $externalId)
709
    {
710 3
        $this->externalId = $externalId;
711
712 3
        return $this;
713
    }
714
715
    /**
716
     * @return null|string
717
     */
718
    public function getBarCodeNumber()
719 3
    {
720
        return $this->barCodeNumber;
721 3
    }
722 3
723
    /**
724
     * @param null|string $barCodeNumber
725
     *
726
     * @return ProductInterface
727
     */
728 3
    public function setBarCodeNumber($barCodeNumber)
729
    {
730 3
        $this->barCodeNumber = $barCodeNumber;
731
732
        return $this;
733
    }
734
735
    /**
736
     * @return array|null
737 3
     */
738
    public function getCategoryIdList()
739 3
    {
740 3
        return $this->categoryIdList;
741
    }
742
743
    /**
744
     * @param array|null $categoryIdList
745
     *
746
     * @return ProductInterface
747
     */
748
    public function setCategoryIdList($categoryIdList)
749
    {
750
        $this->categoryIdList = $categoryIdList;
751
752
        return $this;
753
    }
754
755
    /**
756
     * @return null|string
757
     */
758
    public function getComments()
759
    {
760
        return $this->comments;
761
    }
762
763
    /**
764 3
     * @param null|string $comments
765
     *
766 3
     * @return ProductInterface
767
     */
768
    public function setComments($comments)
769
    {
770
        $this->comments = $comments;
771
772
        return $this;
773 3
    }
774
775 3
    /**
776 3
     * @return float|null
777
     */
778
    public function getCostPrice()
779
    {
780
        return $this->costPrice;
781
    }
782 3
783
    /**
784 3
     * @param float|null $costPrice
785
     *
786
     * @return ProductInterface
787
     */
788
    public function setCostPrice($costPrice)
789
    {
790
        $this->costPrice = $costPrice;
791 3
792
        return $this;
793 3
    }
794 3
795
    /**
796
     * @return \DateTimeImmutable|null
797
     */
798
    public function getCreated()
799
    {
800 3
        return $this->created;
801
    }
802 3
803
    /**
804
     * @param \DateTimeImmutable|null $created
805
     *
806
     * @return ProductInterface
807
     */
808
    public function setCreated($created)
809 3
    {
810
        $this->created = $created;
811 3
812 3
        return $this;
813
    }
814
815
    /**
816
     * @return null|string
817
     */
818 3
    public function getCreatedBy()
819
    {
820 3
        return $this->createdBy;
821
    }
822
823
    /**
824
     * @param null|string $createdBy
825
     *
826
     * @return ProductInterface
827 3
     */
828
    public function setCreatedBy($createdBy)
829 3
    {
830 3
        $this->createdBy = $createdBy;
831
832
        return $this;
833
    }
834
835
    /**
836 3
     * @return int|null
837
     */
838 3
    public function getDefaultCategoryId()
839
    {
840
        return $this->defaultCategoryId;
841
    }
842
843
    /**
844
     * @param int|null $defaultCategoryId
845 3
     *
846
     * @return ProductInterface
847 3
     */
848 3
    public function setDefaultCategoryId($defaultCategoryId)
849
    {
850
        $this->defaultCategoryId = $defaultCategoryId;
851
852
        return $this;
853
    }
854 3
855
    /**
856 3
     * @return array|null
857
     */
858
    public function getDisabledVariantIdList()
859
    {
860
        return $this->disabledVariantIdList;
861
    }
862
863 3
    /**
864
     * @param array|null $disabledVariantIdList
865 3
     *
866 3
     * @return ProductInterface
867
     */
868
    public function setDisabledVariantIdList($disabledVariantIdList)
869
    {
870
        $this->disabledVariantIdList = $disabledVariantIdList;
871
872 3
        return $this;
873
    }
874 3
875
    /**
876
     * @return null|string
877
     */
878
    public function getEdbPriserProductNumber()
879
    {
880
        return $this->edbPriserProductNumber;
881 3
    }
882
883 3
    /**
884 3
     * @param null|string $edbPriserProductNumber
885
     *
886
     * @return ProductInterface
887
     */
888
    public function setEdbPriserProductNumber($edbPriserProductNumber)
889
    {
890 3
        $this->edbPriserProductNumber = $edbPriserProductNumber;
891
892 3
        return $this;
893
    }
894
895
    /**
896
     * @return null|string
897
     */
898
    public function getFileSaleLink()
899 3
    {
900
        return $this->fileSaleLink;
901 3
    }
902 3
903
    /**
904
     * @param null|string $fileSaleLink
905
     *
906
     * @return ProductInterface
907
     */
908 3
    public function setFileSaleLink($fileSaleLink)
909
    {
910 3
        $this->fileSaleLink = $fileSaleLink;
911
912
        return $this;
913
    }
914
915
    /**
916
     * @return null|string
917 3
     */
918
    public function getGoogleFeedCategory()
919 3
    {
920 3
        return $this->googleFeedCategory;
921
    }
922
923
    /**
924
     * @param null|string $googleFeedCategory
925
     *
926
     * @return ProductInterface
927
     */
928
    public function setGoogleFeedCategory($googleFeedCategory)
929
    {
930
        $this->googleFeedCategory = $googleFeedCategory;
931
932
        return $this;
933
    }
934
935
    /**
936
     * @return bool|null
937
     */
938
    public function getIsGiftCertificate()
939
    {
940
        return $this->isGiftCertificate;
941
    }
942
943
    /**
944 3
     * @param bool|null $isGiftCertificate
945
     *
946 3
     * @return ProductInterface
947
     */
948
    public function setIsGiftCertificate($isGiftCertificate)
949
    {
950
        $this->isGiftCertificate = $isGiftCertificate;
951
952
        return $this;
953 3
    }
954
955 3
    /**
956 3
     * @return bool|null
957
     */
958
    public function getIsModified()
959
    {
960
        return $this->isModified;
961
    }
962 3
963
    /**
964 3
     * @param bool|null $isModified
965
     *
966
     * @return ProductInterface
967
     */
968
    public function setIsModified($isModified)
969
    {
970
        $this->isModified = $isModified;
971 3
972
        return $this;
973 3
    }
974 3
975
    /**
976
     * @return bool|null
977
     */
978
    public function getIsRateVariants()
979
    {
980 3
        return $this->isRateVariants;
981
    }
982 3
983
    /**
984
     * @param bool|null $isRateVariants
985
     *
986
     * @return ProductInterface
987
     */
988
    public function setIsRateVariants($isRateVariants)
989 3
    {
990
        $this->isRateVariants = $isRateVariants;
991 3
992 3
        return $this;
993
    }
994
995
    /**
996
     * @return bool|null
997
     */
998 3
    public function getIsReviewVariants()
999
    {
1000 3
        return $this->isReviewVariants;
1001
    }
1002
1003
    /**
1004
     * @param bool|null $isReviewVariants
1005
     *
1006
     * @return ProductInterface
1007 3
     */
1008
    public function setIsReviewVariants($isReviewVariants)
1009 3
    {
1010 3
        $this->isReviewVariants = $isReviewVariants;
1011
1012
        return $this;
1013
    }
1014
1015
    /**
1016 3
     * @return bool|null
1017
     */
1018 3
    public function getIsVariantMaster()
1019
    {
1020
        return $this->isVariantMaster;
1021
    }
1022
1023
    /**
1024
     * @param bool|null $isVariantMaster
1025 3
     *
1026
     * @return ProductInterface
1027 3
     */
1028 3
    public function setIsVariantMaster($isVariantMaster)
1029
    {
1030
        $this->isVariantMaster = $isVariantMaster;
1031
1032
        return $this;
1033
    }
1034 3
1035
    /**
1036 3
     * @return null|string
1037
     */
1038
    public function getLocationNumber()
1039
    {
1040
        return $this->locationNumber;
1041
    }
1042
1043 3
    /**
1044
     * @param null|string $locationNumber
1045 3
     *
1046 3
     * @return ProductInterface
1047
     */
1048
    public function setLocationNumber($locationNumber)
1049
    {
1050
        $this->locationNumber = $locationNumber;
1051
1052
        return $this;
1053
    }
1054
1055
    /**
1056
     * @return array|null
1057
     */
1058
    public function getManufacturereIdList()
1059
    {
1060
        return $this->manufacturereIdList;
1061
    }
1062
1063
    /**
1064
     * @param array|null $manufacturereIdList
1065
     *
1066
     * @return ProductInterface
1067
     */
1068
    public function setManufacturereIdList($manufacturereIdList)
1069
    {
1070 3
        $this->manufacturereIdList = $manufacturereIdList;
1071
1072 3
        return $this;
1073
    }
1074
1075
    /**
1076
     * @return int|null
1077
     */
1078
    public function getMaxBuyAmount()
1079 3
    {
1080
        return $this->maxBuyAmount;
1081 3
    }
1082 3
1083
    /**
1084
     * @param int|null $maxBuyAmount
1085
     *
1086
     * @return ProductInterface
1087
     */
1088 3
    public function setMaxBuyAmount($maxBuyAmount)
1089
    {
1090 3
        $this->maxBuyAmount = $maxBuyAmount;
1091
1092
        return $this;
1093
    }
1094
1095
    /**
1096
     * @return int|null
1097 3
     */
1098
    public function getMinBuyAmount()
1099 3
    {
1100 3
        return $this->minBuyAmount;
1101
    }
1102
1103
    /**
1104
     * @param int|null $minBuyAmount
1105
     *
1106 3
     * @return ProductInterface
1107
     */
1108 3
    public function setMinBuyAmount($minBuyAmount)
1109
    {
1110
        $this->minBuyAmount = $minBuyAmount;
1111
1112
        return $this;
1113
    }
1114
1115 3
    /**
1116
     * @return int|null
1117 3
     */
1118 3
    public function getMinBuyAmountB2B()
1119
    {
1120
        return $this->minBuyAmountB2B;
1121
    }
1122
1123
    /**
1124 3
     * @param int|null $minBuyAmountB2B
1125
     *
1126 3
     * @return ProductInterface
1127
     */
1128
    public function setMinBuyAmountB2B($minBuyAmountB2B)
1129
    {
1130
        $this->minBuyAmountB2B = $minBuyAmountB2B;
1131
1132
        return $this;
1133 3
    }
1134
1135 3
    /**
1136 3
     * @return string
1137
     */
1138
    public function getNumber()
1139
    {
1140
        return (string) $this->number;
1141
    }
1142 3
1143
    /**
1144 3
     * @param string $number
1145
     *
1146
     * @return ProductInterface
1147
     */
1148
    public function setNumber(string $number)
1149
    {
1150
        $this->number = $number;
1151 3
1152
        return $this;
1153 3
    }
1154 3
1155
    /**
1156
     * @return null|string
1157
     */
1158
    public function getPicture()
1159
    {
1160 3
        return $this->picture;
1161
    }
1162 3
1163
    /**
1164
     * @param null|string $picture
1165
     *
1166
     * @return ProductInterface
1167
     */
1168
    public function setPicture($picture)
1169 3
    {
1170
        $this->picture = $picture;
1171 3
1172 3
        return $this;
1173
    }
1174
1175
    /**
1176
     * @return int|null
1177
     */
1178
    public function getSalesCount()
1179
    {
1180
        return $this->salesCount;
1181
    }
1182
1183
    /**
1184
     * @param int|null $salesCount
1185
     *
1186
     * @return ProductInterface
1187
     */
1188
    public function setSalesCount($salesCount)
1189
    {
1190
        $this->salesCount = $salesCount;
1191
1192
        return $this;
1193
    }
1194
1195
    /**
1196
     * @return array|null
1197
     */
1198
    public function getSegmentIdList()
1199
    {
1200
        return $this->segmentIdList;
1201
    }
1202
1203
    /**
1204
     * @param array|null $segmentIdList
1205
     *
1206
     * @return ProductInterface
1207
     */
1208
    public function setSegmentIdList($segmentIdList)
1209
    {
1210
        $this->segmentIdList = $segmentIdList;
1211
1212
        return $this;
1213
    }
1214 3
1215
    /**
1216 3
     * @return int|null
1217
     */
1218
    public function getSortOrder()
1219
    {
1220
        return $this->sortOrder;
1221
    }
1222
1223 3
    /**
1224
     * @param int|null $sortOrder
1225 3
     *
1226 3
     * @return ProductInterface
1227
     */
1228
    public function setSortOrder($sortOrder)
1229
    {
1230
        $this->sortOrder = $sortOrder;
1231
1232 3
        return $this;
1233
    }
1234 3
1235
    /**
1236
     * @return int|null
1237
     */
1238
    public function getStockCount()
1239
    {
1240
        return $this->stockCount;
1241 3
    }
1242
1243 3
    /**
1244 3
     * @param int|null $stockCount
1245
     *
1246
     * @return ProductInterface
1247
     */
1248
    public function setStockCount($stockCount)
1249
    {
1250 3
        $this->stockCount = $stockCount;
1251
1252 3
        return $this;
1253
    }
1254
1255
    /**
1256
     * @return int|null
1257
     */
1258
    public function getStockLimit()
1259 3
    {
1260
        return $this->stockLimit;
1261 3
    }
1262 3
1263
    /**
1264
     * @param int|null $stockLimit
1265
     *
1266
     * @return ProductInterface
1267
     */
1268
    public function setStockLimit($stockLimit)
1269
    {
1270
        $this->stockLimit = $stockLimit;
1271
1272
        return $this;
1273
    }
1274
1275
    /**
1276
     * @return int|null
1277
     */
1278
    public function getTypeId()
1279
    {
1280
        return $this->typeId;
1281
    }
1282
1283
    /**
1284
     * @param int|null $typeId
1285
     *
1286
     * @return ProductInterface
1287
     */
1288
    public function setTypeId($typeId)
1289
    {
1290
        $this->typeId = $typeId;
1291
1292
        return $this;
1293
    }
1294
1295
    /**
1296
     * @return \DateTimeImmutable|null
1297
     */
1298
    public function getUpdated()
1299
    {
1300
        return $this->updated;
1301
    }
1302
1303
    /**
1304
     * @param \DateTimeImmutable|null $updated
1305
     *
1306
     * @return ProductInterface
1307
     */
1308
    public function setUpdated($updated)
1309
    {
1310
        $this->updated = $updated;
1311
1312
        return $this;
1313
    }
1314
1315
    /**
1316
     * @return null|string
1317
     */
1318
    public function getUpdatedBy()
1319
    {
1320
        return $this->updatedBy;
1321
    }
1322
1323
    /**
1324
     * @param null|string $updatedBy
1325
     *
1326
     * @return ProductInterface
1327
     */
1328
    public function setUpdatedBy($updatedBy)
1329
    {
1330
        $this->updatedBy = $updatedBy;
1331
1332
        return $this;
1333
    }
1334
1335
    /**
1336
     * @return array|null
1337
     */
1338
    public function getVariantGroupIdList()
1339
    {
1340
        return $this->variantGroupIdList;
1341
    }
1342
1343
    /**
1344
     * @param array|null $variantGroupIdList
1345
     *
1346
     * @return ProductInterface
1347
     */
1348
    public function setVariantGroupIdList($variantGroupIdList)
1349
    {
1350
        $this->variantGroupIdList = $variantGroupIdList;
1351
1352
        return $this;
1353
    }
1354
1355
    /**
1356
     * @return array|null
1357
     */
1358
    public function getVariantIdList()
1359
    {
1360
        return $this->variantIdList;
1361
    }
1362
1363
    /**
1364
     * @param array|null $variantIdList
1365
     *
1366
     * @return ProductInterface
1367
     */
1368
    public function setVariantIdList($variantIdList)
1369
    {
1370
        $this->variantIdList = $variantIdList;
1371
1372
        return $this;
1373
    }
1374
1375
    /**
1376
     * @return int|null
1377
     */
1378
    public function getVariantMasterId()
1379
    {
1380
        return $this->variantMasterId;
1381
    }
1382
1383
    /**
1384
     * @param int|null $variantMasterId
1385
     *
1386
     * @return ProductInterface
1387
     */
1388
    public function setVariantMasterId($variantMasterId)
1389
    {
1390
        $this->variantMasterId = $variantMasterId;
1391
1392
        return $this;
1393
    }
1394
1395
    /**
1396
     * @return null|string
1397
     */
1398
    public function getVendorNumber()
1399
    {
1400
        return $this->vendorNumber;
1401
    }
1402
1403
    /**
1404
     * @param null|string $vendorNumber
1405
     *
1406
     * @return ProductInterface
1407
     */
1408
    public function setVendorNumber($vendorNumber)
1409
    {
1410
        $this->vendorNumber = $vendorNumber;
1411
1412
        return $this;
1413
    }
1414
1415
    /**
1416
     * @return int|null
1417
     */
1418
    public function getWeight()
1419
    {
1420
        return $this->weight;
1421
    }
1422
1423
    /**
1424
     * @param int|null $weight
1425
     *
1426
     * @return ProductInterface
1427
     */
1428
    public function setWeight($weight)
1429
    {
1430
        $this->weight = $weight;
1431
1432
        return $this;
1433
    }
1434
1435
    /**
1436
     * @return ArrayCollection|Category[]
1437
     */
1438
    public function getCategories()
1439
    {
1440
        return $this->categories;
1441
    }
1442
1443
    /**
1444
     * @param ArrayCollection|Category[] $categories
1445
     *
1446
     * @return ProductInterface
1447
     */
1448
    public function setCategories($categories)
1449
    {
1450
        $this->categories = $categories;
1451
1452
        return $this;
1453
    }
1454
1455
    /**
1456
     * @return ArrayCollection|Variant[]
1457
     */
1458
    public function getDisabledVariants()
1459
    {
1460
        return $this->disabledVariants;
1461
    }
1462
1463
    /**
1464
     * @param ArrayCollection|Variant[] $disabledVariants
1465
     *
1466
     * @return ProductInterface
1467
     */
1468
    public function setDisabledVariants($disabledVariants)
1469
    {
1470
        $this->disabledVariants = $disabledVariants;
1471
1472
        return $this;
1473
    }
1474
1475
    /**
1476
     * @return ArrayCollection|Manufacturer[]
1477
     */
1478
    public function getManufacturers()
1479
    {
1480
        return $this->manufacturers;
1481
    }
1482
1483
    /**
1484
     * @param ArrayCollection|Manufacturer[] $manufacturers
1485
     *
1486
     * @return ProductInterface
1487
     */
1488
    public function setManufacturers($manufacturers)
1489
    {
1490
        $this->manufacturers = $manufacturers;
1491
1492
        return $this;
1493
    }
1494
1495
    /**
1496
     * @return ArrayCollection|Medium[]
1497
     */
1498
    public function getMedia()
1499
    {
1500
        return $this->media;
1501
    }
1502
1503
    /**
1504
     * @param ArrayCollection|Medium[] $media
1505
     *
1506
     * @return ProductInterface
1507
     */
1508
    public function setMedia($media)
1509
    {
1510
        $this->media = $media;
1511
1512
        return $this;
1513
    }
1514
1515
    /**
1516
     * @return bool
1517
     */
1518
    public function isPriceLess(): bool
1519
    {
1520
        return $this->priceLess;
1521
    }
1522
1523
    /**
1524
     * @param bool $priceLess
1525
     *
1526
     * @return Product
1527
     */
1528
    public function setPriceLess(bool $priceLess)
1529
    {
1530
        $this->priceLess = $priceLess;
1531
1532
        return $this;
1533
    }
1534
1535
    /**
1536
     * @return ArrayCollection|Price[]
1537
     */
1538
    public function getPrices()
1539
    {
1540
        return $this->prices;
1541
    }
1542
1543
    /**
1544
     * @param ArrayCollection|Price[] $prices
1545
     *
1546
     * @return ProductInterface
1547
     */
1548
    public function setPrices($prices)
1549
    {
1550
        $this->prices = $prices;
1551
1552
        return $this;
1553
    }
1554
1555
    /**
1556
     * @return ArrayCollection|ProductRelation[]
1557
     */
1558
    public function getProductRelations()
1559
    {
1560
        return $this->productRelations;
1561
    }
1562
1563
    /**
1564
     * @param ArrayCollection|ProductRelation[] $productRelations
1565
     *
1566
     * @return ProductInterface
1567
     */
1568
    public function setProductRelations($productRelations)
1569
    {
1570
        $this->productRelations = $productRelations;
1571
1572
        return $this;
1573
    }
1574
1575
    /**
1576
     * @return ProductTypeInterface
1577
     */
1578
    public function getProductType(): ProductTypeInterface
1579
    {
1580
        return $this->productType;
1581
    }
1582
1583
    /**
1584
     * @param ProductType $productType
1585
     *
1586
     * @return ProductInterface
1587
     */
1588
    public function setProductType(ProductType $productType)
1589
    {
1590
        $this->productType = $productType;
1591
1592
        return $this;
1593
    }
1594
1595
    /**
1596
     * @return ArrayCollection|Segment[]
1597
     */
1598
    public function getSegments()
1599
    {
1600
        return $this->segments;
1601
    }
1602
1603
    /**
1604
     * @param ArrayCollection|Segment[] $segments
1605
     *
1606
     * @return ProductInterface
1607
     */
1608
    public function setSegments($segments)
1609
    {
1610
        $this->segments = $segments;
1611
1612
        return $this;
1613
    }
1614
1615
    /**
1616
     * @return ArrayCollection|VariantGroup[]
1617
     */
1618
    public function getVariantGroups()
1619
    {
1620
        return $this->variantGroups;
1621
    }
1622
1623
    /**
1624
     * @param ArrayCollection|VariantGroup[] $variantGroups
1625
     *
1626
     * @return ProductInterface
1627
     */
1628
    public function setVariantGroups($variantGroups)
1629
    {
1630
        $this->variantGroups = $variantGroups;
1631
1632
        return $this;
1633
    }
1634
1635
    /**
1636
     * @return ArrayCollection|Variant[]
1637
     */
1638
    public function getVariants()
1639
    {
1640
        return $this->variants;
1641
    }
1642
1643
    /**
1644
     * @param ArrayCollection|Variant[] $variants
1645
     *
1646
     * @return ProductInterface
1647
     */
1648
    public function setVariants($variants)
1649
    {
1650
        $this->variants = $variants;
1651
1652
        return $this;
1653
    }
1654
1655
    /**
1656
     * @return ProductInterface|null
1657
     */
1658
    public function getParent(): ?ProductInterface
1659
    {
1660
        return $this->parent;
1661
    }
1662
1663
    /**
1664
     * @param ProductInterface|null $parent
1665
     *
1666
     * @return Product
1667
     */
1668
    public function setParent(?ProductInterface $parent)
1669
    {
1670
        $this->parent = $parent;
1671
1672
        return $this;
1673
    }
1674
1675
    /**
1676
     * @return ArrayCollection|Product[]
1677
     */
1678
    public function getChildren()
1679
    {
1680
        return $this->children;
1681
    }
1682
1683
    /**
1684
     * @param ArrayCollection|Product[] $children
1685
     *
1686
     * @return Product
1687
     */
1688
    public function setChildren($children)
1689
    {
1690
        $this->children = $children;
1691
1692
        return $this;
1693
    }
1694
1695
    /**
1696
     * This method will try to find a price based on the unique constraint defined in price.
1697
     *
1698
     * @param PriceInterface $searchPrice
1699
     *
1700
     * @return PriceInterface|null
1701
     */
1702
    protected function findPrice(PriceInterface $searchPrice): ?PriceInterface
1703
    {
1704
        foreach ($this->prices as $price) {
1705
            if ($price->getAmount() == $searchPrice->getAmount() && $price->getB2bGroupId() == $searchPrice->getB2bGroupId() && $price->getCurrency()->getId() == $searchPrice->getCurrency()->getId()) {
1706
                return $price;
1707
            }
1708
        }
1709
1710
        return null;
1711
    }
1712
}
1713