1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\CatalogBundle\Entity; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
use Knp\DoctrineBehaviors\Model\Blameable\Blameable; |
18
|
|
|
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable; |
19
|
|
|
use Knp\DoctrineBehaviors\Model\Translatable\Translatable; |
20
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Dimension; |
21
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\DiscountablePrice; |
22
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Media; |
23
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Price; |
24
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\ShopCollectionAwareTrait; |
25
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Tax; |
26
|
|
|
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Enableable; |
27
|
|
|
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable; |
28
|
|
|
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Sortable; |
29
|
|
|
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface; |
30
|
|
|
use WellCommerce\Extra\CatalogBundle\Entity\ProductExtraTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class Product |
34
|
|
|
* |
35
|
|
|
* @author Adam Piotrowski <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class Product implements EntityInterface |
38
|
|
|
{ |
39
|
|
|
use Identifiable; |
40
|
|
|
use Enableable; |
41
|
|
|
use Sortable; |
42
|
|
|
use Translatable; |
43
|
|
|
use Timestampable; |
44
|
|
|
use Blameable; |
45
|
|
|
use ShopCollectionAwareTrait; |
46
|
|
|
use ProductExtraTrait; |
47
|
|
|
|
48
|
|
|
protected $sku = ''; |
49
|
|
|
protected $barcode = ''; |
50
|
|
|
protected $stock = 0; |
51
|
|
|
protected $trackStock = true; |
52
|
|
|
protected $weight = 0.00; |
53
|
|
|
protected $packageSize = 1.00; |
54
|
|
|
protected $popularity = 0; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Price |
58
|
|
|
*/ |
59
|
|
|
protected $buyPrice; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Tax |
63
|
|
|
*/ |
64
|
|
|
protected $buyPriceTax; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var DiscountablePrice |
68
|
|
|
*/ |
69
|
|
|
protected $sellPrice; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var Tax |
73
|
|
|
*/ |
74
|
|
|
protected $sellPriceTax; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var Dimension |
78
|
|
|
*/ |
79
|
|
|
protected $dimension; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var AttributeGroup |
83
|
|
|
*/ |
84
|
|
|
protected $attributeGroup; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var Collection |
88
|
|
|
*/ |
89
|
|
|
protected $variants; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var Collection |
93
|
|
|
*/ |
94
|
|
|
protected $categories; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var Collection |
98
|
|
|
*/ |
99
|
|
|
protected $distinctions; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var Media |
103
|
|
|
*/ |
104
|
|
|
protected $photo; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var Collection |
108
|
|
|
*/ |
109
|
|
|
protected $productPhotos; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var null|Availability |
113
|
|
|
*/ |
114
|
|
|
protected $availability; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var Producer |
118
|
|
|
*/ |
119
|
|
|
protected $producer; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var Unit |
123
|
|
|
*/ |
124
|
|
|
protected $unit; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @var ProducerCollection |
128
|
|
|
*/ |
129
|
|
|
protected $producerCollection; |
130
|
|
|
|
131
|
|
|
public function __construct() |
132
|
|
|
{ |
133
|
|
|
$this->categories = new ArrayCollection(); |
134
|
|
|
$this->productPhotos = new ArrayCollection(); |
135
|
|
|
$this->distinctions = new ArrayCollection(); |
136
|
|
|
$this->variants = new ArrayCollection(); |
137
|
|
|
$this->shops = new ArrayCollection(); |
138
|
|
|
$this->sellPrice = new DiscountablePrice(); |
139
|
|
|
$this->buyPrice = new Price(); |
140
|
|
|
$this->dimension = new Dimension(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getSku(): string |
144
|
|
|
{ |
145
|
|
|
return $this->sku; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function setSku(string $sku) |
149
|
|
|
{ |
150
|
|
|
$this->sku = $sku; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function getStock(): int |
154
|
|
|
{ |
155
|
|
|
return $this->stock; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getBarcode(): string |
159
|
|
|
{ |
160
|
|
|
return $this->barcode; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setBarcode(string $barcode) |
164
|
|
|
{ |
165
|
|
|
$this->barcode = $barcode; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function setStock(int $stock) |
169
|
|
|
{ |
170
|
|
|
$this->stock = $stock; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getTrackStock(): bool |
174
|
|
|
{ |
175
|
|
|
return $this->trackStock; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function setTrackStock(bool $trackStock) |
179
|
|
|
{ |
180
|
|
|
$this->trackStock = $trackStock; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function getDistinctions(): Collection |
184
|
|
|
{ |
185
|
|
|
return $this->distinctions; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function setDistinctions(Collection $distinctions) |
189
|
|
|
{ |
190
|
|
|
$this->distinctions->map(function (ProductDistinction $distinction) use ($distinctions) { |
191
|
|
|
if (false === $distinctions->contains($distinction)) { |
192
|
|
|
$this->distinctions->removeElement($distinction); |
193
|
|
|
} |
194
|
|
|
}); |
195
|
|
|
|
196
|
|
|
$this->distinctions = $distinctions; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function getPhoto() |
200
|
|
|
{ |
201
|
|
|
return $this->photo; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function setPhoto(Media $photo = null) |
205
|
|
|
{ |
206
|
|
|
$this->photo = $photo; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function getProductPhotos(): Collection |
210
|
|
|
{ |
211
|
|
|
return $this->productPhotos; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function setProductPhotos(Collection $photos) |
215
|
|
|
{ |
216
|
|
|
$this->productPhotos = $photos; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function addProductPhoto(ProductPhoto $photo) |
220
|
|
|
{ |
221
|
|
|
$this->productPhotos[] = $photo; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function getCategories(): Collection |
225
|
|
|
{ |
226
|
|
|
return $this->categories; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function setCategories(Collection $collection) |
230
|
|
|
{ |
231
|
|
|
$this->categories = $collection; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function addCategory(Category $category) |
235
|
|
|
{ |
236
|
|
|
$this->categories[] = $category; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public function getSellPrice(): DiscountablePrice |
240
|
|
|
{ |
241
|
|
|
return $this->sellPrice; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function setSellPrice(DiscountablePrice $sellPrice) |
245
|
|
|
{ |
246
|
|
|
$this->sellPrice = $sellPrice; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function getBuyPrice(): Price |
250
|
|
|
{ |
251
|
|
|
return $this->buyPrice; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function setBuyPrice(Price $buyPrice) |
255
|
|
|
{ |
256
|
|
|
$this->buyPrice = $buyPrice; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function getWeight(): float |
260
|
|
|
{ |
261
|
|
|
return $this->weight; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function setWeight(float $weight) |
265
|
|
|
{ |
266
|
|
|
$this->weight = $weight; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function getDimension(): Dimension |
270
|
|
|
{ |
271
|
|
|
return $this->dimension; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
public function setDimension(Dimension $dimension) |
275
|
|
|
{ |
276
|
|
|
$this->dimension = $dimension; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
public function getPackageSize(): float |
280
|
|
|
{ |
281
|
|
|
return $this->packageSize; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
public function setPackageSize(float $packageSize) |
285
|
|
|
{ |
286
|
|
|
$this->packageSize = $packageSize; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
public function getAttributeGroup() |
290
|
|
|
{ |
291
|
|
|
return $this->attributeGroup; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
public function setAttributeGroup(AttributeGroup $group = null) |
295
|
|
|
{ |
296
|
|
|
$this->attributeGroup = $group; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function getVariants(): Collection |
300
|
|
|
{ |
301
|
|
|
return $this->variants; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function setVariants(Collection $variants) |
305
|
|
|
{ |
306
|
|
|
$this->variants->map(function (Variant $variant) use ($variants) { |
307
|
|
|
if (false === $variants->contains($variant)) { |
308
|
|
|
$this->variants->removeElement($variant); |
309
|
|
|
} |
310
|
|
|
}); |
311
|
|
|
|
312
|
|
|
$this->variants = $variants; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
public function getBuyPriceTax() |
316
|
|
|
{ |
317
|
|
|
return $this->buyPriceTax; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function setBuyPriceTax(Tax $tax = null) |
321
|
|
|
{ |
322
|
|
|
$this->buyPriceTax = $tax; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
public function getSellPriceTax() |
326
|
|
|
{ |
327
|
|
|
return $this->sellPriceTax; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function setSellPriceTax(Tax $tax = null) |
331
|
|
|
{ |
332
|
|
|
$this->sellPriceTax = $tax; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function getAvailability() |
336
|
|
|
{ |
337
|
|
|
return $this->availability; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public function setAvailability(Availability $availability = null) |
341
|
|
|
{ |
342
|
|
|
$this->availability = $availability; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function getProducer() |
346
|
|
|
{ |
347
|
|
|
return $this->producer; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
public function setProducer(Producer $producer) |
351
|
|
|
{ |
352
|
|
|
$this->producer = $producer; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
public function getUnit() |
356
|
|
|
{ |
357
|
|
|
return $this->unit; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
public function setUnit(Unit $unit = null) |
361
|
|
|
{ |
362
|
|
|
$this->unit = $unit; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
public function getProducerCollection() |
366
|
|
|
{ |
367
|
|
|
return $this->producerCollection; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
public function setProducerCollection(ProducerCollection $producerCollection = null) |
371
|
|
|
{ |
372
|
|
|
$this->producerCollection = $producerCollection; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public function getPopularity(): int |
376
|
|
|
{ |
377
|
|
|
return $this->popularity; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
public function setPopularity(int $popularity) |
381
|
|
|
{ |
382
|
|
|
$this->popularity = $popularity; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
public function increasePopularity(int $increase = 1) |
386
|
|
|
{ |
387
|
|
|
$this->popularity += $increase; |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|