Completed
Push — master ( 256f7a...476c16 )
by Joachim
06:08
created

Product   F

Complexity

Total Complexity 167

Size/Duplication

Total Lines 1725
Duplicated Lines 0 %

Test Coverage

Coverage 43.34%

Importance

Changes 28
Bugs 3 Features 6
Metric Value
eloc 330
c 28
b 3
f 6
dl 0
loc 1725
ccs 179
cts 413
cp 0.4334
rs 2
wmc 167

131 Methods

Rating   Name   Duplication   Size   Complexity  
A getIsModified() 0 3 1
A getIsReviewVariants() 0 3 1
A __toString() 0 3 1
A setMaxBuyAmount() 0 5 1
A hasVariantGroup() 0 8 2
A getCreatedBy() 0 3 1
A addSegment() 0 7 2
A addDisabledVariant() 0 7 2
A setManufacturers() 0 5 1
A removeCategory() 0 3 1
A setPrices() 0 5 1
A getVariantIdList() 0 3 1
A getMedia() 0 3 1
A setCategories() 0 5 1
A findPriceByCurrency() 0 19 6
A getParent() 0 3 1
A findPrice() 0 9 5
A removeVariantGroup() 0 3 1
A setId() 0 5 1
A setVariantIdList() 0 5 1
A setExternalId() 0 5 1
A setDefaultCategoryId() 0 5 1
A removeManufacturer() 0 3 1
A setIsGiftCertificate() 0 5 1
A getVariants() 0 3 1
A addVariantGroup() 0 7 2
A getSalesCount() 0 3 1
A setParent() 0 5 1
A getNumber() 0 3 1
A getPicture() 0 3 1
A getVariantGroupIdList() 0 3 1
A setUpdatedBy() 0 5 1
A clearManufacturers() 0 3 1
A getUpdated() 0 3 1
A setGoogleFeedCategory() 0 5 1
A getCategories() 0 3 1
A getSegmentIdList() 0 3 1
A setComments() 0 5 1
A hasChild() 0 8 2
A clearVariantGroups() 0 3 1
A __construct() 0 12 1
A setTypeId() 0 5 1
A getLocationNumber() 0 3 1
A getManufacturers() 0 3 1
A setCostPrice() 0 5 1
A getPrices() 0 3 1
A setFileSaleLink() 0 5 1
A getCategoryIdList() 0 3 1
A setUpdated() 0 5 1
A setStockLimit() 0 5 1
A addManufacturer() 0 7 2
A setWeight() 0 5 1
A setMedia() 0 5 1
A setIsModified() 0 5 1
A getSortOrder() 0 3 1
A getTypeId() 0 3 1
A getMaxBuyAmount() 0 3 1
A setVariants() 0 5 1
A setSalesCount() 0 5 1
A getProductRelations() 0 3 1
A getFileSaleLink() 0 3 1
A getDefaultCategoryId() 0 3 1
A setVariantMasterId() 0 5 1
A setProductRelations() 0 5 1
A clearPrices() 0 7 2
A setCategoryIdList() 0 5 1
A addPrice() 0 8 2
A updateCategories() 0 24 6
A getUpdatedBy() 0 3 1
A setSegments() 0 5 1
A removeChild() 0 5 1
A getProductType() 0 3 1
A getBarCodeNumber() 0 3 1
A getId() 0 3 1
A getIsVariantMaster() 0 3 1
A getStockLimit() 0 3 1
A setMinBuyAmount() 0 5 1
A getVariantMasterId() 0 3 1
A setVendorNumber() 0 5 1
A setDisabledVariantIdList() 0 5 1
A setPicture() 0 5 1
A getGoogleFeedCategory() 0 3 1
A addProductRelation() 0 7 2
A getIsRateVariants() 0 3 1
A hydrate() 0 11 3
A getIsGiftCertificate() 0 3 1
A getDisabledVariantIdList() 0 3 1
A getVariantGroups() 0 3 1
A addVariant() 0 7 2
A setChildren() 0 5 1
A clearCategories() 0 3 1
A getEdbPriserProductNumber() 0 3 1
A setVariantGroups() 0 5 1
A setBarCodeNumber() 0 5 1
A getVendorNumber() 0 3 1
A setEdbPriserProductNumber() 0 5 1
A getChildren() 0 3 1
A setDisabledVariants() 0 5 1
A getComments() 0 3 1
A setProductType() 0 5 1
A setCreated() 0 5 1
A setVariantGroupIdList() 0 5 1
A findCategory() 0 9 3
A setSegmentIdList() 0 5 1
A setIsReviewVariants() 0 5 1
A getWeight() 0 3 1
A getMinBuyAmountB2B() 0 3 1
A getMinBuyAmount() 0 3 1
A setMinBuyAmountB2B() 0 5 1
A getSegments() 0 3 1
A removePrice() 0 5 1
A getDisabledVariants() 0 3 1
A setNumber() 0 5 1
A getCreated() 0 3 1
A addCategory() 0 7 2
A getCostPrice() 0 3 1
A hasManufacturer() 0 4 1
A setStockCount() 0 5 1
A setIsRateVariants() 0 5 1
A getManufacturereIdList() 0 3 1
A setSortOrder() 0 5 1
A setIsVariantMaster() 0 5 1
A setCreatedBy() 0 5 1
A updatePrices() 0 22 5
A validate() 0 9 2
A addChild() 0 8 2
A setLocationNumber() 0 5 1
A getExternalId() 0 3 1
A setManufacturereIdList() 0 5 1
A getStockCount() 0 3 1
A addMedium() 0 7 2

How to fix   Complexity   

Complex Class

Complex classes like Product often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Product, and based on these observations, apply Extract Interface, too.

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