Completed
Push — master ( 2d4a89...f31334 )
by Joachim
11:46
created

Product   F

Complexity

Total Complexity 156

Size/Duplication

Total Lines 1653
Duplicated Lines 0 %

Test Coverage

Coverage 52.19%

Importance

Changes 0
Metric Value
dl 0
loc 1653
ccs 179
cts 343
cp 0.5219
rs 0.6314
c 0
b 0
f 0
wmc 156

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