Completed
Push — master ( 778cf4...326520 )
by Joachim
13:13
created

Product::clearPrices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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