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\Common\Constant; |
29
|
|
|
use Eccube\Entity\Customer; |
30
|
|
|
use Eccube\Entity\CustomerAddress; |
31
|
|
|
use Eccube\Entity\ShipmentItem; |
32
|
|
|
use Eccube\Entity\Shipping; |
33
|
|
|
use Eccube\Event\EccubeEvents; |
34
|
|
|
use Eccube\Event\EventArgs; |
35
|
|
|
use Eccube\Exception\CartException; |
36
|
|
|
use Eccube\Exception\ShoppingException; |
37
|
|
|
use Symfony\Component\HttpFoundation\Request; |
38
|
|
|
use Symfony\Component\HttpFoundation\Response; |
39
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
40
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
41
|
|
|
|
42
|
|
|
class ShoppingController extends AbstractController |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string 非会員用セッションキー |
47
|
|
|
*/ |
48
|
|
|
private $sessionKey = 'eccube.front.shopping.nonmember'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string 非会員用セッションキー |
52
|
|
|
*/ |
53
|
|
|
private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string 複数配送警告メッセージ |
57
|
|
|
*/ |
58
|
|
|
private $sessionMultipleKey = 'eccube.front.shopping.multiple'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string 受注IDキー |
62
|
|
|
*/ |
63
|
|
|
private $sessionOrderKey = 'eccube.front.shopping.order.id'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* 購入画面表示 |
67
|
|
|
* |
68
|
|
|
* @param Application $app |
69
|
|
|
* @param Request $request |
|
|
|
|
70
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response |
71
|
|
|
*/ |
72
|
94 |
|
public function index(Application $app, Request $request) |
73
|
|
|
{ |
74
|
94 |
|
$cartService = $app['eccube.service.cart']; |
75
|
|
|
|
76
|
|
|
// カートチェック |
77
|
94 |
|
if (!$cartService->isLocked()) { |
78
|
4 |
|
log_info('カートが存在しません'); |
79
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
80
|
4 |
|
return $app->redirect($app->url('cart')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// カートチェック |
84
|
90 |
View Code Duplication |
if (count($cartService->getCart()->getCartItems()) <= 0) { |
|
|
|
|
85
|
7 |
|
log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト'); |
86
|
|
|
// カートが存在しない時はエラー |
87
|
7 |
|
return $app->redirect($app->url('cart')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// 登録済みの受注情報を取得 |
91
|
86 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
92
|
|
|
|
93
|
|
|
// 初回アクセス(受注情報がない)の場合は, 受注情報を作成 |
94
|
86 |
|
if (is_null($Order)) { |
95
|
|
|
// 未ログインの場合, ログイン画面へリダイレクト. |
96
|
86 |
|
if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) { |
97
|
|
|
// 非会員でも一度会員登録されていればショッピング画面へ遷移 |
98
|
30 |
|
$Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); |
99
|
|
|
|
100
|
30 |
|
if (is_null($Customer)) { |
101
|
|
|
log_info('未ログインのためログイン画面にリダイレクト'); |
102
|
30 |
|
return $app->redirect($app->url('shopping_login')); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} else { |
105
|
56 |
|
$Customer = $app->user(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
try { |
109
|
|
|
// 受注情報を作成 |
110
|
86 |
|
$Order = $app['eccube.service.shopping']->createOrder($Customer); |
111
|
1 |
|
} catch (CartException $e) { |
112
|
1 |
|
log_error('初回受注情報作成エラー', array($e->getMessage())); |
113
|
1 |
|
$app->addRequestError($e->getMessage()); |
114
|
1 |
|
return $app->redirect($app->url('cart')); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// セッション情報を削除 |
118
|
85 |
|
$app['session']->remove($this->sessionOrderKey); |
119
|
85 |
|
$app['session']->remove($this->sessionMultipleKey); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// 受注関連情報を最新状態に更新 |
123
|
85 |
|
$app['orm.em']->refresh($Order); |
124
|
|
|
|
125
|
|
|
// form作成 |
126
|
85 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
127
|
|
|
|
128
|
85 |
|
$event = new EventArgs( |
129
|
|
|
array( |
130
|
85 |
|
'builder' => $builder, |
131
|
85 |
|
'Order' => $Order, |
132
|
|
|
), |
133
|
|
|
$request |
134
|
|
|
); |
135
|
85 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event); |
136
|
|
|
|
137
|
85 |
|
$form = $builder->getForm(); |
138
|
|
|
|
139
|
85 |
|
if ($Order->getTotalPrice() < 0) { |
140
|
|
|
// 合計金額がマイナスの場合、エラー |
141
|
|
|
log_info('受注金額マイナスエラー', array($Order->getId())); |
142
|
|
|
$message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice()))); |
143
|
|
|
$app->addError($message); |
144
|
|
|
|
145
|
|
|
return $app->redirect($app->url('shopping_error')); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// 複数配送の場合、エラーメッセージを一度だけ表示 |
149
|
85 |
|
if (!$app['session']->has($this->sessionMultipleKey)) { |
150
|
85 |
|
if (count($Order->getShippings()) > 1) { |
|
|
|
|
151
|
|
|
|
152
|
5 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
153
|
|
|
|
154
|
5 |
|
if (!$BaseInfo->getOptionMultipleShipping()) { |
155
|
|
|
// 複数配送に設定されていないのに複数配送先ができればエラー |
156
|
|
|
$app->addRequestError('cart.product.type.kind'); |
157
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
5 |
|
$app->addError('shopping.multiple.delivery'); |
161
|
|
|
} |
162
|
85 |
|
$app['session']->set($this->sessionMultipleKey, 'multiple'); |
163
|
|
|
} |
164
|
|
|
|
165
|
85 |
|
return $app->render('Shopping/index.twig', array( |
166
|
85 |
|
'form' => $form->createView(), |
167
|
85 |
|
'Order' => $Order, |
168
|
|
|
)); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
|
|
|
|
172
|
|
|
* 購入処理 |
173
|
|
|
*/ |
|
|
|
|
174
|
23 |
|
public function confirm(Application $app, Request $request) |
175
|
|
|
{ |
176
|
23 |
|
$cartService = $app['eccube.service.cart']; |
177
|
|
|
|
178
|
|
|
// カートチェック |
179
|
23 |
|
if (!$cartService->isLocked()) { |
180
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
181
|
|
|
log_info('カートが存在しません'); |
182
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
23 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
186
|
23 |
|
if (!$Order) { |
187
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
188
|
|
|
$app->addError('front.shopping.order.error'); |
189
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
23 |
|
if ('POST' !== $request->getMethod()) { |
193
|
|
|
return $app->redirect($app->url('cart')); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
// form作成 |
197
|
23 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
198
|
|
|
|
199
|
23 |
|
$event = new EventArgs( |
200
|
|
|
array( |
201
|
23 |
|
'builder' => $builder, |
202
|
23 |
|
'Order' => $Order, |
203
|
|
|
), |
204
|
|
|
$request |
205
|
|
|
); |
206
|
23 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event); |
207
|
|
|
|
208
|
23 |
|
$form = $builder->getForm(); |
209
|
|
|
|
210
|
23 |
|
$form->handleRequest($request); |
211
|
|
|
|
212
|
23 |
|
if ($form->isSubmitted() && $form->isValid()) { |
213
|
23 |
|
$data = $form->getData(); |
214
|
|
|
|
215
|
23 |
|
log_info('購入処理開始', array($Order->getId())); |
216
|
|
|
|
217
|
|
|
// トランザクション制御 |
218
|
23 |
|
$em = $app['orm.em']; |
219
|
23 |
|
$em->getConnection()->beginTransaction(); |
220
|
|
|
try { |
|
|
|
|
221
|
|
|
|
222
|
|
|
// お問い合わせ、配送時間などのフォーム項目をセット |
223
|
23 |
|
$app['eccube.service.shopping']->setFormData($Order, $data); |
224
|
|
|
// 購入処理 |
225
|
23 |
|
$app['eccube.service.shopping']->processPurchase($Order); |
226
|
|
|
|
227
|
23 |
|
$em->flush(); |
228
|
23 |
|
$em->getConnection()->commit(); |
229
|
|
|
|
230
|
23 |
|
log_info('購入処理完了', array($Order->getId())); |
231
|
|
|
|
|
|
|
|
232
|
|
|
} catch (ShoppingException $e) { |
|
|
|
|
233
|
|
|
|
234
|
|
|
log_error('購入エラー', array($e->getMessage())); |
235
|
|
|
|
236
|
|
|
$em->getConnection()->rollback(); |
237
|
|
|
|
238
|
|
|
$app->log($e); |
239
|
|
|
$app->addError($e->getMessage()); |
240
|
|
|
|
241
|
|
|
return $app->redirect($app->url('shopping_error')); |
242
|
|
|
} catch (\Exception $e) { |
|
|
|
|
243
|
|
|
|
244
|
|
|
log_error('予期しないエラー', array($e->getMessage())); |
245
|
|
|
|
246
|
|
|
$em->getConnection()->rollback(); |
247
|
|
|
|
248
|
|
|
$app->log($e); |
249
|
|
|
|
250
|
|
|
$app->addError('front.shopping.system.error'); |
251
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
// カート削除 |
255
|
23 |
|
$app['eccube.service.cart']->clear()->save(); |
256
|
|
|
|
257
|
23 |
|
$event = new EventArgs( |
258
|
|
|
array( |
259
|
23 |
|
'form' => $form, |
260
|
23 |
|
'Order' => $Order, |
261
|
|
|
), |
262
|
|
|
$request |
263
|
|
|
); |
264
|
23 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event); |
265
|
|
|
|
266
|
23 |
View Code Duplication |
if ($event->getResponse() !== null) { |
|
|
|
|
267
|
|
|
log_info('イベントレスポンス返却', array($Order->getId())); |
268
|
|
|
return $event->getResponse(); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
// 受注IDをセッションにセット |
272
|
23 |
|
$app['session']->set($this->sessionOrderKey, $Order->getId()); |
273
|
|
|
|
274
|
|
|
// メール送信 |
275
|
23 |
|
$MailHistory = $app['eccube.service.shopping']->sendOrderMail($Order); |
276
|
|
|
|
277
|
23 |
|
$event = new EventArgs( |
278
|
|
|
array( |
279
|
23 |
|
'form' => $form, |
280
|
23 |
|
'Order' => $Order, |
281
|
23 |
|
'MailHistory' => $MailHistory, |
282
|
|
|
), |
283
|
|
|
$request |
284
|
|
|
); |
285
|
23 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event); |
286
|
|
|
|
287
|
23 |
View Code Duplication |
if ($event->getResponse() !== null) { |
|
|
|
|
288
|
|
|
log_info('イベントレスポンス返却', array($Order->getId())); |
289
|
|
|
return $event->getResponse(); |
|
|
|
|
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
// 完了画面表示 |
293
|
23 |
|
return $app->redirect($app->url('shopping_complete')); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
log_info('購入チェックエラー', array($Order->getId())); |
297
|
|
|
|
298
|
|
|
return $app->render('Shopping/index.twig', array( |
299
|
|
|
'form' => $form->createView(), |
300
|
|
|
'Order' => $Order, |
301
|
|
|
)); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
/** |
|
|
|
|
306
|
|
|
* 購入完了画面表示 |
307
|
|
|
*/ |
|
|
|
|
308
|
9 |
|
public function complete(Application $app, Request $request) |
309
|
|
|
{ |
310
|
|
|
// 受注IDを取得 |
311
|
9 |
|
$orderId = $app['session']->get($this->sessionOrderKey); |
312
|
|
|
|
313
|
9 |
|
$event = new EventArgs( |
314
|
|
|
array( |
315
|
9 |
|
'orderId' => $orderId, |
316
|
|
|
), |
317
|
|
|
$request |
318
|
|
|
); |
319
|
9 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event); |
320
|
|
|
|
321
|
9 |
|
if ($event->getResponse() !== null) { |
322
|
|
|
return $event->getResponse(); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
// 受注IDセッションを削除 |
326
|
9 |
|
$app['session']->remove($this->sessionOrderKey); |
327
|
|
|
|
328
|
9 |
|
log_info('購入処理完了', array($orderId)); |
329
|
|
|
|
330
|
9 |
|
return $app->render('Shopping/complete.twig', array( |
331
|
9 |
|
'orderId' => $orderId, |
332
|
|
|
)); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
/** |
|
|
|
|
337
|
|
|
* 配送業者選択処理 |
338
|
|
|
*/ |
|
|
|
|
339
|
6 |
|
public function delivery(Application $app, Request $request) |
340
|
|
|
{ |
341
|
|
|
// カートチェック |
342
|
6 |
|
if (!$app['eccube.service.cart']->isLocked()) { |
343
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
344
|
|
|
log_info('カートが存在しません'); |
345
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
346
|
|
|
} |
347
|
|
|
|
348
|
6 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
349
|
6 |
|
if (!$Order) { |
350
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
351
|
|
|
$app->addError('front.shopping.order.error'); |
352
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
353
|
|
|
} |
354
|
|
|
|
355
|
6 |
|
if ('POST' !== $request->getMethod()) { |
356
|
|
|
return $app->redirect($app->url('shopping')); |
357
|
|
|
} |
358
|
|
|
|
359
|
6 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
360
|
|
|
|
361
|
6 |
|
$event = new EventArgs( |
362
|
|
|
array( |
363
|
6 |
|
'builder' => $builder, |
364
|
6 |
|
'Order' => $Order, |
365
|
|
|
), |
366
|
|
|
$request |
367
|
|
|
); |
368
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event); |
369
|
|
|
|
370
|
6 |
|
$form = $builder->getForm(); |
371
|
|
|
|
372
|
6 |
|
$form->handleRequest($request); |
373
|
|
|
|
374
|
6 |
|
if ($form->isSubmitted() && $form->isValid()) { |
375
|
2 |
|
log_info('配送業者変更処理開始', array($Order->getId())); |
376
|
|
|
|
377
|
2 |
|
$data = $form->getData(); |
378
|
|
|
|
379
|
2 |
|
$shippings = $data['shippings']; |
380
|
|
|
|
381
|
2 |
|
$productDeliveryFeeTotal = 0; |
382
|
2 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
383
|
|
|
|
384
|
2 |
|
foreach ($shippings as $Shipping) { |
385
|
2 |
|
$Delivery = $Shipping->getDelivery(); |
386
|
|
|
|
387
|
2 |
|
if ($Delivery) { |
388
|
2 |
|
$deliveryFee = $app['eccube.repository.delivery_fee']->findOneBy(array( |
|
|
|
|
389
|
2 |
|
'Delivery' => $Delivery, |
390
|
2 |
|
'Pref' => $Shipping->getPref() |
391
|
|
|
)); |
392
|
|
|
|
393
|
|
|
// 商品ごとの配送料合計 |
394
|
2 |
|
if (!is_null($BaseInfo->getOptionProductDeliveryFee())) { |
395
|
2 |
|
$productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping); |
396
|
|
|
} |
397
|
|
|
|
398
|
2 |
|
$Shipping->setDeliveryFee($deliveryFee); |
399
|
2 |
|
$Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
400
|
2 |
|
$Shipping->setShippingDeliveryName($Delivery->getName()); |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
// 支払い情報をセット |
405
|
2 |
|
$payment = $data['payment']; |
406
|
2 |
|
$message = $data['message']; |
407
|
|
|
|
408
|
2 |
|
$Order->setPayment($payment); |
409
|
2 |
|
$Order->setPaymentMethod($payment->getMethod()); |
410
|
2 |
|
$Order->setMessage($message); |
411
|
2 |
|
$Order->setCharge($payment->getCharge()); |
412
|
|
|
|
413
|
2 |
|
$Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings)); |
414
|
|
|
|
415
|
|
|
// 合計金額の再計算 |
416
|
2 |
|
$Order = $app['eccube.service.shopping']->getAmount($Order); |
417
|
|
|
|
418
|
|
|
// 受注関連情報を最新状態に更新 |
419
|
2 |
|
$app['orm.em']->flush(); |
420
|
|
|
|
421
|
2 |
|
$event = new EventArgs( |
422
|
|
|
array( |
423
|
2 |
|
'form' => $form, |
424
|
2 |
|
'Order' => $Order, |
425
|
|
|
), |
426
|
|
|
$request |
427
|
|
|
); |
428
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event); |
429
|
|
|
|
430
|
2 |
|
log_info('配送業者変更処理完了', array($Order->getId())); |
431
|
2 |
|
return $app->redirect($app->url('shopping')); |
|
|
|
|
432
|
|
|
} |
433
|
|
|
|
434
|
4 |
|
log_info('配送業者変更入力チェックエラー', array($Order->getId())); |
435
|
4 |
|
return $app->render('Shopping/index.twig', array( |
|
|
|
|
436
|
4 |
|
'form' => $form->createView(), |
437
|
4 |
|
'Order' => $Order, |
438
|
|
|
)); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
|
|
|
|
442
|
|
|
* 支払い方法選択処理 |
443
|
|
|
*/ |
|
|
|
|
444
|
9 |
|
public function payment(Application $app, Request $request) |
445
|
|
|
{ |
446
|
9 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
447
|
9 |
|
if (!$Order) { |
448
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
449
|
|
|
$app->addError('front.shopping.order.error'); |
450
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
451
|
|
|
} |
452
|
|
|
|
453
|
9 |
|
if ('POST' !== $request->getMethod()) { |
454
|
|
|
return $app->redirect($app->url('shopping')); |
455
|
|
|
} |
456
|
|
|
|
457
|
9 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
458
|
|
|
|
459
|
9 |
|
$event = new EventArgs( |
460
|
|
|
array( |
461
|
9 |
|
'builder' => $builder, |
462
|
9 |
|
'Order' => $Order, |
463
|
|
|
), |
464
|
|
|
$request |
465
|
|
|
); |
466
|
9 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event); |
467
|
|
|
|
468
|
9 |
|
$form = $builder->getForm(); |
469
|
|
|
|
470
|
9 |
|
$form->handleRequest($request); |
471
|
|
|
|
472
|
9 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
473
|
|
|
|
474
|
7 |
|
log_info('支払い方法変更処理開始', array("id" => $Order->getId())); |
475
|
|
|
|
476
|
7 |
|
$data = $form->getData(); |
477
|
7 |
|
$payment = $data['payment']; |
478
|
7 |
|
$message = $data['message']; |
479
|
|
|
|
480
|
7 |
|
$Order->setPayment($payment); |
481
|
7 |
|
$Order->setPaymentMethod($payment->getMethod()); |
482
|
7 |
|
$Order->setMessage($message); |
483
|
7 |
|
$Order->setCharge($payment->getCharge()); |
484
|
|
|
|
485
|
|
|
// 合計金額の再計算 |
486
|
7 |
|
$Order = $app['eccube.service.shopping']->getAmount($Order); |
487
|
|
|
|
488
|
|
|
// 受注関連情報を最新状態に更新 |
489
|
7 |
|
$app['orm.em']->flush(); |
490
|
|
|
|
491
|
7 |
|
$event = new EventArgs( |
492
|
|
|
array( |
493
|
7 |
|
'form' => $form, |
494
|
7 |
|
'Order' => $Order, |
495
|
|
|
), |
496
|
|
|
$request |
497
|
|
|
); |
498
|
7 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event); |
499
|
|
|
|
500
|
7 |
|
log_info('支払い方法変更処理完了', array("id" => $Order->getId(), "payment" => $payment->getId())); |
501
|
|
|
|
502
|
7 |
|
return $app->redirect($app->url('shopping')); |
503
|
|
|
} |
504
|
|
|
|
505
|
2 |
|
log_info('支払い方法変更入力チェックエラー', array("id" => $Order->getId())); |
506
|
2 |
|
return $app->render('Shopping/index.twig', array( |
|
|
|
|
507
|
2 |
|
'form' => $form->createView(), |
508
|
2 |
|
'Order' => $Order, |
509
|
|
|
)); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
|
|
|
|
513
|
|
|
* お届け先変更がクリックされた場合の処理 |
514
|
|
|
*/ |
|
|
|
|
515
|
18 |
View Code Duplication |
public function shippingChange(Application $app, Request $request, $id) |
|
|
|
|
516
|
|
|
{ |
517
|
18 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
518
|
18 |
|
if (!$Order) { |
519
|
|
|
$app->addError('front.shopping.order.error'); |
520
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
521
|
|
|
} |
522
|
|
|
|
523
|
18 |
|
if ('POST' !== $request->getMethod()) { |
524
|
|
|
return $app->redirect($app->url('shopping')); |
525
|
|
|
} |
526
|
|
|
|
527
|
18 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
528
|
|
|
|
529
|
18 |
|
$event = new EventArgs( |
530
|
|
|
array( |
531
|
18 |
|
'builder' => $builder, |
532
|
18 |
|
'Order' => $Order, |
533
|
|
|
), |
534
|
|
|
$request |
535
|
|
|
); |
536
|
18 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_CHANGE_INITIALIZE, $event); |
537
|
|
|
|
538
|
18 |
|
$form = $builder->getForm(); |
539
|
|
|
|
540
|
18 |
|
$form->handleRequest($request); |
541
|
|
|
|
542
|
18 |
|
if ($form->isSubmitted() && $form->isValid()) { |
543
|
18 |
|
$data = $form->getData(); |
544
|
18 |
|
$message = $data['message']; |
545
|
18 |
|
$Order->setMessage($message); |
546
|
|
|
// 受注情報を更新 |
547
|
18 |
|
$app['orm.em']->flush(); |
548
|
|
|
|
549
|
|
|
// お届け先設定一覧へリダイレクト |
550
|
18 |
|
return $app->redirect($app->url('shopping_shipping', array('id' => $id))); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
return $app->render('Shopping/index.twig', array( |
554
|
|
|
'form' => $form->createView(), |
555
|
|
|
'Order' => $Order, |
556
|
|
|
)); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
|
|
|
|
560
|
|
|
* お届け先の設定一覧からの選択 |
561
|
|
|
*/ |
|
|
|
|
562
|
4 |
|
public function shipping(Application $app, Request $request, $id) |
563
|
|
|
{ |
564
|
|
|
// カートチェック |
565
|
4 |
|
if (!$app['eccube.service.cart']->isLocked()) { |
566
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
567
|
|
|
log_info('カートが存在しません'); |
568
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
569
|
|
|
} |
570
|
|
|
|
571
|
4 |
|
if ('POST' === $request->getMethod()) { |
572
|
|
|
$address = $request->get('address'); |
573
|
|
|
|
574
|
|
|
if (is_null($address)) { |
575
|
|
|
// 選択されていなければエラー |
576
|
|
|
log_info('お届け先入力チェックエラー'); |
577
|
|
|
return $app->render( |
|
|
|
|
578
|
|
|
'Shopping/shipping.twig', |
579
|
|
|
array( |
580
|
|
|
'Customer' => $app->user(), |
581
|
|
|
'shippingId' => $id, |
582
|
|
|
'error' => true, |
583
|
|
|
) |
584
|
|
|
); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
// 選択されたお届け先情報を取得 |
588
|
|
|
$CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array( |
589
|
|
|
'Customer' => $app->user(), |
590
|
|
|
'id' => $address, |
591
|
|
|
)); |
592
|
|
|
if (is_null($CustomerAddress)) { |
593
|
|
|
throw new NotFoundHttpException('選択されたお届け先住所が存在しない'); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
597
|
|
|
if (!$Order) { |
598
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
599
|
|
|
$app->addError('front.shopping.order.error'); |
600
|
|
|
|
601
|
|
|
return $app->redirect($app->url('shopping_error')); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
$Shipping = $Order->findShipping($id); |
605
|
|
|
if (!$Shipping) { |
606
|
|
|
throw new NotFoundHttpException('お届け先情報が存在しない'); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
log_info('お届先情報更新開始', array($Shipping->getId())); |
610
|
|
|
|
611
|
|
|
// お届け先情報を更新 |
612
|
|
|
$Shipping |
613
|
|
|
->setFromCustomerAddress($CustomerAddress); |
614
|
|
|
|
615
|
|
|
// 配送料金の設定 |
616
|
|
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
617
|
|
|
|
618
|
|
|
// 合計金額の再計算 |
619
|
|
|
$Order = $app['eccube.service.shopping']->getAmount($Order); |
620
|
|
|
|
621
|
|
|
// 配送先を更新 |
622
|
|
|
$app['orm.em']->flush(); |
623
|
|
|
|
624
|
|
|
$event = new EventArgs( |
625
|
|
|
array( |
626
|
|
|
'Order' => $Order, |
627
|
|
|
'shippingId' => $id, |
628
|
|
|
), |
629
|
|
|
$request |
630
|
|
|
); |
631
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event); |
632
|
|
|
|
633
|
|
|
log_info('お届先情報更新完了', array($Shipping->getId())); |
634
|
|
|
return $app->redirect($app->url('shopping')); |
|
|
|
|
635
|
|
|
} |
636
|
|
|
|
637
|
4 |
|
return $app->render( |
638
|
4 |
|
'Shopping/shipping.twig', |
639
|
|
|
array( |
640
|
4 |
|
'Customer' => $app->user(), |
641
|
4 |
|
'shippingId' => $id, |
642
|
|
|
'error' => false, |
643
|
|
|
) |
644
|
|
|
); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
|
|
|
|
648
|
|
|
* お届け先の設定(非会員)がクリックされた場合の処理 |
649
|
|
|
*/ |
|
|
|
|
650
|
19 |
View Code Duplication |
public function shippingEditChange(Application $app, Request $request, $id) |
|
|
|
|
651
|
|
|
{ |
652
|
19 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
653
|
19 |
|
if (!$Order) { |
654
|
|
|
$app->addError('front.shopping.order.error'); |
655
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
656
|
|
|
} |
657
|
|
|
|
658
|
19 |
|
if ('POST' !== $request->getMethod()) { |
659
|
1 |
|
return $app->redirect($app->url('shopping')); |
660
|
|
|
} |
661
|
|
|
|
662
|
18 |
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
663
|
|
|
|
664
|
18 |
|
$event = new EventArgs( |
665
|
|
|
array( |
666
|
18 |
|
'builder' => $builder, |
667
|
18 |
|
'Order' => $Order, |
668
|
|
|
), |
669
|
|
|
$request |
670
|
|
|
); |
671
|
18 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_CHANGE_INITIALIZE, $event); |
672
|
|
|
|
673
|
18 |
|
$form = $builder->getForm(); |
674
|
|
|
|
675
|
18 |
|
$form->handleRequest($request); |
676
|
|
|
|
677
|
18 |
|
if ($form->isSubmitted() && $form->isValid()) { |
678
|
17 |
|
$data = $form->getData(); |
679
|
17 |
|
$message = $data['message']; |
680
|
17 |
|
$Order->setMessage($message); |
681
|
|
|
// 受注情報を更新 |
682
|
17 |
|
$app['orm.em']->flush(); |
683
|
|
|
|
684
|
|
|
// お届け先設定一覧へリダイレクト |
685
|
17 |
|
return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id))); |
686
|
|
|
} |
687
|
|
|
|
688
|
1 |
|
return $app->render('Shopping/index.twig', array( |
689
|
1 |
|
'form' => $form->createView(), |
690
|
1 |
|
'Order' => $Order, |
691
|
|
|
)); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
/** |
|
|
|
|
695
|
|
|
* お届け先の設定(非会員でも使用する) |
696
|
|
|
*/ |
|
|
|
|
697
|
4 |
|
public function shippingEdit(Application $app, Request $request, $id) |
698
|
|
|
{ |
699
|
|
|
// 配送先住所最大値判定 |
700
|
4 |
|
$Customer = $app->user(); |
701
|
4 |
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
|
|
|
|
702
|
2 |
|
$addressCurrNum = count($app->user()->getCustomerAddresses()); |
703
|
2 |
|
$addressMax = $app['config']['deliv_addr_max']; |
704
|
2 |
|
if ($addressCurrNum >= $addressMax) { |
705
|
|
|
throw new NotFoundHttpException('配送先住所最大数エラー'); |
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
// カートチェック |
710
|
4 |
|
if (!$app['eccube.service.cart']->isLocked()) { |
711
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
712
|
|
|
log_info('カートが存在しません'); |
713
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
714
|
|
|
} |
715
|
|
|
|
716
|
4 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
717
|
4 |
|
if (!$Order) { |
718
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
719
|
|
|
$app->addError('front.shopping.order.error'); |
720
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
721
|
|
|
} |
722
|
|
|
|
723
|
4 |
|
$Shipping = $Order->findShipping($id); |
724
|
4 |
|
if (!$Shipping) { |
725
|
|
|
throw new NotFoundHttpException('設定されている配送先が存在しない'); |
726
|
|
|
} |
727
|
4 |
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
728
|
2 |
|
$Shipping->clearCustomerAddress(); |
729
|
|
|
} |
730
|
|
|
|
731
|
4 |
|
$CustomerAddress = new CustomerAddress(); |
732
|
4 |
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
733
|
2 |
|
$CustomerAddress->setCustomer($Customer); |
734
|
|
|
} else { |
735
|
2 |
|
$CustomerAddress->setFromShipping($Shipping); |
736
|
|
|
} |
737
|
|
|
|
738
|
4 |
|
$builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress); |
739
|
|
|
|
740
|
4 |
|
$event = new EventArgs( |
741
|
|
|
array( |
742
|
4 |
|
'builder' => $builder, |
743
|
4 |
|
'Order' => $Order, |
744
|
4 |
|
'Shipping' => $Shipping, |
745
|
4 |
|
'CustomerAddress' => $CustomerAddress, |
746
|
|
|
), |
747
|
|
|
$request |
748
|
|
|
); |
749
|
4 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event); |
750
|
|
|
|
751
|
4 |
|
$form = $builder->getForm(); |
752
|
|
|
|
753
|
4 |
|
$form->handleRequest($request); |
754
|
|
|
|
755
|
4 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
756
|
|
|
|
757
|
3 |
|
log_info('お届け先追加処理開始', array('id' => $Order->getId(), 'shipping' => $id)); |
758
|
|
|
|
759
|
|
|
// 会員の場合、お届け先情報を新規登録 |
760
|
3 |
|
$Shipping->setFromCustomerAddress($CustomerAddress); |
761
|
|
|
|
762
|
3 |
|
if ($Customer instanceof Customer) { |
|
|
|
|
763
|
2 |
|
$app['orm.em']->persist($CustomerAddress); |
764
|
2 |
|
log_info('新規お届け先登録', array( |
|
|
|
|
765
|
2 |
|
'id' => $Order->getId(), |
766
|
2 |
|
'shipping' => $id, |
767
|
2 |
|
'customer address' => $CustomerAddress->getId())); |
|
|
|
|
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
// 配送料金の設定 |
771
|
3 |
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
772
|
|
|
|
773
|
|
|
// 合計金額の再計算 |
774
|
3 |
|
$app['eccube.service.shopping']->getAmount($Order); |
775
|
|
|
|
776
|
|
|
// 配送先を更新 |
777
|
3 |
|
$app['orm.em']->flush(); |
778
|
|
|
|
779
|
3 |
|
$event = new EventArgs( |
780
|
|
|
array( |
781
|
3 |
|
'form' => $form, |
782
|
3 |
|
'Shipping' => $Shipping, |
783
|
3 |
|
'CustomerAddress' => $CustomerAddress, |
784
|
|
|
), |
785
|
|
|
$request |
786
|
|
|
); |
787
|
3 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event); |
788
|
|
|
|
789
|
3 |
|
log_info('お届け先追加処理完了', array('id' => $Order->getId(), 'shipping' => $id)); |
790
|
3 |
|
return $app->redirect($app->url('shopping')); |
|
|
|
|
791
|
|
|
} |
792
|
|
|
|
793
|
3 |
|
return $app->render('Shopping/shipping_edit.twig', array( |
794
|
3 |
|
'form' => $form->createView(), |
795
|
3 |
|
'shippingId' => $id, |
796
|
|
|
)); |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
/** |
|
|
|
|
800
|
|
|
* お客様情報の変更(非会員) |
801
|
|
|
*/ |
|
|
|
|
802
|
|
|
public function customer(Application $app, Request $request) |
803
|
|
|
{ |
804
|
|
|
if ($request->isXmlHttpRequest()) { |
805
|
|
|
try { |
|
|
|
|
806
|
|
|
|
807
|
|
|
log_info('非会員お客様情報変更処理開始'); |
808
|
|
|
|
809
|
|
|
$data = $request->request->all(); |
810
|
|
|
|
811
|
|
|
// 入力チェック |
812
|
|
|
$errors = $this->customerValidation($app, $data); |
813
|
|
|
|
814
|
|
|
foreach ($errors as $error) { |
815
|
|
View Code Duplication |
if ($error->count() != 0) { |
|
|
|
|
816
|
|
|
log_info('非会員お客様情報変更入力チェックエラー'); |
817
|
|
|
$response = new Response(json_encode('NG'), 400); |
818
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
819
|
|
|
return $response; |
|
|
|
|
820
|
|
|
} |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
$pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref'])); |
824
|
|
View Code Duplication |
if (!$pref) { |
|
|
|
|
825
|
|
|
log_info('非会員お客様情報変更入力チェックエラー'); |
826
|
|
|
$response = new Response(json_encode('NG'), 400); |
827
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
828
|
|
|
return $response; |
|
|
|
|
829
|
|
|
} |
830
|
|
|
|
831
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
832
|
|
|
if (!$Order) { |
833
|
|
|
log_info('カートが存在しません'); |
834
|
|
|
$app->addError('front.shopping.order.error'); |
835
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
$Order |
839
|
|
|
->setName01($data['customer_name01']) |
840
|
|
|
->setName02($data['customer_name02']) |
841
|
|
|
->setCompanyName($data['customer_company_name']) |
842
|
|
|
->setTel01($data['customer_tel01']) |
843
|
|
|
->setTel02($data['customer_tel02']) |
844
|
|
|
->setTel03($data['customer_tel03']) |
845
|
|
|
->setZip01($data['customer_zip01']) |
846
|
|
|
->setZip02($data['customer_zip02']) |
847
|
|
|
->setZipCode($data['customer_zip01'].$data['customer_zip02']) |
848
|
|
|
->setPref($pref) |
849
|
|
|
->setAddr01($data['customer_addr01']) |
850
|
|
|
->setAddr02($data['customer_addr02']) |
851
|
|
|
->setEmail($data['customer_email']); |
852
|
|
|
|
853
|
|
|
// 配送先を更新 |
854
|
|
|
$app['orm.em']->flush(); |
855
|
|
|
|
856
|
|
|
// 受注関連情報を最新状態に更新 |
857
|
|
|
$app['orm.em']->refresh($Order); |
858
|
|
|
|
859
|
|
|
$event = new EventArgs( |
860
|
|
|
array( |
861
|
|
|
'Order' => $Order, |
862
|
|
|
'data' => $data, |
863
|
|
|
), |
864
|
|
|
$request |
865
|
|
|
); |
866
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event); |
867
|
|
|
|
868
|
|
|
log_info('非会員お客様情報変更処理完了', array($Order->getId())); |
869
|
|
|
$response = new Response(json_encode('OK')); |
870
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
871
|
|
|
} catch (\Exception $e) { |
872
|
|
|
log_error('予期しないエラー', array($e->getMessage())); |
873
|
|
|
$app['monolog']->error($e); |
874
|
|
|
|
875
|
|
|
$response = new Response(json_encode('NG'), 500); |
876
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
return $response; |
880
|
|
|
} |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
/** |
|
|
|
|
884
|
|
|
* ログイン |
885
|
|
|
*/ |
|
|
|
|
886
|
4 |
|
public function login(Application $app, Request $request) |
887
|
|
|
{ |
888
|
4 |
|
if (!$app['eccube.service.cart']->isLocked()) { |
889
|
3 |
|
return $app->redirect($app->url('cart')); |
890
|
|
|
} |
891
|
|
|
|
892
|
1 |
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
893
|
|
|
return $app->redirect($app->url('shopping')); |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
897
|
1 |
|
$builder = $app['form.factory']->createNamedBuilder('', 'customer_login'); |
898
|
|
|
|
899
|
1 |
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
|
|
|
|
900
|
|
|
$Customer = $app->user(); |
901
|
|
|
if ($Customer) { |
902
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
903
|
|
|
} |
904
|
|
|
} |
905
|
|
|
|
906
|
1 |
|
$event = new EventArgs( |
907
|
|
|
array( |
908
|
1 |
|
'builder' => $builder, |
909
|
|
|
), |
910
|
|
|
$request |
911
|
|
|
); |
912
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event); |
913
|
|
|
|
914
|
1 |
|
$form = $builder->getForm(); |
915
|
|
|
|
916
|
1 |
|
return $app->render('Shopping/login.twig', array( |
917
|
1 |
|
'error' => $app['security.last_error']($request), |
918
|
1 |
|
'form' => $form->createView(), |
919
|
|
|
)); |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
/** |
|
|
|
|
923
|
|
|
* 非会員処理 |
924
|
|
|
*/ |
|
|
|
|
925
|
35 |
|
public function nonmember(Application $app, Request $request) |
926
|
|
|
{ |
927
|
35 |
|
$cartService = $app['eccube.service.cart']; |
928
|
|
|
|
929
|
|
|
// カートチェック |
930
|
35 |
|
if (!$cartService->isLocked()) { |
931
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
932
|
2 |
|
log_info('カートが存在しません'); |
933
|
2 |
|
return $app->redirect($app->url('cart')); |
|
|
|
|
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
// ログイン済みの場合は, 購入画面へリダイレクト. |
937
|
33 |
|
if ($app->isGranted('ROLE_USER')) { |
938
|
1 |
|
return $app->redirect($app->url('shopping')); |
939
|
|
|
} |
940
|
|
|
|
941
|
|
|
// カートチェック |
942
|
32 |
View Code Duplication |
if (count($cartService->getCart()->getCartItems()) <= 0) { |
|
|
|
|
943
|
|
|
// カートが存在しない時はエラー |
944
|
|
|
log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト'); |
945
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
946
|
|
|
} |
947
|
|
|
|
948
|
32 |
|
$builder = $app['form.factory']->createBuilder('nonmember'); |
949
|
|
|
|
950
|
32 |
|
$event = new EventArgs( |
951
|
|
|
array( |
952
|
32 |
|
'builder' => $builder, |
953
|
|
|
), |
954
|
|
|
$request |
955
|
|
|
); |
956
|
32 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event); |
957
|
|
|
|
958
|
32 |
|
$form = $builder->getForm(); |
959
|
|
|
|
960
|
32 |
|
$form->handleRequest($request); |
961
|
|
|
|
962
|
32 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
963
|
|
|
|
964
|
31 |
|
log_info('非会員お客様情報登録開始'); |
965
|
|
|
|
966
|
31 |
|
$data = $form->getData(); |
967
|
31 |
|
$Customer = new Customer(); |
968
|
|
|
$Customer |
969
|
31 |
|
->setName01($data['name01']) |
970
|
31 |
|
->setName02($data['name02']) |
971
|
31 |
|
->setKana01($data['kana01']) |
972
|
31 |
|
->setKana02($data['kana02']) |
973
|
31 |
|
->setCompanyName($data['company_name']) |
974
|
31 |
|
->setEmail($data['email']) |
975
|
31 |
|
->setTel01($data['tel01']) |
976
|
31 |
|
->setTel02($data['tel02']) |
977
|
31 |
|
->setTel03($data['tel03']) |
978
|
31 |
|
->setZip01($data['zip01']) |
979
|
31 |
|
->setZip02($data['zip02']) |
980
|
31 |
|
->setZipCode($data['zip01'].$data['zip02']) |
981
|
31 |
|
->setPref($data['pref']) |
982
|
31 |
|
->setAddr01($data['addr01']) |
983
|
31 |
|
->setAddr02($data['addr02']); |
984
|
|
|
|
985
|
|
|
// 非会員複数配送用 |
986
|
31 |
|
$CustomerAddress = new CustomerAddress(); |
987
|
|
|
$CustomerAddress |
988
|
31 |
|
->setCustomer($Customer) |
989
|
31 |
|
->setName01($data['name01']) |
990
|
31 |
|
->setName02($data['name02']) |
991
|
31 |
|
->setKana01($data['kana01']) |
992
|
31 |
|
->setKana02($data['kana02']) |
993
|
31 |
|
->setCompanyName($data['company_name']) |
994
|
31 |
|
->setTel01($data['tel01']) |
995
|
31 |
|
->setTel02($data['tel02']) |
996
|
31 |
|
->setTel03($data['tel03']) |
997
|
31 |
|
->setZip01($data['zip01']) |
998
|
31 |
|
->setZip02($data['zip02']) |
999
|
31 |
|
->setZipCode($data['zip01'].$data['zip02']) |
1000
|
31 |
|
->setPref($data['pref']) |
1001
|
31 |
|
->setAddr01($data['addr01']) |
1002
|
31 |
|
->setAddr02($data['addr02']) |
1003
|
31 |
|
->setDelFlg(Constant::DISABLED); |
1004
|
31 |
|
$Customer->addCustomerAddress($CustomerAddress); |
1005
|
|
|
|
1006
|
|
|
// 受注情報を取得 |
1007
|
31 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
1008
|
|
|
|
1009
|
|
|
// 初回アクセス(受注データがない)の場合は, 受注情報を作成 |
1010
|
31 |
|
if (is_null($Order)) { |
1011
|
|
|
// 受注情報を作成 |
1012
|
|
|
try { |
1013
|
|
|
// 受注情報を作成 |
1014
|
31 |
|
$Order = $app['eccube.service.shopping']->createOrder($Customer); |
1015
|
|
|
} catch (CartException $e) { |
1016
|
|
|
$app->addRequestError($e->getMessage()); |
1017
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
1018
|
|
|
} |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
// 非会員用セッションを作成 |
1022
|
31 |
|
$nonMember = array(); |
1023
|
31 |
|
$nonMember['customer'] = $Customer; |
1024
|
31 |
|
$nonMember['pref'] = $Customer->getPref()->getId(); |
1025
|
31 |
|
$app['session']->set($this->sessionKey, $nonMember); |
1026
|
|
|
|
1027
|
31 |
|
$customerAddresses = array(); |
1028
|
31 |
|
$customerAddresses[] = $CustomerAddress; |
1029
|
31 |
|
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); |
1030
|
|
|
|
1031
|
31 |
|
$event = new EventArgs( |
1032
|
|
|
array( |
1033
|
31 |
|
'form' => $form, |
1034
|
31 |
|
'Order' => $Order, |
1035
|
|
|
), |
1036
|
|
|
$request |
1037
|
|
|
); |
1038
|
31 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event); |
1039
|
|
|
|
1040
|
31 |
|
if ($event->getResponse() !== null) { |
1041
|
|
|
return $event->getResponse(); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
31 |
|
log_info('非会員お客様情報登録完了', array($Order->getId())); |
1045
|
|
|
|
1046
|
31 |
|
return $app->redirect($app->url('shopping')); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
1 |
|
return $app->render('Shopping/nonmember.twig', array( |
1050
|
1 |
|
'form' => $form->createView(), |
1051
|
|
|
)); |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
/** |
|
|
|
|
1055
|
|
|
* 複数配送処理がクリックされた場合の処理 |
1056
|
|
|
*/ |
|
|
|
|
1057
|
|
View Code Duplication |
public function shippingMultipleChange(Application $app, Request $request) |
|
|
|
|
1058
|
|
|
{ |
1059
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
1060
|
|
|
if (!$Order) { |
1061
|
|
|
$app->addError('front.shopping.order.error'); |
1062
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
if ('POST' !== $request->getMethod()) { |
1066
|
|
|
return $app->redirect($app->url('shopping')); |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
$builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order); |
1070
|
|
|
|
1071
|
|
|
$event = new EventArgs( |
1072
|
|
|
array( |
1073
|
|
|
'builder' => $builder, |
1074
|
|
|
'Order' => $Order, |
1075
|
|
|
), |
1076
|
|
|
$request |
1077
|
|
|
); |
1078
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event); |
1079
|
|
|
|
1080
|
|
|
$form = $builder->getForm(); |
1081
|
|
|
|
1082
|
|
|
$form->handleRequest($request); |
1083
|
|
|
|
1084
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
1085
|
|
|
$data = $form->getData(); |
1086
|
|
|
$message = $data['message']; |
1087
|
|
|
$Order->setMessage($message); |
1088
|
|
|
// 受注情報を更新 |
1089
|
|
|
$app['orm.em']->flush(); |
1090
|
|
|
|
1091
|
|
|
// 複数配送設定へリダイレクト |
1092
|
|
|
return $app->redirect($app->url('shopping_shipping_multiple')); |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
return $app->render('Shopping/index.twig', array( |
1096
|
|
|
'form' => $form->createView(), |
1097
|
|
|
'Order' => $Order, |
1098
|
|
|
)); |
1099
|
|
|
} |
1100
|
|
|
|
1101
|
|
|
|
1102
|
|
|
/** |
|
|
|
|
1103
|
|
|
* 複数配送処理 |
1104
|
|
|
*/ |
|
|
|
|
1105
|
37 |
|
public function shippingMultiple(Application $app, Request $request) |
1106
|
|
|
{ |
1107
|
37 |
|
$cartService = $app['eccube.service.cart']; |
1108
|
|
|
|
1109
|
|
|
// カートチェック |
1110
|
37 |
|
if (!$cartService->isLocked()) { |
1111
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
1112
|
4 |
|
log_info('カートが存在しません'); |
1113
|
4 |
|
return $app->redirect($app->url('cart')); |
|
|
|
|
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
// カートチェック |
1117
|
33 |
|
if (count($cartService->getCart()->getCartItems()) <= 0) { |
1118
|
|
|
// カートが存在しない時はエラー |
1119
|
|
|
log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト'); |
1120
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
/** @var \Eccube\Entity\Order $Order */ |
1124
|
33 |
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
1125
|
33 |
|
if (!$Order) { |
1126
|
|
|
log_info('購入処理中の受注情報がないため購入エラー'); |
1127
|
|
|
$app->addError('front.shopping.order.error'); |
1128
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
// 処理しやすいようにすべてのShippingItemをまとめる |
1132
|
33 |
|
$ShipmentItems = array(); |
1133
|
33 |
|
foreach ($Order->getShippings() as $Shipping) { |
1134
|
33 |
|
foreach ($Shipping->getShipmentItems() as $ShipmentItem) { |
1135
|
33 |
|
$ShipmentItems[] = $ShipmentItem; |
1136
|
|
|
} |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
// Orderに含まれる商品ごとの数量を求める |
1140
|
33 |
|
$ItemQuantitiesByClassId = array(); |
1141
|
33 |
|
foreach ($ShipmentItems as $item) { |
1142
|
33 |
|
$itemId = $item->getProductClass()->getId(); |
1143
|
33 |
|
$quantity = $item->getQuantity(); |
1144
|
33 |
|
if (array_key_exists($itemId, $ItemQuantitiesByClassId)) { |
1145
|
|
|
$ItemQuantitiesByClassId[$itemId] += $quantity; |
1146
|
|
|
} else { |
1147
|
33 |
|
$ItemQuantitiesByClassId[$itemId] = $quantity; |
1148
|
|
|
} |
1149
|
|
|
} |
1150
|
|
|
|
1151
|
|
|
// FormBuilder用に商品ごとにShippingItemをまとめる |
1152
|
33 |
|
$ShipmentItemsForFormBuilder = array(); |
1153
|
33 |
|
$tmpAddedClassIds = array(); |
1154
|
33 |
|
foreach ($ShipmentItems as $item) { |
1155
|
33 |
|
$itemId = $item->getProductClass()->getId(); |
1156
|
33 |
|
if (!in_array($itemId, $tmpAddedClassIds)) { |
1157
|
33 |
|
$ShipmentItemsForFormBuilder[] = $item; |
1158
|
33 |
|
$tmpAddedClassIds[] = $itemId; |
1159
|
|
|
} |
1160
|
|
|
} |
1161
|
|
|
|
1162
|
|
|
// Form生成 |
1163
|
33 |
|
$builder = $app->form(); |
1164
|
|
|
$builder |
1165
|
33 |
|
->add('shipping_multiple', 'collection', array( |
1166
|
33 |
|
'type' => 'shipping_multiple', |
1167
|
33 |
|
'data' => $ShipmentItemsForFormBuilder, |
1168
|
|
|
'allow_add' => true, |
1169
|
|
|
'allow_delete' => true, |
1170
|
|
|
)); |
1171
|
|
|
// Event |
1172
|
33 |
|
$event = new EventArgs( |
1173
|
|
|
array( |
1174
|
33 |
|
'builder' => $builder, |
1175
|
33 |
|
'Order' => $Order, |
1176
|
|
|
), |
1177
|
|
|
$request |
1178
|
|
|
); |
1179
|
33 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event); |
1180
|
|
|
|
1181
|
33 |
|
$form = $builder->getForm(); |
1182
|
33 |
|
$form->handleRequest($request); |
1183
|
|
|
|
1184
|
33 |
|
$errors = array(); |
1185
|
33 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
1186
|
|
|
|
1187
|
32 |
|
log_info('複数配送設定処理開始', array($Order->getId())); |
1188
|
|
|
|
1189
|
32 |
|
$data = $form['shipping_multiple']; |
1190
|
|
|
|
1191
|
|
|
// フォームの入力から、送り先ごとに商品の数量を集計する |
1192
|
32 |
|
$arrShipmentItemTemp = array(); |
1193
|
32 |
|
foreach ($data as $mulitples) { |
1194
|
32 |
|
$ShipmentItem = $mulitples->getData(); |
1195
|
32 |
|
foreach ($mulitples as $items) { |
1196
|
32 |
|
foreach ($items as $item) { |
1197
|
32 |
|
$cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); |
1198
|
32 |
|
$itemId = $ShipmentItem->getProductClass()->getId(); |
1199
|
32 |
|
$quantity = $item['quantity']->getData(); |
1200
|
|
|
|
1201
|
32 |
|
if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($itemId, $arrShipmentItemTemp[$cusAddId])) { |
1202
|
10 |
|
$arrShipmentItemTemp[$cusAddId][$itemId] = $arrShipmentItemTemp[$cusAddId][$itemId] + $quantity; |
1203
|
|
|
} else { |
1204
|
32 |
|
$arrShipmentItemTemp[$cusAddId][$itemId] = $quantity; |
1205
|
|
|
} |
1206
|
|
|
} |
1207
|
|
|
} |
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
// フォームの入力から、商品ごとの数量を集計する |
1211
|
32 |
|
$itemQuantities = array(); |
1212
|
32 |
|
foreach ($arrShipmentItemTemp as $FormItemByAddress) { |
1213
|
32 |
|
foreach ($FormItemByAddress as $itemId => $quantity) { |
1214
|
32 |
|
if (array_key_exists($itemId, $itemQuantities)) { |
1215
|
17 |
|
$itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity; |
1216
|
|
|
} else { |
1217
|
32 |
|
$itemQuantities[$itemId] = $quantity; |
1218
|
|
|
} |
1219
|
|
|
} |
1220
|
|
|
} |
1221
|
|
|
|
1222
|
|
|
// 「Orderに含まれる商品ごとの数量」と「フォームに入力された商品ごとの数量」が一致しているかの確認 |
1223
|
|
|
// 数量が異なっているならエラーを表示する |
1224
|
32 |
|
foreach ($ItemQuantitiesByClassId as $key => $value) { |
1225
|
32 |
|
if (array_key_exists($key, $itemQuantities)) { |
1226
|
32 |
|
if ($itemQuantities[$key] != $value) { |
1227
|
2 |
|
$errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff')); |
1228
|
|
|
|
1229
|
|
|
// 対象がなければエラー |
1230
|
2 |
|
log_info('複数配送設定入力チェックエラー', array($Order->getId())); |
1231
|
2 |
|
return $app->render('Shopping/shipping_multiple.twig', array( |
|
|
|
|
1232
|
2 |
|
'form' => $form->createView(), |
1233
|
2 |
|
'shipmentItems' => $ShipmentItemsForFormBuilder, |
1234
|
2 |
|
'compItemQuantities' => $ItemQuantitiesByClassId, |
1235
|
32 |
|
'errors' => $errors, |
1236
|
|
|
)); |
1237
|
|
|
} |
1238
|
|
|
} |
1239
|
|
|
} |
1240
|
|
|
|
1241
|
|
|
// -- ここから先がお届け先を再生成する処理 -- |
1242
|
|
|
|
1243
|
|
|
// お届け先情報をすべて削除 |
1244
|
30 |
|
foreach ($Order->getShippings() as $Shipping) { |
1245
|
30 |
|
$Order->removeShipping($Shipping); |
1246
|
30 |
|
$app['orm.em']->remove($Shipping); |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
// お届け先のリストを作成する |
1250
|
30 |
|
$ShippingList = array(); |
1251
|
30 |
|
foreach ($data as $mulitples) { |
1252
|
30 |
|
$ShipmentItem = $mulitples->getData(); |
1253
|
30 |
|
$ProductClass = $ShipmentItem->getProductClass(); |
1254
|
30 |
|
$Delivery = $ShipmentItem->getShipping()->getDelivery(); |
1255
|
30 |
|
$productTypeId = $ProductClass->getProductType()->getId(); |
1256
|
|
|
|
1257
|
30 |
|
foreach ($mulitples as $items) { |
1258
|
30 |
|
foreach ($items as $item) { |
1259
|
30 |
|
$CustomerAddress = $this->getCustomerAddress($app, $item['customer_address']->getData()); |
1260
|
30 |
|
$cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); |
1261
|
|
|
|
1262
|
30 |
|
$Shipping = new Shipping(); |
1263
|
|
|
$Shipping |
1264
|
30 |
|
->setFromCustomerAddress($CustomerAddress) |
1265
|
30 |
|
->setDelivery($Delivery) |
1266
|
30 |
|
->setDelFlg(Constant::DISABLED) |
1267
|
30 |
|
->setOrder($Order); |
1268
|
|
|
|
1269
|
30 |
|
$ShippingList[$cusAddId][$productTypeId] = $Shipping; |
1270
|
|
|
} |
1271
|
|
|
} |
1272
|
|
|
} |
1273
|
|
|
// お届け先のリストを保存 |
1274
|
30 |
|
foreach ($ShippingList as $ShippingListByAddress) { |
1275
|
30 |
|
foreach ($ShippingListByAddress as $Shipping) { |
1276
|
30 |
|
$app['orm.em']->persist($Shipping); |
1277
|
|
|
} |
1278
|
|
|
} |
1279
|
|
|
|
1280
|
|
|
// お届け先に、配送商品の情報(ShipmentItem)を関連付ける |
1281
|
30 |
|
foreach ($data as $mulitples) { |
1282
|
30 |
|
$ShipmentItem = $mulitples->getData(); |
1283
|
30 |
|
$ProductClass = $ShipmentItem->getProductClass(); |
1284
|
30 |
|
$Product = $ShipmentItem->getProduct(); |
1285
|
30 |
|
$productTypeId = $ProductClass->getProductType()->getId(); |
1286
|
30 |
|
$productClassId = $ProductClass->getId(); |
1287
|
|
|
|
1288
|
30 |
|
foreach ($mulitples as $items) { |
1289
|
30 |
|
foreach ($items as $item) { |
1290
|
30 |
|
$cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); |
1291
|
|
|
|
1292
|
|
|
// お届け先から商品の数量を取得 |
1293
|
30 |
|
$quantity = 0; |
|
|
|
|
1294
|
30 |
|
if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($productClassId, $arrShipmentItemTemp[$cusAddId])) { |
1295
|
30 |
|
$quantity = $arrShipmentItemTemp[$cusAddId][$productClassId]; |
1296
|
30 |
|
unset($arrShipmentItemTemp[$cusAddId][$productClassId]); |
1297
|
|
|
} else { |
1298
|
|
|
// この配送先には送る商品がないのでスキップ(通常ありえない) |
1299
|
10 |
|
continue; |
1300
|
|
|
} |
1301
|
|
|
|
1302
|
|
|
// 関連付けるお届け先のインスタンスを取得 |
1303
|
30 |
|
$Shipping = $ShippingList[$cusAddId][$productTypeId]; |
1304
|
|
|
|
1305
|
|
|
// インスタンスを生成して保存 |
1306
|
30 |
|
$ShipmentItem = new ShipmentItem(); |
1307
|
30 |
|
$ShipmentItem->setShipping($Shipping) |
1308
|
30 |
|
->setOrder($Order) |
1309
|
30 |
|
->setProductClass($ProductClass) |
1310
|
30 |
|
->setProduct($Product) |
1311
|
30 |
|
->setProductName($Product->getName()) |
1312
|
30 |
|
->setProductCode($ProductClass->getCode()) |
1313
|
30 |
|
->setPrice($ProductClass->getPrice02()) |
1314
|
30 |
|
->setQuantity($quantity); |
1315
|
|
|
|
1316
|
30 |
|
$ClassCategory1 = $ProductClass->getClassCategory1(); |
1317
|
30 |
|
if (!is_null($ClassCategory1)) { |
1318
|
30 |
|
$ShipmentItem->setClasscategoryName1($ClassCategory1->getName()); |
1319
|
30 |
|
$ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName()); |
1320
|
|
|
} |
1321
|
30 |
|
$ClassCategory2 = $ProductClass->getClassCategory2(); |
1322
|
30 |
|
if (!is_null($ClassCategory2)) { |
1323
|
24 |
|
$ShipmentItem->setClasscategoryName2($ClassCategory2->getName()); |
1324
|
24 |
|
$ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName()); |
1325
|
|
|
} |
1326
|
30 |
|
$Shipping->addShipmentItem($ShipmentItem); |
1327
|
30 |
|
$app['orm.em']->persist($ShipmentItem); |
1328
|
|
|
} |
1329
|
|
|
} |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
// 送料を計算(お届け先ごと) |
1333
|
30 |
|
foreach ($ShippingList as $data) { |
1334
|
|
|
// data is product type => shipping |
1335
|
30 |
|
foreach ($data as $Shipping) { |
1336
|
|
|
// 配送料金の設定 |
1337
|
30 |
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
1338
|
30 |
|
$Order->addShipping($Shipping); |
1339
|
|
|
} |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
// 合計金額の再計算 |
1343
|
30 |
|
$Order = $app['eccube.service.shopping']->getAmount($Order); |
1344
|
|
|
|
1345
|
|
|
// 配送先を更新 |
1346
|
30 |
|
$app['orm.em']->flush(); |
1347
|
|
|
|
1348
|
30 |
|
$event = new EventArgs( |
1349
|
|
|
array( |
1350
|
30 |
|
'form' => $form, |
1351
|
30 |
|
'Order' => $Order, |
1352
|
|
|
), |
1353
|
|
|
$request |
1354
|
|
|
); |
1355
|
30 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event); |
1356
|
|
|
|
1357
|
30 |
|
log_info('複数配送設定処理完了', array($Order->getId())); |
1358
|
30 |
|
return $app->redirect($app->url('shopping')); |
|
|
|
|
1359
|
|
|
} |
1360
|
|
|
|
1361
|
5 |
|
return $app->render('Shopping/shipping_multiple.twig', array( |
1362
|
5 |
|
'form' => $form->createView(), |
1363
|
5 |
|
'shipmentItems' => $ShipmentItemsForFormBuilder, |
1364
|
5 |
|
'compItemQuantities' => $ItemQuantitiesByClassId, |
1365
|
5 |
|
'errors' => $errors, |
1366
|
|
|
)); |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* フォームの情報からお届け先のインデックスを返す |
1371
|
|
|
* |
1372
|
|
|
* @param Application $app |
|
|
|
|
1373
|
|
|
* @param mixed $CustomerAddressData |
1374
|
|
|
* @return int |
1375
|
|
|
*/ |
1376
|
32 |
|
private function getCustomerAddressId($CustomerAddressData) |
1377
|
|
|
{ |
1378
|
32 |
|
if ($CustomerAddressData instanceof CustomerAddress) { |
|
|
|
|
1379
|
15 |
|
return $CustomerAddressData->getId(); |
1380
|
|
|
} else { |
1381
|
17 |
|
return $CustomerAddressData; |
1382
|
|
|
} |
1383
|
|
|
} |
1384
|
|
|
|
1385
|
|
|
/** |
1386
|
|
|
* フォームの情報からお届け先のインスタンスを返す |
1387
|
|
|
* |
1388
|
|
|
* @param Application $app |
1389
|
|
|
* @param mixed $CustomerAddressData |
1390
|
|
|
* @return CustomerAddress |
1391
|
|
|
*/ |
1392
|
30 |
|
private function getCustomerAddress(Application $app, $CustomerAddressData) |
1393
|
|
|
{ |
1394
|
30 |
|
if ($CustomerAddressData instanceof CustomerAddress) { |
|
|
|
|
1395
|
14 |
|
return $CustomerAddressData; |
1396
|
|
|
} else { |
1397
|
16 |
|
$cusAddId = $CustomerAddressData; |
1398
|
16 |
|
$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); |
1399
|
16 |
|
$customerAddresses = unserialize($customerAddresses); |
1400
|
|
|
|
1401
|
16 |
|
$CustomerAddress = $customerAddresses[$cusAddId]; |
1402
|
16 |
|
$pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId()); |
1403
|
16 |
|
$CustomerAddress->setPref($pref); |
1404
|
|
|
|
1405
|
16 |
|
return $CustomerAddress; |
1406
|
|
|
} |
1407
|
|
|
} |
1408
|
|
|
|
1409
|
|
|
/** |
|
|
|
|
1410
|
|
|
* 非会員用複数配送設定時の新規お届け先の設定 |
1411
|
|
|
*/ |
|
|
|
|
1412
|
10 |
|
public function shippingMultipleEdit(Application $app, Request $request) |
|
|
|
|
1413
|
|
|
{ |
1414
|
|
|
// カートチェック |
1415
|
10 |
|
if (!$app['eccube.service.cart']->isLocked()) { |
1416
|
|
|
log_info('カートが存在しません'); |
1417
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
1418
|
|
|
return $app->redirect($app->url('cart')); |
1419
|
|
|
} |
1420
|
|
|
|
1421
|
|
|
// 非会員用Customerを取得 |
1422
|
10 |
|
$Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); |
1423
|
10 |
|
$CustomerAddress = new CustomerAddress(); |
1424
|
10 |
|
$CustomerAddress->setCustomer($Customer); |
1425
|
10 |
|
$Customer->addCustomerAddress($CustomerAddress); |
1426
|
|
|
|
1427
|
10 |
|
$builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress); |
1428
|
|
|
|
1429
|
10 |
|
$event = new EventArgs( |
1430
|
|
|
array( |
1431
|
10 |
|
'builder' => $builder, |
1432
|
10 |
|
'Customer' => $Customer, |
1433
|
|
|
), |
1434
|
|
|
$request |
1435
|
|
|
); |
1436
|
10 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event); |
1437
|
|
|
|
1438
|
10 |
|
$form = $builder->getForm(); |
1439
|
|
|
|
1440
|
10 |
|
$form->handleRequest($request); |
1441
|
|
|
|
1442
|
10 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
1443
|
|
|
|
1444
|
10 |
|
log_info('非会員お届け先追加処理開始'); |
1445
|
|
|
|
1446
|
|
|
// 非会員用のセッションに追加 |
1447
|
10 |
|
$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); |
1448
|
10 |
|
$customerAddresses = unserialize($customerAddresses); |
1449
|
10 |
|
$customerAddresses[] = $CustomerAddress; |
1450
|
10 |
|
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); |
1451
|
|
|
|
1452
|
10 |
|
$event = new EventArgs( |
1453
|
|
|
array( |
1454
|
10 |
|
'form' => $form, |
1455
|
10 |
|
'CustomerAddresses' => $customerAddresses, |
1456
|
|
|
), |
1457
|
|
|
$request |
1458
|
|
|
); |
1459
|
10 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event); |
1460
|
|
|
|
1461
|
10 |
|
log_info('非会員お届け先追加処理完了'); |
1462
|
|
|
|
1463
|
10 |
|
return $app->redirect($app->url('shopping_shipping_multiple')); |
1464
|
|
|
} |
1465
|
|
|
|
1466
|
1 |
|
return $app->render('Shopping/shipping_multiple_edit.twig', array( |
1467
|
1 |
|
'form' => $form->createView(), |
1468
|
|
|
)); |
1469
|
|
|
} |
1470
|
|
|
|
1471
|
|
|
/** |
|
|
|
|
1472
|
|
|
* 購入エラー画面表示 |
1473
|
|
|
*/ |
|
|
|
|
1474
|
2 |
|
public function shoppingError(Application $app, Request $request) |
1475
|
|
|
{ |
1476
|
|
|
|
1477
|
2 |
|
$event = new EventArgs( |
1478
|
2 |
|
array(), |
1479
|
|
|
$request |
1480
|
|
|
); |
1481
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event); |
1482
|
|
|
|
1483
|
2 |
|
if ($event->getResponse() !== null) { |
1484
|
|
|
return $event->getResponse(); |
1485
|
|
|
} |
1486
|
|
|
|
1487
|
2 |
|
return $app->render('Shopping/shopping_error.twig'); |
1488
|
|
|
} |
1489
|
|
|
|
1490
|
|
|
/** |
1491
|
|
|
* 非会員でのお客様情報変更時の入力チェック |
1492
|
|
|
* |
1493
|
|
|
* @param Application $app |
1494
|
|
|
* @param array $data リクエストパラメータ |
1495
|
|
|
* @return array |
1496
|
|
|
*/ |
1497
|
|
|
private function customerValidation(Application $app, array $data) |
1498
|
|
|
{ |
1499
|
|
|
// 入力チェック |
1500
|
|
|
$errors = array(); |
1501
|
|
|
|
1502
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name01'], array( |
|
|
|
|
1503
|
|
|
new Assert\NotBlank(), |
1504
|
|
|
new Assert\Length(array('max' => $app['config']['name_len'],)), |
|
|
|
|
1505
|
|
|
new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) |
1506
|
|
|
)); |
1507
|
|
|
|
1508
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name02'], array( |
|
|
|
|
1509
|
|
|
new Assert\NotBlank(), |
1510
|
|
|
new Assert\Length(array('max' => $app['config']['name_len'],)), |
|
|
|
|
1511
|
|
|
new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) |
1512
|
|
|
)); |
1513
|
|
|
|
1514
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_company_name'], array( |
1515
|
|
|
new Assert\Length(array('max' => $app['config']['stext_len'])), |
1516
|
|
|
)); |
1517
|
|
|
|
1518
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel01'], array( |
1519
|
|
|
new Assert\NotBlank(), |
1520
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1521
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1522
|
|
|
)); |
1523
|
|
|
|
1524
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel02'], array( |
1525
|
|
|
new Assert\NotBlank(), |
1526
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1527
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1528
|
|
|
)); |
1529
|
|
|
|
1530
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel03'], array( |
1531
|
|
|
new Assert\NotBlank(), |
1532
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1533
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1534
|
|
|
)); |
1535
|
|
|
|
1536
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip01'], array( |
1537
|
|
|
new Assert\NotBlank(), |
1538
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1539
|
|
|
new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])), |
1540
|
|
|
)); |
1541
|
|
|
|
1542
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip02'], array( |
1543
|
|
|
new Assert\NotBlank(), |
1544
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1545
|
|
|
new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])), |
1546
|
|
|
)); |
1547
|
|
|
|
1548
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr01'], array( |
1549
|
|
|
new Assert\NotBlank(), |
1550
|
|
|
new Assert\Length(array('max' => $app['config']['address1_len'])), |
1551
|
|
|
)); |
1552
|
|
|
|
1553
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr02'], array( |
1554
|
|
|
new Assert\NotBlank(), |
1555
|
|
|
new Assert\Length(array('max' => $app['config']['address2_len'])), |
1556
|
|
|
)); |
1557
|
|
|
|
1558
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_email'], array( |
1559
|
|
|
new Assert\NotBlank(), |
1560
|
|
|
new Assert\Email(array('strict' => true)), |
1561
|
|
|
)); |
1562
|
|
|
|
1563
|
|
|
return $errors; |
1564
|
|
|
} |
1565
|
|
|
} |
1566
|
|
|
|