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