Completed
Push — master ( d1e201...e04814 )
by Joachim
14:55
created

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