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
|
|
|
namespace Eccube\Controller; |
25
|
|
|
|
26
|
|
|
use Eccube\Annotation\ForwardOnly; |
27
|
|
|
use Eccube\Entity\BaseInfo; |
28
|
|
|
use Eccube\Entity\Customer; |
29
|
|
|
use Eccube\Entity\CustomerAddress; |
30
|
|
|
use Eccube\Entity\Master\OrderStatus; |
31
|
|
|
use Eccube\Entity\Order; |
32
|
|
|
use Eccube\Event\EccubeEvents; |
33
|
|
|
use Eccube\Event\EventArgs; |
34
|
|
|
use Eccube\Exception\CartException; |
35
|
|
|
use Eccube\Exception\ShoppingException; |
36
|
|
|
use Eccube\Form\Type\Front\CustomerLoginType; |
37
|
|
|
use Eccube\Form\Type\Front\ShoppingShippingType; |
38
|
|
|
use Eccube\Form\Type\Shopping\OrderType; |
39
|
|
|
use Eccube\Repository\CustomerAddressRepository; |
40
|
|
|
use Eccube\Service\CartService; |
41
|
|
|
use Eccube\Service\OrderHelper; |
42
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
43
|
|
|
use Eccube\Service\ShoppingService; |
44
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
45
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
46
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
47
|
|
|
use Symfony\Component\Form\FormError; |
48
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
49
|
|
|
use Symfony\Component\HttpFoundation\Request; |
50
|
|
|
use Symfony\Component\HttpFoundation\Response; |
51
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
52
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Route(service=ShoppingController::class) |
56
|
|
|
*/ |
57
|
|
|
class ShoppingController extends AbstractShoppingController |
58
|
|
|
{ |
59
|
|
|
/** |
60
|
|
|
* @var BaseInfo |
61
|
|
|
*/ |
62
|
|
|
protected $BaseInfo; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var OrderHelper |
66
|
|
|
*/ |
67
|
|
|
protected $orderHelper; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var CartService |
71
|
|
|
*/ |
72
|
|
|
protected $cartService; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var ShoppingService |
76
|
|
|
*/ |
77
|
|
|
protected $shoppingService; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var CustomerAddressRepository |
81
|
|
|
*/ |
82
|
|
|
protected $customerAddressRepository; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var ParameterBag |
86
|
|
|
*/ |
87
|
|
|
protected $parameterBag; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* ShoppingController constructor. |
91
|
|
|
* |
92
|
|
|
* @param BaseInfo $BaseInfo |
|
|
|
|
93
|
|
|
* @param OrderHelper $orderHelper |
|
|
|
|
94
|
|
|
* @param CartService $cartService |
|
|
|
|
95
|
|
|
* @param ShoppingService $shoppingService |
|
|
|
|
96
|
|
|
* @param CustomerAddressRepository $customerAddressRepository |
97
|
|
|
* @param ParameterBag $parameterBag |
|
|
|
|
98
|
|
|
*/ |
99
|
36 |
|
public function __construct( |
100
|
|
|
BaseInfo $BaseInfo, |
101
|
|
|
OrderHelper $orderHelper, |
102
|
|
|
CartService $cartService, |
103
|
|
|
ShoppingService $shoppingService, |
104
|
|
|
CustomerAddressRepository $customerAddressRepository, |
105
|
|
|
ParameterBag $parameterBag |
106
|
|
|
) { |
107
|
36 |
|
$this->BaseInfo = $BaseInfo; |
108
|
36 |
|
$this->orderHelper = $orderHelper; |
109
|
36 |
|
$this->cartService = $cartService; |
110
|
36 |
|
$this->shoppingService = $shoppingService; |
111
|
36 |
|
$this->customerAddressRepository = $customerAddressRepository; |
112
|
36 |
|
$this->parameterBag = $parameterBag; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
|
|
|
|
116
|
|
|
* 購入画面表示 |
117
|
|
|
* |
118
|
|
|
* @Route("/shopping", name="shopping") |
119
|
|
|
* @Template("Shopping/index.twig") |
120
|
|
|
*/ |
|
|
|
|
121
|
28 |
|
public function index(Request $request) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
// カートチェック |
124
|
28 |
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
125
|
28 |
|
if ($response->isRedirection() || $response->getContent()) { |
126
|
3 |
|
return $response; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// 受注情報を初期化 |
130
|
25 |
|
$response = $this->forwardToRoute('shopping_initialize_order'); |
131
|
25 |
|
if ($response->isRedirection() || $response->getContent()) { |
132
|
|
|
return $response; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** @var Order $Order */ |
136
|
25 |
|
$Order = $this->parameterBag->get('Order'); |
137
|
|
|
|
138
|
|
|
// 単価集計 |
139
|
25 |
|
$flowResult = $this->executePurchaseFlow($Order); |
140
|
|
|
|
141
|
|
|
// フォームを生成する |
142
|
25 |
|
$this->forwardToRoute('shopping_create_form'); |
143
|
|
|
|
144
|
25 |
|
if ($flowResult->hasWarning() || $flowResult->hasError()) { |
145
|
10 |
|
return $this->redirectToRoute('cart'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// 複数配送の場合、エラーメッセージを一度だけ表示 |
149
|
20 |
|
$this->forwardToRoute('shopping_handle_multiple_errors'); |
150
|
20 |
|
$form = $this->parameterBag->get(OrderType::class); |
151
|
|
|
|
152
|
|
|
return [ |
153
|
20 |
|
'form' => $form->createView(), |
154
|
20 |
|
'Order' => $Order, |
155
|
|
|
]; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
|
|
|
|
159
|
|
|
* 購入確認画面から, 他の画面へのリダイレクト. |
160
|
|
|
* 配送業者や支払方法、お問い合わせ情報をDBに保持してから遷移する. |
161
|
|
|
* |
162
|
|
|
* @Route("/shopping/redirect", name="shopping_redirect_to") |
163
|
|
|
* @Template("Shopping/index.twig") |
164
|
|
|
*/ |
|
|
|
|
165
|
10 |
View Code Duplication |
public function redirectTo(Request $request) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
// カートチェック |
168
|
10 |
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
169
|
10 |
|
if ($response->isRedirection() || $response->getContent()) { |
170
|
|
|
return $response; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// 受注の存在チェック |
174
|
10 |
|
$response = $this->forwardToRoute('shopping_exists_order'); |
175
|
10 |
|
if ($response->isRedirection() || $response->getContent()) { |
176
|
|
|
return $response; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
// フォームの生成 |
180
|
10 |
|
$this->forwardToRoute('shopping_create_form'); |
181
|
10 |
|
$form = $this->parameterBag->get(OrderType::class); |
182
|
10 |
|
$form->handleRequest($request); |
183
|
|
|
|
184
|
|
|
// 各種変更ページへリダイレクトする |
185
|
10 |
|
$response = $this->forwardToRoute('shopping_redirect_to_change'); |
186
|
10 |
|
if ($response->isRedirection() || $response->getContent()) { |
187
|
7 |
|
return $response; |
188
|
|
|
} |
189
|
3 |
|
$form = $this->parameterBag->get(OrderType::class); |
190
|
3 |
|
$Order = $this->parameterBag->get('Order'); |
191
|
|
|
|
192
|
|
|
return [ |
193
|
3 |
|
'form' => $form->createView(), |
194
|
3 |
|
'Order' => $Order, |
195
|
|
|
]; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
|
|
|
|
199
|
|
|
* 購入処理 |
200
|
|
|
* |
201
|
|
|
* @Route("/shopping/confirm", name="shopping_confirm") |
202
|
|
|
* @Method("POST") |
203
|
|
|
* @Template("Shopping/confirm.twig") |
204
|
|
|
*/ |
|
|
|
|
205
|
2 |
View Code Duplication |
public function confirm(Request $request) |
|
|
|
|
206
|
|
|
{ |
207
|
|
|
// カートチェック |
208
|
2 |
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
209
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
210
|
|
|
return $response; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
// 受注の存在チェック |
214
|
2 |
|
$response = $this->forwardToRoute('shopping_exists_order'); |
215
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
216
|
|
|
return $response; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
// フォームの生成 |
220
|
2 |
|
$this->forwardToRoute('shopping_create_form'); |
221
|
2 |
|
$form = $this->parameterBag->get(OrderType::class); |
222
|
2 |
|
$form->handleRequest($request); |
223
|
|
|
|
224
|
2 |
|
$form = $this->parameterBag->get(OrderType::class); |
225
|
2 |
|
$Order = $this->parameterBag->get('Order'); |
226
|
|
|
|
227
|
2 |
|
$flowResult = $this->executePurchaseFlow($Order); |
228
|
2 |
|
if ($flowResult->hasWarning() || $flowResult->hasError()) { |
229
|
|
|
return $this->redirectToRoute('shopping_error'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return [ |
233
|
2 |
|
'form' => $form->createView(), |
234
|
2 |
|
'Order' => $Order, |
235
|
|
|
]; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
|
|
|
|
239
|
|
|
* 購入処理 |
240
|
|
|
* |
241
|
|
|
* @Route("/shopping/order", name="shopping_order") |
242
|
|
|
* @Method("POST") |
243
|
|
|
* @Template("Shopping/index.twig") |
244
|
|
|
*/ |
|
|
|
|
245
|
2 |
|
public function order(Request $request) |
246
|
|
|
{ |
247
|
|
|
// カートチェック |
248
|
2 |
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
249
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
250
|
|
|
return $response; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
// 受注の存在チェック |
254
|
2 |
|
$response = $this->forwardToRoute('shopping_exists_order'); |
255
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
256
|
|
|
return $response; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
// form作成 |
260
|
|
|
// FIXME イベントハンドラを外から渡したい |
261
|
2 |
|
$this->forwardToRoute('shopping_create_form'); |
262
|
|
|
|
263
|
2 |
|
$form = $this->parameterBag->get(OrderType::class); |
264
|
2 |
|
$Order = $this->parameterBag->get('Order'); |
265
|
2 |
|
$usePoint = $Order->getUsePoint(); |
266
|
|
|
|
267
|
2 |
|
$form->handleRequest($request); |
268
|
2 |
|
$Order->setUsePoint($usePoint); |
269
|
|
|
|
270
|
|
|
// 受注処理 |
271
|
2 |
|
$response = $this->forwardToRoute('shopping_complete_order'); |
272
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
273
|
2 |
|
return $response; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
log_info('購入チェックエラー', [$Order->getId()]); |
277
|
|
|
|
278
|
|
|
return [ |
279
|
|
|
'form' => $form->createView(), |
280
|
|
|
'Order' => $Order, |
281
|
|
|
]; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* 支払方法バーリデト |
286
|
|
|
*/ |
287
|
|
|
private function isValidPayment(Application $app, $form) |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
$data = $form->getData(); |
290
|
|
|
$paymentId = $data['payment']->getId(); |
291
|
|
|
$shippings = $data['shippings']; |
292
|
|
|
$validCount = count($shippings); |
293
|
|
|
foreach ($shippings as $Shipping) { |
294
|
|
|
$payments = $app['eccube.repository.payment']->findPayments($Shipping->getDelivery()); |
295
|
|
|
if ($payments == null) { |
296
|
|
|
continue; |
297
|
|
|
} |
298
|
|
|
foreach ($payments as $payment) { |
299
|
|
|
if ($payment['id'] == $paymentId) { |
300
|
|
|
$validCount--; |
301
|
|
|
continue; |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
if ($validCount == 0) { |
306
|
|
|
return true; |
307
|
|
|
} |
308
|
|
|
$form->get('payment')->addError(new FormError('front.shopping.payment.error')); |
309
|
|
|
|
310
|
|
|
return false; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
|
|
|
|
314
|
|
|
* 購入完了画面表示 |
315
|
|
|
* |
316
|
|
|
* @Route("/shopping/complete", name="shopping_complete") |
317
|
|
|
* @Template("Shopping/complete.twig") |
318
|
|
|
*/ |
|
|
|
|
319
|
1 |
|
public function complete(Request $request) |
|
|
|
|
320
|
|
|
{ |
321
|
|
|
// 受注IDを取得 |
322
|
1 |
|
$orderId = $this->session->get($this->sessionOrderKey); |
323
|
|
|
|
324
|
1 |
|
$event = new EventArgs( |
325
|
|
|
[ |
326
|
1 |
|
'orderId' => $orderId, |
327
|
|
|
], |
328
|
1 |
|
$request |
329
|
|
|
); |
330
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event); |
331
|
|
|
|
332
|
1 |
|
if ($event->getResponse() !== null) { |
333
|
|
|
return $event->getResponse(); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
// 受注に関連するセッションを削除 |
337
|
1 |
|
$this->session->remove($this->sessionOrderKey); |
338
|
1 |
|
$this->session->remove($this->sessionMultipleKey); |
339
|
|
|
|
340
|
|
|
// 非会員用セッション情報を空の配列で上書きする(プラグイン互換性保持のために削除はしない) |
341
|
1 |
|
$this->session->set($this->sessionKey, []); |
342
|
1 |
|
$this->session->set($this->sessionCustomerAddressKey, []); |
343
|
|
|
|
344
|
1 |
|
log_info('購入処理完了', [$orderId]); |
345
|
|
|
|
346
|
1 |
|
$hasNextCart = !empty($this->cartService->getCarts()); |
347
|
|
|
|
348
|
|
|
return [ |
349
|
1 |
|
'orderId' => $orderId, |
350
|
1 |
|
'hasNextCart' => $hasNextCart, |
351
|
|
|
]; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
|
|
|
|
355
|
|
|
* お届け先の設定一覧からの選択 |
356
|
|
|
* |
357
|
|
|
* @Route("/shopping/shipping/{id}", name="shopping_shipping", requirements={"id" = "\d+"}) |
358
|
|
|
* @Template("Shopping/shipping.twig") |
359
|
|
|
*/ |
|
|
|
|
360
|
2 |
|
public function shipping(Request $request, $id) |
361
|
|
|
{ |
362
|
|
|
// カートチェック |
363
|
2 |
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
364
|
2 |
|
if ($response->isRedirection() || $response->getContent()) { |
365
|
|
|
return $response; |
366
|
|
|
} |
367
|
|
|
|
368
|
2 |
|
if ('POST' === $request->getMethod()) { |
369
|
2 |
|
$address = $request->get('address'); |
370
|
|
|
|
371
|
2 |
|
if (is_null($address)) { |
372
|
|
|
// 選択されていなければエラー |
373
|
2 |
|
log_info('お届け先入力チェックエラー'); |
374
|
|
|
|
375
|
|
|
return [ |
376
|
2 |
|
'Customer' => $this->getUser(), |
377
|
2 |
|
'shippingId' => $id, |
378
|
|
|
'error' => true, |
379
|
|
|
]; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
// 選択されたお届け先情報を取得 |
383
|
|
|
$CustomerAddress = $this->customerAddressRepository->findOneBy( |
384
|
|
|
[ |
385
|
|
|
'Customer' => $this->getUser(), |
386
|
|
|
'id' => $address, |
387
|
|
|
] |
388
|
|
|
); |
389
|
|
|
if (is_null($CustomerAddress)) { |
390
|
|
|
throw new NotFoundHttpException(trans('shoppingcontroller.text.error.selected_address')); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** @var Order $Order */ |
394
|
|
|
$Order = $this->shoppingService->getOrder(OrderStatus::PROCESSING); |
395
|
|
|
if (!$Order) { |
396
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
397
|
|
|
$this->addError('front.shopping.order.error'); |
398
|
|
|
|
399
|
|
|
return $this->redirectToRoute('shopping_error'); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
$Shipping = $Order->findShipping($id); |
403
|
|
|
if (!$Shipping) { |
404
|
|
|
throw new NotFoundHttpException(trans('shoppingcontroller.text.error.address')); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
log_info('お届先情報更新開始', [$Shipping->getId()]); |
408
|
|
|
|
409
|
|
|
// お届け先情報を更新 |
410
|
|
|
$Shipping->setFromCustomerAddress($CustomerAddress); |
411
|
|
|
|
412
|
|
|
// 配送料金の設定 |
413
|
|
|
$this->shoppingService->setShippingDeliveryFee($Shipping); |
414
|
|
|
|
415
|
|
|
// 合計金額の再計算 |
416
|
|
|
$flowResult = $this->executePurchaseFlow($Order); |
417
|
|
|
if ($flowResult->hasWarning() || $flowResult->hasError()) { |
418
|
|
|
return $this->redirectToRoute('shopping_error'); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
// 配送先を更新 |
422
|
|
|
$this->entityManager->flush(); |
423
|
|
|
|
424
|
|
|
$event = new EventArgs( |
425
|
|
|
[ |
426
|
|
|
'Order' => $Order, |
427
|
|
|
'shippingId' => $id, |
428
|
|
|
], |
429
|
|
|
$request |
430
|
|
|
); |
431
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event); |
432
|
|
|
|
433
|
|
|
log_info('お届先情報更新完了', [$Shipping->getId()]); |
434
|
|
|
|
435
|
|
|
return $this->redirectToRoute('shopping'); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
return [ |
439
|
1 |
|
'Customer' => $this->getUser(), |
440
|
1 |
|
'shippingId' => $id, |
441
|
|
|
'error' => false, |
442
|
|
|
]; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
|
|
|
|
446
|
|
|
* お届け先の設定(非会員でも使用する) |
447
|
|
|
* |
448
|
|
|
* @Route("/shopping/shipping_edit/{id}", name="shopping_shipping_edit", requirements={"id" = "\d+"}) |
449
|
|
|
* @Template("Shopping/shipping_edit.twig") |
450
|
|
|
*/ |
|
|
|
|
451
|
|
|
public function shippingEdit(Request $request, $id) |
452
|
|
|
{ |
453
|
|
|
// 配送先住所最大値判定 |
454
|
|
|
$Customer = $this->getUser(); |
455
|
|
|
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) { |
456
|
|
|
$addressCurrNum = count($this->getUser()->getCustomerAddresses()); |
457
|
|
|
$addressMax = $this->eccubeConfig['eccube_deliv_addr_max']; |
458
|
|
|
if ($addressCurrNum >= $addressMax) { |
459
|
|
|
throw new NotFoundHttpException(trans('shoppingcontroller.text.error.number_of_address')); |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
// カートチェック |
464
|
|
|
$response = $this->forwardToRoute('shopping_check_to_cart'); |
465
|
|
|
if ($response->isRedirection() || $response->getContent()) { |
466
|
|
|
return $response; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
// 受注の存在チェック |
470
|
|
|
$response = $this->forwardToRoute('shopping_exists_order'); |
471
|
|
|
if ($response->isRedirection() || $response->getContent()) { |
472
|
|
|
return $response; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** @var Order $Order */ |
476
|
|
|
$Order = $this->parameterBag->get('Order'); |
477
|
|
|
|
478
|
|
|
$Shipping = $Order->findShipping($id); |
479
|
|
|
if (!$Shipping) { |
480
|
|
|
throw new NotFoundHttpException(trans('shoppingcontroller.text.error.set_address')); |
481
|
|
|
} |
482
|
|
|
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) { |
483
|
|
|
$Shipping->clearCustomerAddress(); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
$CustomerAddress = new CustomerAddress(); |
487
|
|
|
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) { |
488
|
|
|
$CustomerAddress->setCustomer($Customer); |
489
|
|
|
} else { |
490
|
|
|
$CustomerAddress->setFromShipping($Shipping); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
$builder = $this->formFactory->createBuilder(ShoppingShippingType::class, $CustomerAddress); |
494
|
|
|
|
495
|
|
|
$event = new EventArgs( |
496
|
|
|
[ |
497
|
|
|
'builder' => $builder, |
498
|
|
|
'Order' => $Order, |
499
|
|
|
'Shipping' => $Shipping, |
500
|
|
|
'CustomerAddress' => $CustomerAddress, |
501
|
|
|
], |
502
|
|
|
$request |
503
|
|
|
); |
504
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event); |
505
|
|
|
|
506
|
|
|
$form = $builder->getForm(); |
507
|
|
|
|
508
|
|
|
$form->handleRequest($request); |
509
|
|
|
|
510
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
511
|
|
|
log_info('お届け先追加処理開始', ['id' => $Order->getId(), 'shipping' => $id]); |
512
|
|
|
|
513
|
|
|
// 会員の場合、お届け先情報を新規登録 |
514
|
|
|
$Shipping->setFromCustomerAddress($CustomerAddress); |
515
|
|
|
|
516
|
|
|
if ($Customer instanceof Customer) { |
|
|
|
|
517
|
|
|
$this->entityManager->persist($CustomerAddress); |
518
|
|
|
log_info( |
519
|
|
|
'新規お届け先登録', |
520
|
|
|
[ |
521
|
|
|
'id' => $Order->getId(), |
522
|
|
|
'shipping' => $id, |
523
|
|
|
'customer address' => $CustomerAddress->getId(), |
524
|
|
|
] |
525
|
|
|
); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
// 配送料金の設定 |
529
|
|
|
$this->shoppingService->setShippingDeliveryFee($Shipping); |
530
|
|
|
|
531
|
|
|
// 合計金額の再計算 |
532
|
|
|
$flowResult = $this->executePurchaseFlow($Order); |
533
|
|
|
if ($flowResult->hasWarning() || $flowResult->hasError()) { |
534
|
|
|
return $this->redirectToRoute('shopping_error'); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
// 配送先を更新 |
538
|
|
|
$this->entityManager->flush(); |
539
|
|
|
|
540
|
|
|
$event = new EventArgs( |
541
|
|
|
[ |
542
|
|
|
'form' => $form, |
543
|
|
|
'Shipping' => $Shipping, |
544
|
|
|
'CustomerAddress' => $CustomerAddress, |
545
|
|
|
], |
546
|
|
|
$request |
547
|
|
|
); |
548
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event); |
549
|
|
|
|
550
|
|
|
log_info('お届け先追加処理完了', ['id' => $Order->getId(), 'shipping' => $id]); |
551
|
|
|
|
552
|
|
|
return $this->redirectToRoute('shopping'); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
return [ |
556
|
|
|
'form' => $form->createView(), |
557
|
|
|
'shippingId' => $id, |
558
|
|
|
]; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
|
|
|
|
562
|
|
|
* ログイン |
563
|
|
|
* |
564
|
|
|
* @Route("/shopping/login", name="shopping_login") |
565
|
|
|
* @Template("Shopping/login.twig") |
566
|
|
|
*/ |
|
|
|
|
567
|
2 |
|
public function login(Request $request, AuthenticationUtils $authenticationUtils) |
568
|
|
|
{ |
569
|
2 |
|
if (!$this->cartService->isLocked()) { |
570
|
2 |
|
return $this->redirectToRoute('cart'); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) { |
574
|
|
|
return $this->redirectToRoute('shopping'); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
578
|
|
|
$builder = $this->formFactory->createNamedBuilder('', CustomerLoginType::class); |
579
|
|
|
|
580
|
|
|
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
581
|
|
|
$Customer = $this->getUser(); |
582
|
|
|
if ($Customer) { |
583
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
$event = new EventArgs( |
588
|
|
|
[ |
589
|
|
|
'builder' => $builder, |
590
|
|
|
], |
591
|
|
|
$request |
592
|
|
|
); |
593
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event); |
594
|
|
|
|
595
|
|
|
$form = $builder->getForm(); |
596
|
|
|
|
597
|
|
|
return [ |
598
|
|
|
'error' => $authenticationUtils->getLastAuthenticationError(), |
599
|
|
|
'form' => $form->createView(), |
600
|
|
|
]; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
|
|
|
|
604
|
|
|
* 購入エラー画面表示 |
605
|
|
|
* |
606
|
|
|
* @Route("/shopping/error", name="shopping_error") |
607
|
|
|
* @Template("Shopping/shopping_error.twig") |
608
|
|
|
*/ |
|
|
|
|
609
|
1 |
|
public function shoppingError(Request $request) |
610
|
|
|
{ |
611
|
1 |
|
$event = new EventArgs( |
612
|
1 |
|
[], |
613
|
1 |
|
$request |
614
|
|
|
); |
615
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event); |
616
|
|
|
|
617
|
1 |
|
if ($event->getResponse() !== null) { |
618
|
|
|
return $event->getResponse(); |
619
|
|
|
} |
620
|
|
|
|
621
|
1 |
|
return []; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
/** |
|
|
|
|
625
|
|
|
* カート画面のチェック |
626
|
|
|
* |
627
|
|
|
* @ForwardOnly |
628
|
|
|
* @Route("/shopping/check_to_cart", name="shopping_check_to_cart") |
629
|
|
|
*/ |
|
|
|
|
630
|
32 |
|
public function checkToCart(Request $request) |
|
|
|
|
631
|
|
|
{ |
632
|
|
|
// カートチェック |
633
|
32 |
|
if (!$this->cartService->isLocked()) { |
634
|
4 |
|
log_info('カートが存在しません'); |
635
|
|
|
|
636
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
637
|
4 |
|
return $this->redirectToRoute('cart'); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
// カートチェック |
641
|
28 |
|
if (count($this->cartService->getCart()->getCartItems()) <= 0) { |
642
|
|
|
log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト'); |
643
|
|
|
|
644
|
|
|
// カートが存在しない時はエラー |
645
|
|
|
return $this->redirectToRoute('cart'); |
646
|
|
|
} |
647
|
|
|
|
648
|
28 |
|
return new Response(); |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
|
|
|
|
652
|
|
|
* 受注情報を初期化する. |
653
|
|
|
* |
654
|
|
|
* @ForwardOnly |
655
|
|
|
* @Route("/shopping/initialize_order", name="shopping_initialize_order") |
656
|
|
|
*/ |
|
|
|
|
657
|
25 |
|
public function initializeOrder(Request $request) |
|
|
|
|
658
|
|
|
{ |
659
|
|
|
// 購入処理中の受注情報を取得 |
660
|
25 |
|
$Order = $this->shoppingService->getOrder(OrderStatus::PROCESSING); |
661
|
|
|
|
662
|
|
|
// 初回アクセス(受注情報がない)の場合は, 受注情報を作成 |
663
|
25 |
|
if (is_null($Order)) { |
664
|
|
|
// 未ログインの場合, ログイン画面へリダイレクト. |
665
|
23 |
|
if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) { |
666
|
|
|
// 非会員でも一度会員登録されていればショッピング画面へ遷移 |
667
|
|
|
$Customer = $this->shoppingService->getNonMember($this->sessionKey); |
668
|
|
|
|
669
|
|
|
if (is_null($Customer)) { |
670
|
|
|
log_info('未ログインのためログイン画面にリダイレクト'); |
671
|
|
|
|
672
|
|
|
return $this->redirectToRoute('shopping_login'); |
673
|
|
|
} |
674
|
|
|
} else { |
675
|
23 |
|
$Customer = $this->getUser(); |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
try { |
679
|
|
|
// 受注情報を作成 |
680
|
|
|
//$Order = $app['eccube.service.shopping']->createOrder($Customer); |
|
|
|
|
681
|
23 |
|
$Order = $this->orderHelper->createProcessingOrder( |
682
|
23 |
|
$Customer, |
683
|
23 |
|
$Customer->getCustomerAddresses()->current(), |
684
|
23 |
|
$this->cartService->getCart()->getCartItems() |
685
|
|
|
); |
686
|
23 |
|
$this->cartService->setPreOrderId($Order->getPreOrderId()); |
687
|
23 |
|
$this->cartService->save(); |
688
|
|
|
} catch (CartException $e) { |
689
|
|
|
log_error('初回受注情報作成エラー', [$e->getMessage()]); |
690
|
|
|
$this->addRequestError($e->getMessage()); |
691
|
|
|
|
692
|
|
|
return $this->redirectToRoute('cart'); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
// セッション情報を削除 |
696
|
23 |
|
$this->session->remove($this->sessionOrderKey); |
697
|
23 |
|
$this->session->remove($this->sessionMultipleKey); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
// 受注関連情報を最新状態に更新 |
701
|
25 |
|
$this->entityManager->refresh($Order); |
702
|
|
|
|
703
|
25 |
|
$this->parameterBag->set('Order', $Order); |
704
|
|
|
|
705
|
25 |
|
return new Response(); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
/** |
|
|
|
|
709
|
|
|
* フォームを作成し, イベントハンドラを設定する |
710
|
|
|
* |
711
|
|
|
* @ForwardOnly |
712
|
|
|
* @Route("/shopping/create_form", name="shopping_create_form") |
713
|
|
|
*/ |
|
|
|
|
714
|
25 |
|
public function createShoppingForm(Request $request) |
715
|
|
|
{ |
716
|
25 |
|
$Order = $this->parameterBag->get('Order'); |
717
|
|
|
// フォームの生成 |
718
|
25 |
|
$builder = $this->formFactory->createBuilder(OrderType::class, $Order); |
719
|
|
|
|
720
|
25 |
|
$event = new EventArgs( |
721
|
|
|
[ |
722
|
25 |
|
'builder' => $builder, |
723
|
25 |
|
'Order' => $Order, |
724
|
|
|
], |
725
|
25 |
|
$request |
726
|
|
|
); |
727
|
25 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event); |
728
|
|
|
|
729
|
25 |
|
$form = $builder->getForm(); |
730
|
|
|
|
731
|
25 |
|
$this->parameterBag->set(OrderType::class, $form); |
732
|
|
|
|
733
|
25 |
|
return new Response(); |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
/** |
|
|
|
|
737
|
|
|
* mode に応じて各変更ページへリダイレクトする. |
738
|
|
|
* |
739
|
|
|
* @ForwardOnly |
740
|
|
|
* @Route("/shopping/redirect_to_change", name="shopping_redirect_to_change") |
741
|
|
|
*/ |
|
|
|
|
742
|
10 |
|
public function redirectToChange(Request $request) |
|
|
|
|
743
|
|
|
{ |
744
|
10 |
|
$form = $this->parameterBag->get(OrderType::class); |
745
|
|
|
|
746
|
|
|
// requestのバインド後、Calculatorに再集計させる |
747
|
|
|
//$app['eccube.service.calculate']($Order, $Order->getCustomer())->calculate(); |
|
|
|
|
748
|
|
|
|
749
|
|
|
// 支払い方法の変更や配送業者の変更があった場合はDBに保持する. |
750
|
10 |
|
if ($form->isSubmitted() && $form->isValid()) { |
751
|
|
|
// POSTされたデータをDBに保持. |
752
|
7 |
|
$this->entityManager->flush(); |
753
|
|
|
|
754
|
7 |
|
$mode = $form['mode']->getData(); |
755
|
7 |
|
switch ($mode) { |
756
|
7 |
|
case 'shipping_change': |
757
|
|
|
// お届け先設定一覧へリダイレクト |
758
|
|
|
$param = $form['param']->getData(); |
759
|
|
|
|
760
|
|
|
return $this->redirectToRoute('shopping_shipping', ['id' => $param]); |
761
|
7 |
|
case 'shipping_edit_change': |
762
|
|
|
// お届け先設定一覧へリダイレクト |
763
|
|
|
$param = $form['param']->getData(); |
764
|
|
|
|
765
|
|
|
return $this->redirectToRoute('shopping_shipping_edit', ['id' => $param]); |
766
|
7 |
|
case 'shipping_multiple_change': |
767
|
|
|
// 複数配送設定へリダイレクト |
768
|
|
|
return $this->redirectToRoute('shopping_shipping_multiple'); |
769
|
7 |
|
case 'payment': |
770
|
7 |
|
case 'delivery': |
771
|
|
|
default: |
772
|
7 |
|
return $this->redirectToRoute('shopping'); |
773
|
|
|
} |
774
|
|
|
} |
775
|
|
|
|
776
|
3 |
|
return new Response(); |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
/** |
|
|
|
|
780
|
|
|
* 複数配送時のエラーを表示する |
781
|
|
|
* |
782
|
|
|
* @ForwardOnly |
783
|
|
|
* @Route("/shopping/handle_multiple_errors", name="shopping_handle_multiple_errors") |
784
|
|
|
*/ |
|
|
|
|
785
|
20 |
|
public function handleMultipleErrors(Request $request) |
|
|
|
|
786
|
|
|
{ |
787
|
20 |
|
$Order = $this->parameterBag->get('Order'); |
788
|
|
|
|
789
|
|
|
// 複数配送の場合、エラーメッセージを一度だけ表示 |
790
|
20 |
|
if (!$this->session->has($this->sessionMultipleKey)) { |
791
|
20 |
|
if (count($Order->getShippings()) > 1) { |
792
|
|
|
if (!$this->BaseInfo->isOptionMultipleShipping()) { |
793
|
|
|
// 複数配送に設定されていないのに複数配送先ができればエラー |
794
|
|
|
$this->addRequestError('cart.product.type.kind'); |
795
|
|
|
|
796
|
|
|
return $this->redirectToRoute('cart'); |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
$this->addError('shopping.multiple.delivery'); |
800
|
|
|
} |
801
|
20 |
|
$this->session->set($this->sessionMultipleKey, 'multiple'); |
802
|
|
|
} |
803
|
|
|
|
804
|
20 |
|
return new Response(); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
/** |
|
|
|
|
808
|
|
|
* 受注の存在チェック |
809
|
|
|
* |
810
|
|
|
* @ForwardOnly |
811
|
|
|
* @Route("/shopping/exists_order", name="shopping_exists_order") |
812
|
|
|
*/ |
|
|
|
|
813
|
12 |
|
public function existsOrder(Request $request) |
|
|
|
|
814
|
|
|
{ |
815
|
12 |
|
$Order = $this->shoppingService->getOrder(OrderStatus::PROCESSING); |
816
|
12 |
|
if (!$Order) { |
817
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
818
|
|
|
$this->addError('front.shopping.order.error'); |
819
|
|
|
|
820
|
|
|
return $this->redirectToRoute('shopping_error'); |
821
|
|
|
} |
822
|
12 |
|
$this->parameterBag->set('Order', $Order); |
823
|
|
|
|
824
|
12 |
|
return new Response(); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
/** |
|
|
|
|
828
|
|
|
* 受注完了処理 |
829
|
|
|
* |
830
|
|
|
* @ForwardOnly |
831
|
|
|
* @Route("/shopping/complete_order", name="shopping_complete_order") |
832
|
|
|
*/ |
|
|
|
|
833
|
2 |
|
public function completeOrder(Request $request) |
|
|
|
|
834
|
|
|
{ |
835
|
2 |
|
$form = $this->parameterBag->get(OrderType::class); |
836
|
|
|
|
837
|
2 |
|
if ($form->isSubmitted() && $form->isValid()) { |
838
|
|
|
/** @var Order $Order */ |
839
|
2 |
|
$Order = $form->getData(); |
840
|
2 |
|
log_info('購入処理開始', [$Order->getId()]); |
841
|
|
|
|
842
|
|
|
// トランザクション制御 |
843
|
2 |
|
$em = $this->entityManager; |
844
|
2 |
|
$em->getConnection()->beginTransaction(); |
845
|
|
|
try { |
846
|
|
|
// お問い合わせ、配送時間などのフォーム項目をセット |
847
|
|
|
// FormTypeで更新されるため不要 |
848
|
|
|
//$app['eccube.service.shopping']->setFormData($Order, $data); |
|
|
|
|
849
|
|
|
|
850
|
2 |
|
$flowResult = $this->executePurchaseFlow($Order); |
851
|
2 |
|
if ($flowResult->hasWarning() || $flowResult->hasError()) { |
852
|
|
|
// TODO エラーメッセージ |
853
|
|
|
throw new ShoppingException(); |
854
|
|
|
} |
855
|
|
|
try { |
856
|
2 |
|
$this->purchaseFlow->purchase($Order, new PurchaseContext($Order, $Order->getCustomer())); // TODO 変更前の Order を渡す必要がある? |
857
|
|
|
} catch (PurchaseException $e) { |
|
|
|
|
858
|
|
|
$this->addError($e->getMessage(), 'front'); |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
// 購入処理 |
862
|
2 |
|
$this->shoppingService->processPurchase($Order); // XXX フロント画面に依存してるので管理画面では使えない |
|
|
|
|
863
|
|
|
|
864
|
|
|
// Order も引数で渡すのがベスト?? |
865
|
2 |
|
$paymentService = $this->createPaymentService($Order); |
866
|
2 |
|
$paymentMethod = $this->createPaymentMethod($Order, $form); |
867
|
|
|
|
868
|
|
|
// 必要に応じて別のコントローラへ forward or redirect(移譲) |
869
|
|
|
// forward の処理はプラグイン内で書けるようにしておく |
870
|
|
|
// dispatch をしたら, パスを返して forwardする |
871
|
|
|
// http://silex.sensiolabs.org/doc/cookbook/sub_requests.html |
872
|
|
|
// 確認画面も挟める |
873
|
|
|
// Request をセッションに入れるべし |
874
|
2 |
|
$dispatcher = $paymentService->dispatch($paymentMethod); // 決済処理中. |
875
|
|
|
// 一旦、決済処理中になった後は、購入処理中に戻せない。キャンセル or 購入完了の仕様とする |
876
|
|
|
// ステータス履歴も保持しておく? 在庫引き当ての仕様もセットで。 |
877
|
2 |
|
if ($dispatcher instanceof Response |
878
|
2 |
|
&& ($dispatcher->isRedirection() || $dispatcher->getContent()) |
879
|
|
|
) { // $paymentMethod->apply() が Response を返した場合は画面遷移 |
880
|
|
|
return $dispatcher; // 画面遷移したいパターンが複数ある場合はどうする? 引数で制御? |
881
|
|
|
} |
882
|
2 |
|
$PaymentResult = $paymentService->doCheckout($paymentMethod); // 決済実行 |
883
|
2 |
|
if (!$PaymentResult->isSuccess()) { |
884
|
|
|
$this->entityManager->getConnection()->rollback(); |
885
|
|
|
|
886
|
|
|
return $this->redirectToRoute('shopping_error'); |
887
|
|
|
} |
888
|
|
|
|
889
|
2 |
|
$this->entityManager->flush(); |
890
|
2 |
|
$this->entityManager->getConnection()->commit(); |
891
|
|
|
|
892
|
2 |
|
log_info('購入処理完了', [$Order->getId()]); |
893
|
|
|
} catch (ShoppingException $e) { |
894
|
|
|
log_error('購入エラー', [$e->getMessage()]); |
895
|
|
|
|
896
|
|
|
$this->entityManager->getConnection()->rollback(); |
897
|
|
|
|
898
|
|
|
$this->log($e); |
|
|
|
|
899
|
|
|
$this->addError($e->getMessage()); |
900
|
|
|
|
901
|
|
|
return $this->redirectToRoute('shopping_error'); |
902
|
|
|
} catch (\Exception $e) { |
903
|
|
|
log_error('予期しないエラー', [$e->getMessage()]); |
904
|
|
|
|
905
|
|
|
$this->entityManager->getConnection()->rollback(); |
906
|
|
|
|
907
|
|
|
$this->addError('front.shopping.system.error'); |
908
|
|
|
|
909
|
|
|
return $this->redirectToRoute('shopping_error'); |
910
|
|
|
} |
911
|
|
|
|
912
|
2 |
|
return $this->forwardToRoute('shopping_after_complete'); |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
return new Response(); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
/** |
|
|
|
|
919
|
|
|
* 受注完了の後処理 |
920
|
|
|
* |
921
|
|
|
* @ForwardOnly |
922
|
|
|
* @Route("/shopping/after_complete", name="shopping_after_complete") |
923
|
|
|
*/ |
|
|
|
|
924
|
2 |
|
public function afterComplete(Request $request) |
925
|
|
|
{ |
926
|
2 |
|
$form = $this->parameterBag->get(OrderType::class); |
927
|
2 |
|
$Order = $this->parameterBag->get('Order'); |
928
|
|
|
|
929
|
|
|
// カート削除 |
930
|
2 |
|
$this->cartService->clear()->save(); |
931
|
|
|
|
932
|
2 |
|
$event = new EventArgs( |
933
|
|
|
[ |
934
|
2 |
|
'form' => $form, |
935
|
2 |
|
'Order' => $Order, |
936
|
|
|
], |
937
|
2 |
|
$request |
938
|
|
|
); |
939
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event); |
940
|
|
|
|
941
|
2 |
View Code Duplication |
if ($event->getResponse() !== null) { |
|
|
|
|
942
|
|
|
log_info('イベントレスポンス返却', [$Order->getId()]); |
943
|
|
|
|
944
|
|
|
return $event->getResponse(); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
// 受注IDをセッションにセット |
948
|
2 |
|
$this->session->set($this->sessionOrderKey, $Order->getId()); |
949
|
|
|
|
950
|
|
|
// メール送信 |
951
|
2 |
|
$MailHistory = $this->shoppingService->sendOrderMail($Order); |
952
|
|
|
|
953
|
2 |
|
$event = new EventArgs( |
954
|
|
|
[ |
955
|
2 |
|
'form' => $form, |
956
|
2 |
|
'Order' => $Order, |
957
|
2 |
|
'MailHistory' => $MailHistory, |
958
|
|
|
], |
959
|
2 |
|
$request |
960
|
|
|
); |
961
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event); |
962
|
|
|
|
963
|
2 |
View Code Duplication |
if ($event->getResponse() !== null) { |
|
|
|
|
964
|
|
|
log_info('イベントレスポンス返却', [$Order->getId()]); |
965
|
|
|
|
966
|
|
|
return $event->getResponse(); |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
// 完了画面表示 |
970
|
2 |
|
return $this->redirectToRoute('shopping_complete'); |
971
|
|
|
} |
972
|
|
|
|
973
|
2 |
|
private function createPaymentService(Order $Order) |
974
|
|
|
{ |
975
|
2 |
|
$serviceClass = $Order->getPayment()->getServiceClass(); |
976
|
2 |
|
$paymentService = new $serviceClass($this->container->get('request_stack')); |
977
|
|
|
|
978
|
2 |
|
return $paymentService; |
979
|
|
|
} |
980
|
|
|
|
981
|
2 |
|
private function createPaymentMethod(Order $Order, $form) |
982
|
|
|
{ |
983
|
2 |
|
$methodClass = $Order->getPayment()->getMethodClass(); |
984
|
2 |
|
$PaymentMethod = new $methodClass(); |
985
|
2 |
|
$PaymentMethod->setFormType($form); |
986
|
2 |
|
$PaymentMethod->setRequest($this->container->get('request_stack')->getCurrentRequest()); |
987
|
|
|
|
988
|
2 |
|
return $PaymentMethod; |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
/** |
992
|
|
|
* 非会員でのお客様情報変更時の入力チェック |
993
|
|
|
* |
994
|
|
|
* TODO https://github.com/EC-CUBE/ec-cube/issues/565 |
995
|
|
|
* |
996
|
|
|
* @param Application $app |
997
|
|
|
* @param array $data リクエストパラメータ |
998
|
|
|
* |
999
|
|
|
* @return array |
1000
|
|
|
*/ |
1001
|
|
|
private function customerValidation(Application $app, array &$data) |
|
|
|
|
1002
|
|
|
{ |
1003
|
|
|
// 入力チェック |
1004
|
|
|
$errors = []; |
1005
|
|
|
|
1006
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name01'], [ |
1007
|
|
|
new Assert\NotBlank(), |
1008
|
|
|
new Assert\Length(['max' => $app['config']['name_len']]), |
1009
|
|
|
new Assert\Regex(['pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace']), |
1010
|
|
|
]); |
1011
|
|
|
|
1012
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name02'], [ |
1013
|
|
|
new Assert\NotBlank(), |
1014
|
|
|
new Assert\Length(['max' => $app['config']['name_len']]), |
1015
|
|
|
new Assert\Regex(['pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace']), |
1016
|
|
|
]); |
1017
|
|
|
|
1018
|
|
|
// 互換性確保のためキーが存在する場合にのみバリデーションを行う(kana01は3.0.15から追加) |
|
|
|
|
1019
|
|
View Code Duplication |
if (array_key_exists('customer_kana01', $data)) { |
|
|
|
|
1020
|
|
|
$data['customer_kana01'] = mb_convert_kana($data['customer_kana01'], 'CV', 'utf-8'); |
1021
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_kana01'], [ |
1022
|
|
|
new Assert\NotBlank(), |
1023
|
|
|
new Assert\Length(['max' => $app['config']['kana_len']]), |
1024
|
|
|
new Assert\Regex(['pattern' => '/^[ァ-ヶヲ-゚ー]+$/u']), |
1025
|
|
|
]); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
// 互換性確保のためキーが存在する場合にのみバリデーションを行う(kana01は3.0.15から追加) |
|
|
|
|
1029
|
|
View Code Duplication |
if (array_key_exists('customer_kana02', $data)) { |
|
|
|
|
1030
|
|
|
$data['customer_kana02'] = mb_convert_kana($data['customer_kana02'], 'CV', 'utf-8'); |
1031
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_kana02'], [ |
1032
|
|
|
new Assert\NotBlank(), |
1033
|
|
|
new Assert\Length(['max' => $app['config']['kana_len']]), |
1034
|
|
|
new Assert\Regex(['pattern' => '/^[ァ-ヶヲ-゚ー]+$/u']), |
1035
|
|
|
]); |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_company_name'], [ |
1039
|
|
|
new Assert\Length(['max' => $app['config']['stext_len']]), |
1040
|
|
|
]); |
1041
|
|
|
|
1042
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel01'], [ |
1043
|
|
|
new Assert\NotBlank(), |
1044
|
|
|
new Assert\Type(['type' => 'numeric', 'message' => 'form.type.numeric.invalid']), |
1045
|
|
|
new Assert\Length(['max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min']]), |
1046
|
|
|
]); |
1047
|
|
|
|
1048
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel02'], [ |
1049
|
|
|
new Assert\NotBlank(), |
1050
|
|
|
new Assert\Type(['type' => 'numeric', 'message' => 'form.type.numeric.invalid']), |
1051
|
|
|
new Assert\Length(['max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min']]), |
1052
|
|
|
]); |
1053
|
|
|
|
1054
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel03'], [ |
1055
|
|
|
new Assert\NotBlank(), |
1056
|
|
|
new Assert\Type(['type' => 'numeric', 'message' => 'form.type.numeric.invalid']), |
1057
|
|
|
new Assert\Length(['max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min']]), |
1058
|
|
|
]); |
1059
|
|
|
|
1060
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip01'], [ |
1061
|
|
|
new Assert\NotBlank(), |
1062
|
|
|
new Assert\Type(['type' => 'numeric', 'message' => 'form.type.numeric.invalid']), |
1063
|
|
|
new Assert\Length(['min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len']]), |
1064
|
|
|
]); |
1065
|
|
|
|
1066
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip02'], [ |
1067
|
|
|
new Assert\NotBlank(), |
1068
|
|
|
new Assert\Type(['type' => 'numeric', 'message' => 'form.type.numeric.invalid']), |
1069
|
|
|
new Assert\Length(['min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len']]), |
1070
|
|
|
]); |
1071
|
|
|
|
1072
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr01'], [ |
1073
|
|
|
new Assert\NotBlank(), |
1074
|
|
|
new Assert\Length(['max' => $app['config']['address1_len']]), |
1075
|
|
|
]); |
1076
|
|
|
|
1077
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr02'], [ |
1078
|
|
|
new Assert\NotBlank(), |
1079
|
|
|
new Assert\Length(['max' => $app['config']['address2_len']]), |
1080
|
|
|
]); |
1081
|
|
|
|
1082
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_email'], [ |
1083
|
|
|
new Assert\NotBlank(), |
1084
|
|
|
new Assert\Email(['strict' => true]), |
1085
|
|
|
]); |
1086
|
|
|
|
1087
|
|
|
return $errors; |
1088
|
|
|
} |
1089
|
|
|
} |
1090
|
|
|
|