Completed
Push — master ( 2a3f70...e0e633 )
by Joachim
66:06 queued 51:06
created

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