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