Product   F
last analyzed

Complexity

Total Complexity 167

Size/Duplication

Total Lines 1726
Duplicated Lines 0 %

Test Coverage

Coverage 46.59%

Importance

Changes 29
Bugs 3 Features 6
Metric Value
wmc 167
eloc 330
c 29
b 3
f 6
dl 0
loc 1726
ccs 294
cts 631
cp 0.4659
rs 2

131 Methods

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