1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Entity; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\ORM\Mapping as ORM; |
18
|
|
|
use Eccube\Service\PurchaseFlow\InvalidItemException; |
19
|
|
|
use Eccube\Service\PurchaseFlow\ItemCollection; |
20
|
|
|
|
21
|
|
|
if (!class_exists('\Eccube\Entity\Cart')) { |
22
|
|
|
/** |
23
|
|
|
* Cart |
24
|
|
|
* |
25
|
|
|
* @ORM\Table(name="dtb_cart", indexes={@ORM\Index(name="dtb_cart_pre_order_id_idx", columns={"pre_order_id"}), @ORM\Index(name="dtb_cart_update_date_idx", columns={"update_date"})}) |
26
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
27
|
|
|
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255) |
28
|
|
|
* @ORM\HasLifecycleCallbacks() |
29
|
|
|
* @ORM\Entity(repositoryClass="Eccube\Repository\CartRepository") |
30
|
|
|
*/ |
31
|
|
|
class Cart extends AbstractEntity implements PurchaseInterface, ItemHolderInterface |
32
|
|
|
{ |
33
|
|
|
use PointTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var integer |
37
|
|
|
* |
38
|
|
|
* @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
39
|
|
|
* @ORM\Id |
40
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
41
|
|
|
*/ |
42
|
|
|
private $id; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(name="cart_key", type="string", options={"unsigned":true}, nullable=true) |
48
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
49
|
|
|
*/ |
50
|
|
|
private $cart_key; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Eccube\Entity\Customer |
54
|
|
|
* |
55
|
|
|
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer") |
56
|
|
|
* @ORM\JoinColumns({ |
57
|
|
|
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id") |
58
|
|
|
* }) |
59
|
|
|
*/ |
60
|
|
|
private $Customer; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
private $lock = false; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var \Doctrine\Common\Collections\Collection|CartItem[] |
69
|
|
|
* |
70
|
|
|
* @ORM\OneToMany(targetEntity="Eccube\Entity\CartItem", mappedBy="Cart", cascade={"persist"}) |
71
|
|
|
*/ |
72
|
|
|
private $CartItems; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var string|null |
76
|
|
|
* |
77
|
|
|
* @ORM\Column(name="pre_order_id", type="string", length=255, nullable=true) |
78
|
|
|
*/ |
79
|
|
|
private $pre_order_id = null; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="total_price", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0}) |
85
|
|
|
*/ |
86
|
|
|
private $total_price; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var string |
90
|
|
|
* |
91
|
|
|
* @ORM\Column(name="delivery_fee_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0}) |
92
|
|
|
*/ |
93
|
|
|
private $delivery_fee_total; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var int|null |
97
|
|
|
* |
98
|
|
|
* @ORM\Column(name="sort_no", type="smallint", nullable=true, options={"unsigned":true}) |
99
|
|
|
*/ |
100
|
|
|
private $sort_no; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var \DateTime |
104
|
|
|
* |
105
|
|
|
* @ORM\Column(name="create_date", type="datetimetz") |
106
|
|
|
*/ |
107
|
|
|
private $create_date; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var \DateTime |
111
|
|
|
* |
112
|
|
|
* @ORM\Column(name="update_date", type="datetimetz") |
113
|
|
|
*/ |
114
|
|
|
private $update_date; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var InvalidItemException[] |
118
|
|
|
*/ |
119
|
|
|
private $errors = []; |
120
|
|
|
|
121
|
|
|
public function __wakeup() |
122
|
|
|
{ |
123
|
|
|
$this->errors = []; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function __construct() |
127
|
|
|
{ |
128
|
|
|
$this->CartItems = new ArrayCollection(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return int |
133
|
|
|
*/ |
134
|
|
|
public function getId() |
135
|
|
|
{ |
136
|
|
|
return $this->id; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function getCartKey() |
143
|
|
|
{ |
144
|
|
|
return $this->cart_key; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $cartKey |
149
|
|
|
*/ |
150
|
|
|
public function setCartKey(string $cartKey) |
151
|
|
|
{ |
152
|
|
|
$this->cart_key = $cartKey; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return bool |
157
|
|
|
* |
158
|
|
|
* @deprecated 使用しないので削除予定 |
159
|
|
|
*/ |
160
|
|
|
public function getLock() |
161
|
|
|
{ |
162
|
|
|
return $this->lock; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param bool $lock |
167
|
|
|
* |
168
|
|
|
* @return \Eccube\Entity\Cart |
169
|
|
|
* |
170
|
|
|
* @deprecated 使用しないので削除予定 |
171
|
|
|
*/ |
172
|
|
|
public function setLock($lock) |
173
|
|
|
{ |
174
|
|
|
$this->lock = $lock; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string|null |
181
|
|
|
*/ |
182
|
|
|
public function getPreOrderId() |
183
|
|
|
{ |
184
|
|
|
return $this->pre_order_id; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param integer $pre_order_id |
189
|
|
|
* |
190
|
|
|
* @return \Eccube\Entity\Cart |
191
|
|
|
*/ |
192
|
|
|
public function setPreOrderId($pre_order_id) |
193
|
|
|
{ |
194
|
|
|
$this->pre_order_id = $pre_order_id; |
|
|
|
|
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param CartItem $CartItem |
201
|
|
|
* |
202
|
|
|
* @return \Eccube\Entity\Cart |
203
|
|
|
*/ |
204
|
|
|
public function addCartItem(CartItem $CartItem) |
205
|
|
|
{ |
206
|
|
|
$this->CartItems[] = $CartItem; |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return \Eccube\Entity\Cart |
213
|
|
|
*/ |
214
|
|
|
public function clearCartItems() |
215
|
|
|
{ |
216
|
|
|
$this->CartItems->clear(); |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return ArrayCollection|CartItem[] |
223
|
|
|
*/ |
224
|
|
|
public function getCartItems() |
225
|
|
|
{ |
226
|
|
|
return $this->CartItems; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Alias of getCartItems() |
231
|
|
|
*/ |
232
|
|
|
public function getItems() |
233
|
|
|
{ |
234
|
|
|
return (new ItemCollection($this->getCartItems()))->sort(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param CartItem[] $CartItems |
239
|
|
|
* |
240
|
|
|
* @return \Eccube\Entity\Cart |
241
|
|
|
*/ |
242
|
|
|
public function setCartItems($CartItems) |
243
|
|
|
{ |
244
|
|
|
$this->CartItems = $CartItems; |
245
|
|
|
|
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Set total. |
251
|
|
|
* |
252
|
|
|
* @param integer $total_price |
253
|
|
|
* |
254
|
|
|
* @return Cart |
255
|
|
|
*/ |
256
|
|
|
public function setTotalPrice($total_price) |
257
|
|
|
{ |
258
|
|
|
$this->total_price = $total_price; |
|
|
|
|
259
|
|
|
|
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return string |
265
|
|
|
*/ |
266
|
|
|
public function getTotalPrice() |
267
|
|
|
{ |
268
|
|
|
return $this->total_price; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Alias of setTotalPrice. |
273
|
|
|
*/ |
274
|
|
|
public function setTotal($total) |
275
|
|
|
{ |
276
|
|
|
return $this->setTotalPrice($total); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Alias of getTotalPrice |
281
|
|
|
*/ |
282
|
|
|
public function getTotal() |
283
|
|
|
{ |
284
|
|
|
return $this->getTotalPrice(); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return integer |
289
|
|
|
*/ |
290
|
|
|
public function getTotalQuantity() |
291
|
|
|
{ |
292
|
|
|
$totalQuantity = 0; |
293
|
|
|
foreach ($this->CartItems as $CartItem) { |
294
|
|
|
$totalQuantity += $CartItem->getQuantity(); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
return $totalQuantity; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @param ItemInterface $item |
302
|
|
|
*/ |
303
|
|
|
public function addItem(ItemInterface $item) |
304
|
|
|
{ |
305
|
|
|
$this->CartItems->add($item); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @param ItemInterface $item |
310
|
|
|
*/ |
311
|
|
|
public function removeItem(ItemInterface $item) |
312
|
|
|
{ |
313
|
|
|
$this->CartItems->removeElement($item); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* 個数の合計を返します。 |
318
|
|
|
* |
319
|
|
|
* @return integer |
320
|
|
|
*/ |
321
|
|
|
public function getQuantity() |
322
|
|
|
{ |
323
|
|
|
return $this->getTotalQuantity(); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* {@inheritdoc} |
328
|
|
|
*/ |
329
|
|
|
public function setDeliveryFeeTotal($total) |
330
|
|
|
{ |
331
|
|
|
$this->delivery_fee_total = $total; |
332
|
|
|
|
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* {@inheritdoc} |
338
|
|
|
*/ |
339
|
|
|
public function getDeliveryFeeTotal() |
340
|
|
|
{ |
341
|
|
|
return $this->delivery_fee_total; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return Customer |
346
|
|
|
*/ |
347
|
|
|
public function getCustomer(): Customer |
348
|
|
|
{ |
349
|
|
|
return $this->Customer; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param Customer $Customer |
354
|
|
|
*/ |
355
|
|
|
public function setCustomer(Customer $Customer = null) |
356
|
|
|
{ |
357
|
|
|
$this->Customer = $Customer; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Set sortNo. |
362
|
|
|
* |
363
|
|
|
* @param int|null $sortNo |
364
|
|
|
* |
365
|
|
|
* @return Cart |
366
|
|
|
*/ |
367
|
|
|
public function setSortNo($sortNo = null) |
368
|
|
|
{ |
369
|
|
|
$this->sort_no = $sortNo; |
370
|
|
|
|
371
|
|
|
return $this; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Get sortNo. |
376
|
|
|
* |
377
|
|
|
* @return int|null |
378
|
|
|
*/ |
379
|
|
|
public function getSortNo() |
380
|
|
|
{ |
381
|
|
|
return $this->sort_no; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Set createDate. |
386
|
|
|
* |
387
|
|
|
* @param \DateTime $createDate |
388
|
|
|
* |
389
|
|
|
* @return Cart |
390
|
|
|
*/ |
391
|
|
|
public function setCreateDate($createDate) |
392
|
|
|
{ |
393
|
|
|
$this->create_date = $createDate; |
394
|
|
|
|
395
|
|
|
return $this; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Get createDate. |
400
|
|
|
* |
401
|
|
|
* @return \DateTime |
402
|
|
|
*/ |
403
|
|
|
public function getCreateDate() |
404
|
|
|
{ |
405
|
|
|
return $this->create_date; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Set updateDate. |
410
|
|
|
* |
411
|
|
|
* @param \DateTime $updateDate |
412
|
|
|
* |
413
|
|
|
* @return Cart |
414
|
|
|
*/ |
415
|
|
|
public function setUpdateDate($updateDate) |
416
|
|
|
{ |
417
|
|
|
$this->update_date = $updateDate; |
418
|
|
|
|
419
|
|
|
return $this; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Get updateDate. |
424
|
|
|
* |
425
|
|
|
* @return \DateTime |
426
|
|
|
*/ |
427
|
|
|
public function getUpdateDate() |
428
|
|
|
{ |
429
|
|
|
return $this->update_date; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* {@inheritdoc} |
434
|
|
|
*/ |
435
|
|
|
public function setDiscount($total) |
436
|
|
|
{ |
437
|
|
|
// TODO quiet |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* {@inheritdoc} |
442
|
|
|
*/ |
443
|
|
|
public function setCharge($total) |
444
|
|
|
{ |
445
|
|
|
// TODO quiet |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* {@inheritdoc} |
450
|
|
|
*/ |
451
|
|
|
public function setTax($total) |
452
|
|
|
{ |
453
|
|
|
// TODO quiet |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..