Completed
Push — master ( 47376d...bafce2 )
by Joachim
32:29 queued 17:34
created

Product::clearPrices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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