|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Service; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\ORM\EntityManager; |
|
28
|
|
|
use Eccube\Common\Constant; |
|
29
|
|
|
use Eccube\Entity\CartItem; |
|
30
|
|
|
use Eccube\Entity\Master\Disp; |
|
31
|
|
|
use Eccube\Entity\ProductClass; |
|
32
|
|
|
use Eccube\Exception\CartException; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
34
|
|
|
|
|
35
|
|
|
class CartService |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
/** @var \Eccube\Application */ |
|
38
|
|
|
public $app; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var Session |
|
42
|
|
|
*/ |
|
43
|
|
|
private $session; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var EntityManager |
|
47
|
|
|
*/ |
|
48
|
|
|
private $entityManager; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var \Eccube\Entity\Cart |
|
52
|
|
|
*/ |
|
53
|
|
|
private $cart; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var \Eccube\Entity\BaseInfo |
|
57
|
|
|
*/ |
|
58
|
|
|
private $BaseInfo; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
private $errors = array(); |
|
64
|
|
|
|
|
65
|
|
|
private $ProductType = null; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
private $messages = array(); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var array |
|
74
|
|
|
*/ |
|
75
|
|
|
private $error; |
|
76
|
|
|
|
|
77
|
227 |
|
public function __construct(\Eccube\Application $app) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
227 |
|
$this->app = $app; |
|
80
|
227 |
|
$this->session = $app['session']; |
|
81
|
227 |
|
$this->entityManager = $app['orm.em']; |
|
82
|
|
|
|
|
83
|
227 |
|
if ($this->session->has('cart')) { |
|
84
|
|
|
$this->cart = $this->session->get('cart'); |
|
85
|
|
|
} else { |
|
86
|
227 |
|
$this->cart = new \Eccube\Entity\Cart(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
227 |
|
$this->loadProductClassFromCart(); |
|
90
|
|
|
|
|
91
|
227 |
|
$this->BaseInfo = $app['eccube.repository.base_info']->get(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* カートに保存されている商品の ProductClass エンティティを読み込み、カートへ設定します。 |
|
96
|
|
|
*/ |
|
97
|
227 |
|
protected function loadProductClassFromCart() |
|
98
|
|
|
{ |
|
99
|
|
|
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
|
100
|
227 |
|
$softDeleteFilter = $this->entityManager->getFilters()->getFilter('soft_delete'); |
|
101
|
227 |
|
$excludes = $softDeleteFilter->getExcludes(); |
|
102
|
227 |
|
$softDeleteFilter->setExcludes(array( |
|
103
|
227 |
|
'Eccube\Entity\ProductClass', |
|
104
|
|
|
)); |
|
105
|
|
|
|
|
106
|
227 |
|
foreach ($this->cart->getCartItems() as $CartItem) { |
|
107
|
227 |
|
$this->loadProductClassFromCartItem($CartItem); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
227 |
|
$softDeleteFilter->setExcludes($excludes); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* CartItem に対応する ProductClass を設定します。 |
|
115
|
|
|
* |
|
116
|
|
|
* @param CartItem $CartItem |
|
117
|
|
|
*/ |
|
118
|
78 |
|
protected function loadProductClassFromCartItem(CartItem $CartItem) |
|
119
|
|
|
{ |
|
120
|
|
|
$ProductClass = $this |
|
121
|
78 |
|
->entityManager |
|
122
|
78 |
|
->getRepository($CartItem->getClassName()) |
|
123
|
78 |
|
->find($CartItem->getClassId()); |
|
124
|
|
|
|
|
125
|
78 |
|
$CartItem->setObject($ProductClass); |
|
126
|
|
|
|
|
127
|
78 |
|
if (is_null($this->ProductType) && $ProductClass->getDelFlg() == Constant::DISABLED) { |
|
128
|
|
|
$this->setCanAddProductType($ProductClass->getProductType()); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
126 |
|
public function setCanAddProductType(\Eccube\Entity\Master\ProductType $ProductType) |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
126 |
|
if (is_null($this->ProductType)) { |
|
135
|
126 |
|
$this->ProductType = $ProductType; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
126 |
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
119 |
|
public function save() |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
119 |
|
return $this->session->set('cart', $this->cart); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
7 |
|
public function unlock() |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
7 |
|
$this->cart |
|
149
|
7 |
|
->setLock(false) |
|
150
|
7 |
|
->setPreOrderId(null); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
76 |
|
public function lock() |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
76 |
|
$this->cart |
|
156
|
76 |
|
->setLock(true) |
|
157
|
76 |
|
->setPreOrderId(null); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return bool |
|
162
|
|
|
*/ |
|
163
|
68 |
|
public function isLocked() |
|
164
|
|
|
{ |
|
165
|
68 |
|
return $this->cart->getLock(); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param string $pre_order_id |
|
170
|
|
|
* @return \Eccube\Service\CartService |
|
171
|
|
|
*/ |
|
172
|
58 |
|
public function setPreOrderId($pre_order_id) |
|
173
|
|
|
{ |
|
174
|
58 |
|
$this->cart->setPreOrderId($pre_order_id); |
|
175
|
|
|
|
|
176
|
58 |
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
57 |
|
public function getPreOrderId() |
|
183
|
|
|
{ |
|
184
|
57 |
|
return $this->cart->getPreOrderId(); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @return \Eccube\Service\CartService |
|
189
|
|
|
*/ |
|
190
|
19 |
|
public function clear() |
|
191
|
|
|
{ |
|
192
|
19 |
|
$this->cart |
|
193
|
19 |
|
->setPreOrderId(null) |
|
194
|
19 |
|
->setLock(false) |
|
195
|
19 |
|
->clearCartItems(); |
|
196
|
|
|
|
|
197
|
19 |
|
return $this; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
1 |
|
public function getCanAddProductType() |
|
|
|
|
|
|
201
|
|
|
{ |
|
202
|
1 |
|
return $this->ProductType; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* |
|
207
|
|
|
* @param string $productClassId |
|
|
|
|
|
|
208
|
|
|
* @param integer $quantity |
|
209
|
|
|
* @return \Eccube\Service\CartService |
|
210
|
|
|
*/ |
|
211
|
82 |
|
public function addProduct($productClassId, $quantity = 1) |
|
212
|
|
|
{ |
|
213
|
82 |
|
$quantity += $this->getProductQuantity($productClassId); |
|
214
|
82 |
|
$this->setProductQuantity($productClassId, $quantity); |
|
215
|
|
|
|
|
216
|
81 |
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param string $productClassId |
|
221
|
|
|
* @return integer |
|
222
|
|
|
*/ |
|
223
|
91 |
|
public function getProductQuantity($productClassId) |
|
224
|
|
|
{ |
|
225
|
91 |
|
$CartItem = $this->cart->getCartItemByIdentifier('Eccube\Entity\ProductClass', (string)$productClassId); |
|
|
|
|
|
|
226
|
91 |
|
if ($CartItem) { |
|
227
|
19 |
|
return $CartItem->getQuantity(); |
|
228
|
|
|
} else { |
|
229
|
89 |
|
return 0; |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @param \Eccube\Entity\ProductClass|integer $ProductClass |
|
235
|
|
|
* @param integer $quantity |
|
|
|
|
|
|
236
|
|
|
* @return \Eccube\Service\CartService |
|
237
|
|
|
* @throws CartException |
|
238
|
|
|
*/ |
|
239
|
129 |
|
public function setProductQuantity($ProductClass, $quantity) |
|
240
|
|
|
{ |
|
241
|
129 |
|
if (!$ProductClass instanceof ProductClass) { |
|
|
|
|
|
|
242
|
124 |
|
$ProductClass = $this->entityManager |
|
243
|
124 |
|
->getRepository('Eccube\Entity\ProductClass') |
|
244
|
124 |
|
->find($ProductClass); |
|
245
|
124 |
|
if (!$ProductClass) { |
|
246
|
3 |
|
throw new CartException('cart.product.delete'); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
126 |
|
if (!$this->isProductDisplay($ProductClass)) { |
|
251
|
4 |
|
throw new CartException('cart.product.not.status'); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
125 |
|
$productName = $this->getProductName($ProductClass); |
|
255
|
|
|
|
|
256
|
|
|
// 商品種別に紐づく配送業者を取得 |
|
257
|
125 |
|
$deliveries = $this->app['eccube.repository.delivery']->getDeliveries($ProductClass->getProductType()); |
|
258
|
|
|
|
|
259
|
125 |
|
if (count($deliveries) == 0) { |
|
260
|
|
|
// 商品種別が存在しなければエラー |
|
261
|
|
|
$this->removeProduct($ProductClass->getId()); |
|
262
|
|
|
$this->addError('cart.product.not.producttype', $productName); |
|
263
|
|
|
throw new CartException('cart.product.not.producttype'); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
125 |
|
$this->setCanAddProductType($ProductClass->getProductType()); |
|
267
|
|
|
|
|
268
|
125 |
|
if ($this->BaseInfo->getOptionMultipleShipping() != Constant::ENABLED) { |
|
269
|
117 |
|
if (!$this->canAddProduct($ProductClass->getId())) { |
|
270
|
|
|
// 複数配送対応でなければ商品種別が異なればエラー |
|
271
|
117 |
|
throw new CartException('cart.product.type.kind'); |
|
272
|
|
|
} |
|
273
|
|
|
} else { |
|
274
|
|
|
// 複数配送の場合、同一支払方法がなければエラー |
|
275
|
8 |
|
if (!$this->canAddProductPayment($ProductClass->getProductType())) { |
|
276
|
1 |
|
throw new CartException('cart.product.payment.kind'); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
125 |
|
$tmp_subtotal = 0; |
|
281
|
125 |
|
$tmp_quantity = 0; |
|
282
|
125 |
|
foreach ($this->getCart()->getCartItems() as $cartitem) { |
|
283
|
15 |
|
$pc = $cartitem->getObject(); |
|
284
|
15 |
|
if ($pc->getId() != $ProductClass->getId()) { |
|
285
|
|
|
// 追加された商品以外のtotal priceをセット |
|
286
|
125 |
|
$tmp_subtotal += $cartitem->getTotalPrice(); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
125 |
|
for ($i = 0; $i < $quantity; $i++) { |
|
290
|
125 |
|
$tmp_subtotal += $ProductClass->getPrice02IncTax(); |
|
291
|
125 |
|
if ($tmp_subtotal > $this->app['config']['max_total_fee']) { |
|
292
|
1 |
|
$this->setError('cart.over.price_limit'); |
|
293
|
1 |
|
break; |
|
294
|
|
|
} |
|
295
|
124 |
|
$tmp_quantity++; |
|
296
|
|
|
} |
|
297
|
125 |
|
if ($tmp_quantity == 0) { |
|
298
|
|
|
// 数量が0の場合、エラー |
|
299
|
1 |
|
throw new CartException('cart.over.price_limit'); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
// 制限数チェック |
|
303
|
124 |
|
$quantity = $this->setProductLimit($ProductClass, $productName, $tmp_quantity); |
|
304
|
|
|
|
|
305
|
124 |
|
$CartItem = new CartItem(); |
|
306
|
|
|
$CartItem |
|
307
|
124 |
|
->setClassName('Eccube\Entity\ProductClass') |
|
308
|
124 |
|
->setClassId((string)$ProductClass->getId()) |
|
|
|
|
|
|
309
|
124 |
|
->setPrice($ProductClass->getPrice02IncTax()) |
|
310
|
124 |
|
->setQuantity($quantity); |
|
311
|
|
|
|
|
312
|
124 |
|
$this->cart->setCartItem($CartItem); |
|
313
|
|
|
|
|
314
|
124 |
|
return $this; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param string $productClassId |
|
319
|
|
|
* @return boolean |
|
320
|
|
|
*/ |
|
321
|
117 |
|
public function canAddProduct($productClassId) |
|
322
|
|
|
{ |
|
323
|
|
|
$ProductClass = $this |
|
324
|
117 |
|
->entityManager |
|
325
|
117 |
|
->getRepository('\Eccube\Entity\ProductClass') |
|
326
|
117 |
|
->find($productClassId); |
|
327
|
|
|
|
|
328
|
117 |
|
if (!$ProductClass) { |
|
329
|
|
|
return false; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
117 |
|
$ProductType = $ProductClass->getProductType(); |
|
333
|
|
|
|
|
334
|
117 |
|
return $this->ProductType == $ProductType; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @param \Eccube\Entity\Master\ProductType $ProductType |
|
339
|
|
|
* @return bool |
|
340
|
|
|
*/ |
|
341
|
9 |
|
public function canAddProductPayment(\Eccube\Entity\Master\ProductType $ProductType) |
|
342
|
|
|
{ |
|
343
|
|
|
$deliveries = $this |
|
344
|
9 |
|
->entityManager |
|
345
|
9 |
|
->getRepository('\Eccube\Entity\Delivery') |
|
346
|
9 |
|
->findBy(array('ProductType' => $ProductType)); |
|
347
|
|
|
|
|
348
|
|
|
// 支払方法を取得 |
|
349
|
9 |
|
$payments = $this->entityManager->getRepository('Eccube\Entity\Payment')->findAllowedPayments($deliveries); |
|
350
|
|
|
|
|
351
|
9 |
|
if ($this->getCart()->getTotalPrice() < 1) { |
|
352
|
|
|
// カートになければ支払方法を全て設定 |
|
353
|
9 |
|
$this->getCart()->setPayments($payments); |
|
354
|
|
|
|
|
355
|
9 |
|
return true; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
// カートに存在している支払方法と追加された商品の支払方法チェック |
|
359
|
7 |
|
$arr = array(); |
|
360
|
7 |
|
foreach ($payments as $payment) { |
|
361
|
7 |
|
foreach ($this->getCart()->getPayments() as $p) { |
|
362
|
7 |
|
if ($payment['id'] == $p['id']) { |
|
363
|
6 |
|
$arr[] = $payment; |
|
364
|
7 |
|
break; |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
7 |
|
if (count($arr) > 0) { |
|
370
|
6 |
|
$this->getCart()->setPayments($arr); |
|
371
|
|
|
|
|
372
|
6 |
|
return true; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
// 支払条件に一致しない |
|
376
|
1 |
|
return false; |
|
377
|
|
|
|
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* カートブロックに表示するカートを取得します。 |
|
382
|
|
|
* ブロックに表示するカートはチェックを行わず、セットされているカートを返します。 |
|
383
|
|
|
* |
|
384
|
|
|
* @return \Eccube\Entity\Cart |
|
385
|
|
|
*/ |
|
386
|
76 |
|
public function getCartObj() |
|
387
|
|
|
{ |
|
388
|
|
|
|
|
389
|
76 |
|
foreach ($this->cart->getCartItems() as $CartItem) { |
|
390
|
|
|
|
|
391
|
|
|
/** @var \Eccube\Entity\ProductClass $ProductClass */ |
|
392
|
|
|
$ProductClass = $CartItem->getObject(); |
|
393
|
|
|
if (!$ProductClass) { |
|
394
|
|
|
$this->loadProductClassFromCartItem($CartItem); |
|
395
|
|
|
|
|
396
|
|
|
$ProductClass = $CartItem->getObject(); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
if ($ProductClass->getDelFlg()) { |
|
400
|
|
|
// 商品情報が削除されていたらエラー |
|
401
|
|
|
$this->setError('cart.product.delete'); |
|
402
|
|
|
// カートから削除 |
|
403
|
76 |
|
$this->removeProduct($ProductClass->getId()); |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
76 |
|
return $this->cart; |
|
408
|
|
|
|
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* カートを取得します。 |
|
413
|
|
|
* |
|
414
|
|
|
* @return \Eccube\Entity\Cart |
|
415
|
|
|
*/ |
|
416
|
130 |
|
public function getCart() |
|
417
|
|
|
{ |
|
418
|
130 |
|
foreach ($this->cart->getCartItems() as $CartItem) { |
|
419
|
|
|
|
|
420
|
|
|
/** @var \Eccube\Entity\ProductClass $ProductClass */ |
|
421
|
78 |
|
$ProductClass = $CartItem->getObject(); |
|
422
|
78 |
|
if (!$ProductClass) { |
|
423
|
78 |
|
$this->loadProductClassFromCartItem($CartItem); |
|
424
|
|
|
|
|
425
|
78 |
|
$ProductClass = $CartItem->getObject(); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
78 |
|
if ($ProductClass->getDelFlg() == Constant::DISABLED) { |
|
429
|
|
|
// 商品情報が有効 |
|
430
|
|
|
|
|
431
|
75 |
|
if (!$this->isProductDisplay($ProductClass)) { |
|
432
|
3 |
|
$this->setError('cart.product.not.status'); |
|
433
|
|
|
} else { |
|
|
|
|
|
|
434
|
|
|
|
|
435
|
74 |
|
$productName = $this->getProductName($ProductClass); |
|
436
|
|
|
|
|
437
|
|
|
// 制限数チェック |
|
438
|
74 |
|
$quantity = $this->setProductLimit($ProductClass, $productName, $CartItem->getQuantity()); |
|
439
|
|
|
|
|
440
|
74 |
|
if ($CartItem->getQuantity() != $quantity) { |
|
441
|
|
|
// 個数が異なれば更新 |
|
442
|
8 |
|
$CartItem->setQuantity($quantity); |
|
443
|
75 |
|
$this->cart->setCartItem($CartItem); |
|
444
|
|
|
} |
|
445
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
|
447
|
|
|
} else { |
|
448
|
|
|
// 商品情報が削除されていたらエラー |
|
449
|
6 |
|
$this->setError('cart.product.delete'); |
|
450
|
|
|
// カートから削除 |
|
451
|
130 |
|
$this->removeProduct($ProductClass->getId()); |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
130 |
|
return $this->cart; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* @param string $productClassId |
|
460
|
|
|
* @return \Eccube\Service\CartService |
|
461
|
|
|
*/ |
|
462
|
27 |
|
public function removeProduct($productClassId) |
|
463
|
|
|
{ |
|
464
|
27 |
|
$this->cart->removeCartItemByIdentifier('Eccube\Entity\ProductClass', (string)$productClassId); |
|
|
|
|
|
|
465
|
|
|
|
|
466
|
|
|
// 支払方法の再設定 |
|
467
|
27 |
|
if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
|
|
|
|
|
|
468
|
|
|
|
|
469
|
|
|
// 複数配送対応 |
|
470
|
1 |
|
$productTypes = array(); |
|
471
|
1 |
|
foreach ($this->getCart()->getCartItems() as $item) { |
|
472
|
|
|
/* @var $ProductClass \Eccube\Entity\ProductClass */ |
|
473
|
1 |
|
$ProductClass = $item->getObject(); |
|
474
|
1 |
|
$productTypes[] = $ProductClass->getProductType(); |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
// 配送業者を取得 |
|
478
|
1 |
|
$deliveries = $this->entityManager->getRepository('Eccube\Entity\Delivery')->getDeliveries($productTypes); |
|
479
|
|
|
|
|
480
|
|
|
// 支払方法を取得 |
|
481
|
1 |
|
$payments = $this->entityManager->getRepository('Eccube\Entity\Payment')->findAllowedPayments($deliveries); |
|
482
|
|
|
|
|
483
|
1 |
|
$this->getCart()->setPayments($payments); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
27 |
|
return $this; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
/** |
|
490
|
|
|
* @param string $error |
|
491
|
|
|
* @param string $productName |
|
492
|
|
|
* @return \Eccube\Service\CartService |
|
493
|
|
|
*/ |
|
494
|
22 |
|
public function addError($error = null, $productName = null) |
|
495
|
|
|
{ |
|
496
|
22 |
|
$this->errors[] = $error; |
|
497
|
22 |
|
$this->session->getFlashBag()->add('eccube.front.request.error', $error); |
|
498
|
22 |
|
if (!is_null($productName)) { |
|
499
|
21 |
|
$this->session->getFlashBag()->add('eccube.front.request.product', $productName); |
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
22 |
|
return $this; |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
/** |
|
506
|
|
|
* @param string $productClassId |
|
507
|
|
|
* @return \Eccube\Service\CartService |
|
508
|
|
|
*/ |
|
509
|
10 |
|
public function upProductQuantity($productClassId) |
|
510
|
|
|
{ |
|
511
|
10 |
|
$quantity = $this->getProductQuantity($productClassId) + 1; |
|
512
|
10 |
|
$this->setProductQuantity($productClassId, $quantity); |
|
513
|
|
|
|
|
514
|
7 |
|
return $this; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* @param string $productClassId |
|
519
|
|
|
* @return \Eccube\Service\CartService |
|
520
|
|
|
*/ |
|
521
|
11 |
|
public function downProductQuantity($productClassId) |
|
522
|
|
|
{ |
|
523
|
11 |
|
$quantity = $this->getProductQuantity($productClassId) - 1; |
|
524
|
|
|
|
|
525
|
11 |
|
if ($quantity > 0) { |
|
526
|
7 |
|
$this->setProductQuantity($productClassId, $quantity); |
|
527
|
|
|
} else { |
|
528
|
4 |
|
$this->removeProduct($productClassId); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
9 |
|
return $this; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* @return array |
|
536
|
|
|
*/ |
|
537
|
58 |
|
public function getProductTypes() |
|
538
|
|
|
{ |
|
539
|
|
|
|
|
540
|
58 |
|
$productTypes = array(); |
|
541
|
58 |
|
foreach ($this->getCart()->getCartItems() as $item) { |
|
542
|
|
|
/* @var $ProductClass \Eccube\Entity\ProductClass */ |
|
543
|
58 |
|
$ProductClass = $item->getObject(); |
|
544
|
58 |
|
$productTypes[] = $ProductClass->getProductType(); |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
58 |
|
return array_unique($productTypes); |
|
548
|
|
|
|
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
/** |
|
552
|
|
|
* @return string[] |
|
553
|
|
|
*/ |
|
554
|
3 |
|
public function getErrors() |
|
555
|
|
|
{ |
|
556
|
3 |
|
return $this->errors; |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* @return string[] |
|
561
|
|
|
*/ |
|
562
|
1 |
|
public function getMessages() |
|
563
|
|
|
{ |
|
564
|
1 |
|
return $this->messages; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* @param string $message |
|
569
|
|
|
* @return \Eccube\Service\CartService |
|
570
|
|
|
*/ |
|
571
|
1 |
|
public function setMessage($message) |
|
572
|
|
|
{ |
|
573
|
1 |
|
$this->messages[] = $message; |
|
574
|
|
|
|
|
575
|
1 |
|
return $this; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* @return string |
|
580
|
|
|
*/ |
|
581
|
1 |
|
public function getError() |
|
582
|
|
|
{ |
|
583
|
1 |
|
return $this->error; |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
/** |
|
587
|
|
|
* @param string $error |
|
588
|
|
|
* @return \Eccube\Service\CartService |
|
589
|
|
|
*/ |
|
590
|
10 |
|
public function setError($error = null) |
|
591
|
|
|
{ |
|
592
|
10 |
|
$this->error = $error; |
|
|
|
|
|
|
593
|
10 |
|
$this->session->getFlashBag()->set('eccube.front.request.error', $error); |
|
594
|
|
|
|
|
595
|
10 |
|
return $this; |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
/** |
|
599
|
|
|
* 商品名を取得 |
|
600
|
|
|
* |
|
601
|
|
|
* @param ProductClass $ProductClass |
|
602
|
|
|
* @return string |
|
603
|
|
|
*/ |
|
604
|
125 |
|
private function getProductName(ProductClass $ProductClass) |
|
605
|
|
|
{ |
|
606
|
|
|
|
|
607
|
125 |
|
$productName = $ProductClass->getProduct()->getName(); |
|
608
|
|
|
|
|
609
|
125 |
|
if ($ProductClass->hasClassCategory1()) { |
|
610
|
125 |
|
$productName .= " - ".$ProductClass->getClassCategory1()->getName(); |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
125 |
|
if ($ProductClass->hasClassCategory2()) { |
|
614
|
98 |
|
$productName .= " - ".$ProductClass->getClassCategory2()->getName(); |
|
615
|
|
|
} |
|
616
|
|
|
|
|
617
|
125 |
|
return $productName; |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
|
|
621
|
|
|
/** |
|
622
|
|
|
* 非公開商品の場合、カートから削除 |
|
623
|
|
|
* |
|
624
|
|
|
* @param ProductClass $ProductClass |
|
625
|
|
|
* @return bool |
|
626
|
|
|
*/ |
|
627
|
126 |
|
private function isProductDisplay(ProductClass $ProductClass) |
|
628
|
|
|
{ |
|
629
|
|
|
|
|
630
|
126 |
|
if ($ProductClass->getProduct()->getStatus()->getId() !== Disp::DISPLAY_SHOW) { |
|
631
|
|
|
// 非公開の商品はカートから削除 |
|
632
|
7 |
|
$this->removeProduct($ProductClass->getId()); |
|
633
|
|
|
|
|
634
|
7 |
|
return false; |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
125 |
|
return true; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
|
|
641
|
|
|
/** |
|
642
|
|
|
* 在庫数と販売制限数のチェック |
|
643
|
|
|
* 在庫数または販売制限数以上の個数が設定されていれば、それぞれの個数にセットし、 |
|
644
|
|
|
* 在庫数と販売制限数ともに個数が超えていれば、少ない方を適用させてメッセージを表示する |
|
645
|
|
|
* |
|
646
|
|
|
* @param ProductClass $ProductClass |
|
647
|
|
|
* @param $productName |
|
648
|
|
|
* @param $quantity |
|
649
|
|
|
* @return int|string |
|
650
|
|
|
*/ |
|
651
|
124 |
|
private function setProductLimit(ProductClass $ProductClass, $productName, $quantity) |
|
652
|
|
|
{ |
|
653
|
|
|
|
|
654
|
|
|
/** |
|
655
|
|
|
* 実際の在庫は ProductClass::ProductStock だが、購入時にロックがかかるため、 |
|
656
|
|
|
* ここでは ProductClass::stock で在庫のチェックをする |
|
657
|
|
|
*/ |
|
658
|
|
|
|
|
659
|
124 |
|
$tmp_quantity = 0; |
|
660
|
|
|
|
|
661
|
|
|
// 在庫数(在庫無制限の場合、null) |
|
662
|
124 |
|
$stock = $ProductClass->getStock(); |
|
663
|
|
|
// 在庫無制限(在庫無制限の場合、1) |
|
664
|
124 |
|
$stockUnlimited = $ProductClass->getStockUnlimited(); |
|
665
|
|
|
|
|
666
|
|
|
// 販売制限数(設定されていなければnull) |
|
667
|
124 |
|
$saleLimit = $ProductClass->getSaleLimit(); |
|
668
|
|
|
|
|
669
|
124 |
|
if ($stockUnlimited) { |
|
670
|
|
|
// 在庫無制限 |
|
671
|
|
|
|
|
672
|
79 |
|
if ($saleLimit && $saleLimit < $quantity) { |
|
673
|
|
|
// 販売制限数を超えていれば販売制限数をセット |
|
674
|
|
|
$tmp_quantity = $saleLimit; |
|
675
|
79 |
|
$this->addError('cart.over.sale_limit', $productName); |
|
676
|
|
|
} |
|
677
|
|
|
} else { |
|
678
|
|
|
// 在庫制限あり |
|
679
|
|
|
|
|
680
|
46 |
|
if ($stock < 1) { |
|
681
|
|
|
// 在庫がなければカートから削除 |
|
682
|
6 |
|
$this->addError('cart.zero.stock', $productName); |
|
683
|
6 |
|
$this->removeProduct($ProductClass->getId()); |
|
684
|
|
|
} else { |
|
685
|
|
|
// 在庫数チェックと販売制限数チェックどちらを適用するか設定 |
|
686
|
46 |
|
$message = 'cart.over.stock'; |
|
687
|
46 |
|
if ($saleLimit) { |
|
688
|
8 |
|
if ($stock > $saleLimit) { |
|
689
|
|
|
// 販売制限数チェック |
|
690
|
8 |
|
$limit = $saleLimit; |
|
691
|
8 |
|
$message = 'cart.over.sale_limit'; |
|
692
|
|
|
} else { |
|
693
|
|
|
// 在庫数チェック |
|
694
|
8 |
|
$limit = $stock; |
|
695
|
|
|
} |
|
696
|
|
|
} else { |
|
697
|
|
|
// 在庫数チェック |
|
698
|
44 |
|
$limit = $stock; |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
46 |
|
if ($limit < $quantity) { |
|
702
|
|
|
// 在庫数、販売制限数を超えていれば購入可能数までをセット |
|
703
|
15 |
|
$tmp_quantity = $limit; |
|
704
|
15 |
|
$this->addError($message, $productName); |
|
705
|
|
|
} |
|
706
|
|
|
} |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
124 |
|
if ($tmp_quantity) { |
|
710
|
15 |
|
$quantity = $tmp_quantity; |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
124 |
|
return $quantity; |
|
714
|
|
|
|
|
715
|
|
|
} |
|
716
|
|
|
|
|
717
|
|
|
} |
|
718
|
|
|
|