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\OrderBundle\Entity; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable; |
18
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Client; |
19
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\ClientBillingAddress; |
20
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\ClientContactDetails; |
21
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\ClientDetails; |
22
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\ClientShippingAddress; |
23
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\MinimumOrderAmount; |
24
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Shop; |
25
|
|
|
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable; |
26
|
|
|
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface; |
27
|
|
|
use WellCommerce\Bundle\CouponBundle\Entity\Coupon; |
28
|
|
|
use WellCommerce\Bundle\OrderBundle\Visitor\OrderVisitorInterface; |
29
|
|
|
use WellCommerce\Extra\OrderBundle\Entity\OrderExtraTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class Order |
33
|
|
|
* |
34
|
|
|
* @author Adam Piotrowski <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class Order implements EntityInterface |
37
|
|
|
{ |
38
|
|
|
use Identifiable; |
39
|
|
|
use Timestampable; |
40
|
|
|
use OrderExtraTrait; |
41
|
|
|
|
42
|
|
|
protected $confirmed = false; |
43
|
|
|
protected $number = null; |
44
|
|
|
protected $currency = null; |
45
|
|
|
protected $currencyRate = 1.0000; |
46
|
|
|
protected $sessionId = ''; |
47
|
|
|
protected $shippingMethodOption = null; |
48
|
|
|
protected $comment = ''; |
49
|
|
|
protected $issueInvoice = false; |
50
|
|
|
protected $conditionsAccepted = false; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var null|Client |
54
|
|
|
*/ |
55
|
|
|
protected $client; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var ClientDetails |
59
|
|
|
*/ |
60
|
|
|
protected $clientDetails; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var ClientContactDetails |
64
|
|
|
*/ |
65
|
|
|
protected $contactDetails; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var ClientBillingAddress |
69
|
|
|
*/ |
70
|
|
|
protected $billingAddress; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var ClientShippingAddress |
74
|
|
|
*/ |
75
|
|
|
protected $shippingAddress; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var Coupon |
79
|
|
|
*/ |
80
|
|
|
protected $coupon; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var OrderStatus |
84
|
|
|
*/ |
85
|
|
|
protected $currentStatus; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var OrderSummary |
89
|
|
|
*/ |
90
|
|
|
protected $summary; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var OrderProductTotal |
94
|
|
|
*/ |
95
|
|
|
protected $productTotal; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var MinimumOrderAmount |
99
|
|
|
*/ |
100
|
|
|
protected $minimumOrderAmount; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var Collection |
104
|
|
|
*/ |
105
|
|
|
protected $products; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var Collection |
109
|
|
|
*/ |
110
|
|
|
protected $payments; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var Collection |
114
|
|
|
*/ |
115
|
|
|
protected $orderStatusHistory; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var Collection |
119
|
|
|
*/ |
120
|
|
|
protected $orderNotes; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var Collection |
124
|
|
|
*/ |
125
|
|
|
protected $modifiers; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var Shop |
129
|
|
|
*/ |
130
|
|
|
protected $shop; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @var ShippingMethod |
134
|
|
|
*/ |
135
|
|
|
protected $shippingMethod; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var PaymentMethod |
139
|
|
|
*/ |
140
|
|
|
protected $paymentMethod; |
141
|
|
|
|
142
|
|
|
public function __construct() |
143
|
|
|
{ |
144
|
|
|
$this->products = new ArrayCollection(); |
145
|
|
|
$this->modifiers = new ArrayCollection(); |
146
|
|
|
$this->payments = new ArrayCollection(); |
147
|
|
|
$this->orderStatusHistory = new ArrayCollection(); |
148
|
|
|
$this->orderNotes = new ArrayCollection(); |
149
|
|
|
$this->productTotal = new OrderProductTotal(); |
150
|
|
|
$this->summary = new OrderSummary(); |
151
|
|
|
$this->clientDetails = new ClientDetails(); |
152
|
|
|
$this->contactDetails = new ClientContactDetails(); |
153
|
|
|
$this->billingAddress = new ClientBillingAddress(); |
154
|
|
|
$this->shippingAddress = new ClientShippingAddress(); |
155
|
|
|
$this->minimumOrderAmount = new MinimumOrderAmount(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getClient() |
159
|
|
|
{ |
160
|
|
|
return $this->client; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setClient(Client $client = null) |
164
|
|
|
{ |
165
|
|
|
$this->client = $client; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getClientDetails(): ClientDetails |
169
|
|
|
{ |
170
|
|
|
return $this->clientDetails; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function setClientDetails(ClientDetails $clientDetails) |
174
|
|
|
{ |
175
|
|
|
$this->clientDetails = $clientDetails; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function getContactDetails(): ClientContactDetails |
179
|
|
|
{ |
180
|
|
|
return $this->contactDetails; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function setContactDetails(ClientContactDetails $contactDetails) |
184
|
|
|
{ |
185
|
|
|
$this->contactDetails = $contactDetails; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getBillingAddress(): ClientBillingAddress |
189
|
|
|
{ |
190
|
|
|
return $this->billingAddress; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function setBillingAddress(ClientBillingAddress $billingAddress) |
194
|
|
|
{ |
195
|
|
|
$this->billingAddress = $billingAddress; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getShippingAddress(): ClientShippingAddress |
199
|
|
|
{ |
200
|
|
|
return $this->shippingAddress; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function setShippingAddress(ClientShippingAddress $shippingAddress) |
204
|
|
|
{ |
205
|
|
|
$this->shippingAddress = $shippingAddress; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function isConfirmed(): bool |
209
|
|
|
{ |
210
|
|
|
return $this->confirmed; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function setConfirmed(bool $confirmed) |
214
|
|
|
{ |
215
|
|
|
$this->confirmed = $confirmed; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function getNumber() |
219
|
|
|
{ |
220
|
|
|
return $this->number; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function setNumber(string $number) |
224
|
|
|
{ |
225
|
|
|
$this->number = $number; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function getCurrency(): string |
229
|
|
|
{ |
230
|
|
|
return $this->currency; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function setCurrency(string $currency) |
234
|
|
|
{ |
235
|
|
|
$this->currency = $currency; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
public function getCurrencyRate(): float |
239
|
|
|
{ |
240
|
|
|
return $this->currencyRate; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function setCurrencyRate(float $currencyRate) |
244
|
|
|
{ |
245
|
|
|
$this->currencyRate = $currencyRate; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getSessionId(): string |
249
|
|
|
{ |
250
|
|
|
return $this->sessionId; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function setSessionId(string $sessionId) |
254
|
|
|
{ |
255
|
|
|
$this->sessionId = $sessionId; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function getCoupon() |
259
|
|
|
{ |
260
|
|
|
return $this->coupon; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function setCoupon(Coupon $coupon = null) |
264
|
|
|
{ |
265
|
|
|
$this->coupon = $coupon; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function getProducts(): Collection |
269
|
|
|
{ |
270
|
|
|
return $this->products; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function setProducts(Collection $products) |
274
|
|
|
{ |
275
|
|
|
$this->products = $products; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
public function getProductTotal(): OrderProductTotal |
279
|
|
|
{ |
280
|
|
|
return $this->productTotal; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function setProductTotal(OrderProductTotal $productTotal) |
284
|
|
|
{ |
285
|
|
|
$this->productTotal = $productTotal; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
public function hasModifier(string $name): bool |
289
|
|
|
{ |
290
|
|
|
return $this->modifiers->containsKey($name); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function removeModifier(string $name) |
294
|
|
|
{ |
295
|
|
|
$this->modifiers->remove($name); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function getModifier(string $name): OrderModifier |
299
|
|
|
{ |
300
|
|
|
return $this->modifiers->get($name); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function getModifiers(): Collection |
304
|
|
|
{ |
305
|
|
|
return $this->modifiers; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
public function getSummary(): OrderSummary |
309
|
|
|
{ |
310
|
|
|
return $this->summary; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function setSummary(OrderSummary $summary) |
314
|
|
|
{ |
315
|
|
|
$this->summary = $summary; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function getCurrentStatus() |
319
|
|
|
{ |
320
|
|
|
return $this->currentStatus; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
public function setCurrentStatus(OrderStatus $currentStatus = null) |
324
|
|
|
{ |
325
|
|
|
$this->currentStatus = $currentStatus; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
public function getOrderStatusHistory(): Collection |
329
|
|
|
{ |
330
|
|
|
return $this->orderStatusHistory; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function getOrderNotes(): Collection |
334
|
|
|
{ |
335
|
|
|
return $this->orderNotes; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
public function getComment(): string |
339
|
|
|
{ |
340
|
|
|
return $this->comment; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
public function setComment(string $comment) |
344
|
|
|
{ |
345
|
|
|
$this->comment = $comment; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function getPayments(): Collection |
349
|
|
|
{ |
350
|
|
|
return $this->payments; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
public function acceptVisitor(OrderVisitorInterface $visitor) |
354
|
|
|
{ |
355
|
|
|
$visitor->visitOrder($this); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
public function isEmpty(): bool |
359
|
|
|
{ |
360
|
|
|
return 0 === $this->productTotal->getQuantity(); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
public function getShippingMethodOption() |
364
|
|
|
{ |
365
|
|
|
return $this->shippingMethodOption; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
public function setShippingMethodOption($shippingMethodOption) |
369
|
|
|
{ |
370
|
|
|
$this->shippingMethodOption = $shippingMethodOption; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function isConditionsAccepted(): bool |
374
|
|
|
{ |
375
|
|
|
return $this->conditionsAccepted; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function setConditionsAccepted(bool $conditionsAccepted) |
379
|
|
|
{ |
380
|
|
|
$this->conditionsAccepted = $conditionsAccepted; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
public function isIssueInvoice(): bool |
384
|
|
|
{ |
385
|
|
|
return $this->issueInvoice; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
public function setIssueInvoice(bool $issueInvoice) |
389
|
|
|
{ |
390
|
|
|
$this->issueInvoice = $issueInvoice; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function getShop(): Shop |
394
|
|
|
{ |
395
|
|
|
return $this->shop; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
public function setShop(Shop $shop) |
399
|
|
|
{ |
400
|
|
|
$this->shop = $shop; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
public function getShippingMethod() |
404
|
|
|
{ |
405
|
|
|
return $this->shippingMethod; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
public function setShippingMethod(ShippingMethod $shippingMethod = null) |
409
|
|
|
{ |
410
|
|
|
$this->shippingMethod = $shippingMethod; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
public function getPaymentMethod() |
414
|
|
|
{ |
415
|
|
|
return $this->paymentMethod; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
public function setPaymentMethod(PaymentMethod $paymentMethod = null) |
419
|
|
|
{ |
420
|
|
|
$this->paymentMethod = $paymentMethod; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
public function getMinimumOrderAmount(): MinimumOrderAmount |
424
|
|
|
{ |
425
|
|
|
return $this->minimumOrderAmount; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
public function setMinimumOrderAmount(MinimumOrderAmount $minimumOrderAmount) |
429
|
|
|
{ |
430
|
|
|
$this->minimumOrderAmount = $minimumOrderAmount; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
public function hasMinimumValue(): bool |
434
|
|
|
{ |
435
|
|
|
return $this->getSummary()->getGrossAmount() >= $this->minimumOrderAmount->getValue(); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
public function hasMethods(): bool |
439
|
|
|
{ |
440
|
|
|
return $this->shippingMethod instanceof ShippingMethod && $this->paymentMethod instanceof PaymentMethod; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
public function isConfirmable(): bool |
444
|
|
|
{ |
445
|
|
|
return !$this->isEmpty() && $this->hasMinimumValue() && $this->hasMethods(); |
446
|
|
|
} |
447
|
|
|
} |
448
|
|
|
|