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\Controller; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Event\EccubeEvents; |
29
|
|
|
use Eccube\Event\EventArgs; |
30
|
|
|
use Eccube\Exception\CartException; |
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
32
|
|
|
|
33
|
|
|
class CartController extends AbstractController |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* カート画面. |
37
|
|
|
* |
38
|
|
|
* @param Application $app |
39
|
|
|
* @param Request $request |
|
|
|
|
40
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
41
|
|
|
*/ |
42
|
32 |
|
public function index(Application $app, Request $request) |
43
|
|
|
{ |
44
|
32 |
|
$Cart = $app['eccube.service.cart']->getCart(); |
45
|
|
|
|
46
|
|
|
// FRONT_CART_INDEX_INITIALIZE |
47
|
32 |
|
$event = new EventArgs( |
48
|
32 |
|
array(), |
49
|
|
|
$request |
50
|
|
|
); |
51
|
32 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_INDEX_INITIALIZE, $event); |
52
|
|
|
|
53
|
|
|
/* @var $BaseInfo \Eccube\Entity\BaseInfo */ |
54
|
|
|
/* @var $Cart \Eccube\Entity\Cart */ |
55
|
32 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
56
|
|
|
|
57
|
32 |
|
$isDeliveryFree = false; |
58
|
32 |
|
$least = 0; |
59
|
32 |
|
$quantity = 0; |
60
|
32 |
|
if ($BaseInfo->getDeliveryFreeAmount()) { |
61
|
|
|
if ($BaseInfo->getDeliveryFreeAmount() <= $Cart->getTotalPrice()) { |
62
|
|
|
// 送料無料(金額)を超えている |
63
|
|
|
$isDeliveryFree = true; |
64
|
|
|
} else { |
65
|
|
|
$least = $BaseInfo->getDeliveryFreeAmount() - $Cart->getTotalPrice(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
32 |
|
if ($BaseInfo->getDeliveryFreeQuantity()) { |
70
|
|
|
if ($BaseInfo->getDeliveryFreeQuantity() <= $Cart->getTotalQuantity()) { |
71
|
|
|
// 送料無料(個数)を超えている |
72
|
|
|
$isDeliveryFree = true; |
73
|
|
|
} else { |
74
|
|
|
$quantity = $BaseInfo->getDeliveryFreeQuantity() - $Cart->getTotalQuantity(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// FRONT_CART_INDEX_COMPLETE |
79
|
32 |
|
$event = new EventArgs( |
80
|
32 |
|
array(), |
81
|
|
|
$request |
82
|
|
|
); |
83
|
32 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_INDEX_COMPLETE, $event); |
84
|
|
|
|
85
|
32 |
|
if ($event->hasResponse()) { |
86
|
|
|
return $event->getResponse(); |
87
|
|
|
} |
88
|
|
|
|
89
|
32 |
|
return $app->render( |
90
|
32 |
|
'Cart/index.twig', |
91
|
|
|
array( |
92
|
32 |
|
'Cart' => $Cart, |
93
|
32 |
|
'least' => $least, |
94
|
32 |
|
'quantity' => $quantity, |
95
|
32 |
|
'is_delivery_free' => $isDeliveryFree, |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* カートに商品を追加する. |
102
|
|
|
* |
103
|
|
|
* @param Application $app |
104
|
|
|
* @param Request $request |
|
|
|
|
105
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
106
|
|
|
*/ |
107
|
112 |
|
public function add(Application $app, Request $request) |
108
|
|
|
{ |
109
|
112 |
|
$productClassId = $request->get('product_class_id'); |
110
|
112 |
|
$quantity = $request->request->has('quantity') ? $request->get('quantity') : 1; |
111
|
|
|
|
112
|
|
|
// FRONT_CART_ADD_INITIALIZE |
113
|
112 |
|
$event = new EventArgs( |
114
|
|
|
array( |
115
|
112 |
|
'productClassId' => $productClassId, |
116
|
112 |
|
'quantity' => $quantity, |
117
|
|
|
), |
118
|
|
|
$request |
119
|
|
|
); |
120
|
112 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_INITIALIZE, $event); |
121
|
|
|
|
122
|
|
|
try { |
|
|
|
|
123
|
|
|
|
124
|
112 |
|
$productClassId = $event->getArgument('productClassId'); |
125
|
112 |
|
$quantity = $event->getArgument('quantity'); |
126
|
|
|
|
127
|
112 |
|
log_info('カート追加処理開始', array('product_class_id' => $productClassId, 'quantity' => $quantity)); |
128
|
|
|
|
129
|
112 |
|
$app['eccube.service.cart']->addProduct($productClassId, $quantity)->save(); |
130
|
|
|
|
131
|
111 |
|
log_info('カート追加処理完了', array('product_class_id' => $productClassId, 'quantity' => $quantity)); |
132
|
|
|
|
133
|
|
|
// FRONT_CART_ADD_COMPLETE |
134
|
111 |
|
$event = new EventArgs( |
135
|
|
|
array( |
136
|
111 |
|
'productClassId' => $productClassId, |
137
|
111 |
|
'quantity' => $quantity, |
138
|
|
|
), |
139
|
|
|
$request |
140
|
|
|
); |
141
|
111 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_COMPLETE, $event); |
142
|
|
|
|
143
|
111 |
|
if ($event->hasResponse()) { |
144
|
111 |
|
return $event->getResponse(); |
145
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
1 |
|
} catch (CartException $e) { |
|
|
|
|
148
|
|
|
|
149
|
1 |
|
log_info('カート追加エラー', array($e->getMessage())); |
150
|
|
|
|
151
|
|
|
// FRONT_CART_ADD_EXCEPTION |
152
|
1 |
|
$event = new EventArgs( |
153
|
|
|
array( |
154
|
1 |
|
'exception' => $e, |
155
|
|
|
), |
156
|
|
|
$request |
157
|
|
|
); |
158
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_EXCEPTION, $event); |
159
|
|
|
|
160
|
1 |
|
if ($event->hasResponse()) { |
161
|
|
|
return $event->getResponse(); |
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
$app->addRequestError($e->getMessage()); |
165
|
|
|
} |
166
|
|
|
|
167
|
112 |
|
return $app->redirect($app->url('cart')); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
|
|
|
|
171
|
|
|
* カートに入っている商品の個数を1増やす. |
172
|
|
|
* |
173
|
|
|
* @param Application $app |
|
|
|
|
174
|
|
|
* @param Request $request |
|
|
|
|
175
|
|
|
* @param $productClassId |
|
|
|
|
176
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
177
|
|
|
*/ |
178
|
9 |
View Code Duplication |
public function up(Application $app, Request $request, $productClassId) |
|
|
|
|
179
|
|
|
{ |
180
|
9 |
|
$this->isTokenValid($app); |
181
|
|
|
|
182
|
|
|
// FRONT_CART_UP_INITIALIZE |
183
|
9 |
|
$event = new EventArgs( |
184
|
|
|
array( |
185
|
9 |
|
'productClassId' => $productClassId, |
186
|
|
|
), |
187
|
|
|
$request |
188
|
|
|
); |
189
|
9 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_INITIALIZE, $event); |
190
|
|
|
|
191
|
|
|
try { |
|
|
|
|
192
|
|
|
|
193
|
9 |
|
log_info('カート加算処理開始', array('product_class_id' => $productClassId)); |
194
|
|
|
|
195
|
9 |
|
$productClassId = $event->getArgument('productClassId'); |
196
|
|
|
|
197
|
9 |
|
$app['eccube.service.cart']->upProductQuantity($productClassId)->save(); |
198
|
|
|
|
199
|
|
|
// FRONT_CART_UP_COMPLETE |
200
|
6 |
|
$event = new EventArgs( |
201
|
|
|
array( |
202
|
6 |
|
'productClassId' => $productClassId, |
203
|
|
|
), |
204
|
|
|
$request |
205
|
|
|
); |
206
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_COMPLETE, $event); |
207
|
|
|
|
208
|
6 |
|
if ($event->hasResponse()) { |
209
|
|
|
return $event->getResponse(); |
210
|
|
|
} |
211
|
|
|
|
212
|
6 |
|
log_info('カート加算処理完了', array('product_class_id' => $productClassId)); |
213
|
|
|
|
|
|
|
|
214
|
3 |
|
} catch (CartException $e) { |
|
|
|
|
215
|
|
|
|
216
|
3 |
|
log_info('カート加算エラー', array($e->getMessage())); |
217
|
|
|
|
218
|
|
|
// FRONT_CART_UP_EXCEPTION |
219
|
3 |
|
$event = new EventArgs( |
220
|
|
|
array( |
221
|
3 |
|
'exception' => $e, |
222
|
|
|
), |
223
|
|
|
$request |
224
|
|
|
); |
225
|
3 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_EXCEPTION, $event); |
226
|
|
|
|
227
|
3 |
|
if ($event->hasResponse()) { |
228
|
|
|
return $event->getResponse(); |
229
|
|
|
} |
230
|
|
|
|
231
|
3 |
|
$app->addRequestError($e->getMessage()); |
232
|
|
|
} |
233
|
|
|
|
234
|
9 |
|
return $app->redirect($app->url('cart')); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
|
|
|
|
238
|
|
|
* カートに入っている商品の個数を1減らす. |
239
|
|
|
* マイナスになる場合は, 商品をカートから削除する. |
240
|
|
|
* |
241
|
|
|
* @param Application $app |
|
|
|
|
242
|
|
|
* @param Request $request |
|
|
|
|
243
|
|
|
* @param $productClassId |
|
|
|
|
244
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
245
|
|
|
*/ |
246
|
9 |
View Code Duplication |
public function down(Application $app, Request $request, $productClassId) |
|
|
|
|
247
|
|
|
{ |
248
|
9 |
|
$this->isTokenValid($app); |
249
|
|
|
|
250
|
|
|
// FRONT_CART_DOWN_INITIALIZE |
251
|
9 |
|
$event = new EventArgs( |
252
|
|
|
array( |
253
|
9 |
|
'productClassId' => $productClassId, |
254
|
|
|
), |
255
|
|
|
$request |
256
|
|
|
); |
257
|
9 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_INITIALIZE, $event); |
258
|
|
|
|
259
|
|
|
try { |
|
|
|
|
260
|
|
|
|
261
|
9 |
|
log_info('カート減算処理開始', array('product_class_id' => $productClassId)); |
262
|
|
|
|
263
|
9 |
|
$productClassId = $event->getArgument('productClassId'); |
264
|
9 |
|
$app['eccube.service.cart']->downProductQuantity($productClassId)->save(); |
265
|
|
|
|
266
|
|
|
// FRONT_CART_UP_COMPLETE |
267
|
7 |
|
$event = new EventArgs( |
268
|
|
|
array( |
269
|
7 |
|
'productClassId' => $productClassId, |
270
|
|
|
), |
271
|
|
|
$request |
272
|
|
|
); |
273
|
7 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_COMPLETE, $event); |
274
|
|
|
|
275
|
7 |
|
if ($event->hasResponse()) { |
276
|
|
|
return $event->getResponse(); |
277
|
|
|
} |
278
|
|
|
|
279
|
7 |
|
log_info('カート減算処理完了', array('product_class_id' => $productClassId)); |
280
|
|
|
|
|
|
|
|
281
|
2 |
|
} catch (CartException $e) { |
282
|
2 |
|
log_info('カート減算エラー', array($e->getMessage())); |
283
|
|
|
|
284
|
|
|
// FRONT_CART_DOWN_EXCEPTION |
285
|
2 |
|
$event = new EventArgs( |
286
|
|
|
array( |
287
|
2 |
|
'exception' => $e, |
288
|
|
|
), |
289
|
|
|
$request |
290
|
|
|
); |
291
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_EXCEPTION, $event); |
292
|
|
|
|
293
|
2 |
|
if ($event->hasResponse()) { |
294
|
|
|
return $event->getResponse(); |
295
|
|
|
} |
296
|
|
|
|
297
|
2 |
|
$app->addRequestError($e->getMessage()); |
298
|
|
|
} |
299
|
|
|
|
300
|
9 |
|
return $app->redirect($app->url('cart')); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
|
|
|
|
304
|
|
|
* カートに入っている商品を削除する. |
305
|
|
|
* |
306
|
|
|
* @param Application $app |
|
|
|
|
307
|
|
|
* @param Request $request |
|
|
|
|
308
|
|
|
* @param $productClassId |
|
|
|
|
309
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
310
|
|
|
*/ |
311
|
2 |
|
public function remove(Application $app, Request $request, $productClassId) |
312
|
|
|
{ |
313
|
2 |
|
$this->isTokenValid($app); |
314
|
|
|
|
315
|
2 |
|
log_info('カート削除処理開始', array('product_class_id' => $productClassId)); |
316
|
|
|
|
317
|
|
|
// FRONT_CART_REMOVE_INITIALIZE |
318
|
2 |
|
$event = new EventArgs( |
319
|
|
|
array( |
320
|
2 |
|
'productClassId' => $productClassId, |
321
|
|
|
), |
322
|
|
|
$request |
323
|
|
|
); |
324
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_REMOVE_INITIALIZE, $event); |
325
|
|
|
|
326
|
2 |
|
$productClassId = $event->getArgument('productClassId'); |
327
|
2 |
|
$app['eccube.service.cart']->removeProduct($productClassId)->save(); |
328
|
|
|
|
329
|
2 |
|
log_info('カート削除処理完了', array('product_class_id' => $productClassId)); |
330
|
|
|
|
331
|
|
|
// FRONT_CART_REMOVE_COMPLETE |
332
|
2 |
|
$event = new EventArgs( |
333
|
|
|
array( |
334
|
2 |
|
'productClassId' => $productClassId, |
335
|
|
|
), |
336
|
|
|
$request |
337
|
|
|
); |
338
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_REMOVE_COMPLETE, $event); |
339
|
|
|
|
340
|
2 |
|
if ($event->hasResponse()) { |
341
|
|
|
return $event->getResponse(); |
342
|
|
|
} |
343
|
|
|
|
344
|
2 |
|
return $app->redirect($app->url('cart')); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
|
|
|
|
348
|
|
|
* カートに商品を個数を指定して設定する. |
349
|
|
|
* |
350
|
|
|
* @param Application $app |
|
|
|
|
351
|
|
|
* @param Request $request |
|
|
|
|
352
|
|
|
* @param $productClassId |
|
|
|
|
353
|
|
|
* @param $quantity |
|
|
|
|
354
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
355
|
|
|
* @throws CartException |
356
|
|
|
* |
357
|
|
|
* @deprecated since 3.0.0, to be removed in 3.1 |
358
|
|
|
*/ |
359
|
|
|
public function setQuantity(Application $app, Request $request, $productClassId, $quantity) |
|
|
|
|
360
|
|
|
{ |
361
|
|
|
$this->isTokenValid($app); |
362
|
|
|
|
363
|
|
|
$app['eccube.service.cart']->setProductQuantity($productClassId, $quantity)->save(); |
364
|
|
|
|
365
|
|
|
return $app->redirect($app->url('cart')); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* カートをロック状態に設定し、購入確認画面へ遷移する. |
370
|
|
|
* |
371
|
|
|
* @param Application $app |
372
|
|
|
* @param Request $request |
|
|
|
|
373
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
374
|
|
|
*/ |
375
|
21 |
|
public function buystep(Application $app, Request $request) |
376
|
|
|
{ |
377
|
|
|
// FRONT_CART_BUYSTEP_INITIALIZE |
378
|
21 |
|
$event = new EventArgs( |
379
|
21 |
|
array(), |
380
|
|
|
$request |
381
|
|
|
); |
382
|
21 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_BUYSTEP_INITIALIZE, $event); |
383
|
|
|
|
384
|
21 |
|
$app['eccube.service.cart']->lock(); |
385
|
21 |
|
$app['eccube.service.cart']->save(); |
386
|
|
|
|
387
|
|
|
// FRONT_CART_BUYSTEP_COMPLETE |
388
|
21 |
|
$event = new EventArgs( |
389
|
21 |
|
array(), |
390
|
|
|
$request |
391
|
|
|
); |
392
|
21 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_BUYSTEP_COMPLETE, $event); |
393
|
|
|
|
394
|
21 |
|
if ($event->hasResponse()) { |
395
|
|
|
return $event->getResponse(); |
396
|
|
|
} |
397
|
|
|
|
398
|
21 |
|
return $app->redirect($app->url('shopping')); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|