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\Entity\MailHistory; |
34
|
|
|
use Eccube\Exception\CartException; |
35
|
|
|
use Symfony\Component\HttpFoundation\Request; |
36
|
|
|
use Symfony\Component\HttpFoundation\Response; |
37
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
38
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
39
|
|
|
|
40
|
|
|
class ShoppingController extends AbstractController |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string 非会員用セッションキー |
45
|
|
|
*/ |
46
|
|
|
private $sessionKey = 'eccube.front.shopping.nonmember'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string 非会員用セッションキー |
50
|
|
|
*/ |
51
|
|
|
private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string 複数配送警告メッセージ |
55
|
|
|
*/ |
56
|
|
|
private $sessionMultipleKey = 'eccube.front.shopping.multiple'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string 受注IDキー |
60
|
|
|
*/ |
61
|
|
|
private $sessionOrderKey = 'eccube.front.shopping.order.id'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* 購入画面表示 |
65
|
|
|
* |
66
|
|
|
* @param Application $app |
67
|
|
|
* @param Request $request |
|
|
|
|
68
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response |
69
|
|
|
*/ |
70
|
19 |
|
public function index(Application $app, Request $request) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$cartService = $app['eccube.service.cart']; |
73
|
|
|
|
74
|
|
|
// カートチェック |
75
|
|
|
if (!$cartService->isLocked()) { |
76
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
77
|
|
|
return $app->redirect($app->url('cart')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// カートチェック |
81
|
|
|
if (count($cartService->getCart()->getCartItems()) <= 0) { |
82
|
|
|
// カートが存在しない時はエラー |
83
|
|
|
return $app->redirect($app->url('cart')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// 登録済みの受注情報を取得 |
87
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
88
|
|
|
|
89
|
|
|
// 初回アクセス(受注情報がない)の場合は, 受注情報を作成 |
90
|
|
|
if (is_null($Order)) { |
91
|
|
|
// 未ログインの場合, ログイン画面へリダイレクト. |
92
|
|
|
if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) { |
93
|
|
|
// 非会員でも一度会員登録されていればショッピング画面へ遷移 |
94
|
|
|
$Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); |
95
|
|
|
|
96
|
|
|
if (is_null($Customer)) { |
97
|
|
|
return $app->redirect($app->url('shopping_login')); |
98
|
|
|
} |
99
|
|
|
} else { |
100
|
|
|
$Customer = $app->user(); |
101
|
7 |
|
} |
102
|
|
|
|
103
|
|
|
try { |
104
|
|
|
// 受注情報を作成 |
105
|
|
|
$Order = $app['eccube.service.shopping']->createOrder($Customer); |
106
|
|
|
} catch (CartException $e) { |
107
|
|
|
$app->addRequestError($e->getMessage()); |
108
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
109
|
16 |
|
} |
110
|
|
|
|
111
|
|
|
// セッション情報を削除 |
112
|
|
|
$app['session']->remove($this->sessionOrderKey); |
113
|
|
|
$app['session']->remove($this->sessionMultipleKey); |
114
|
|
|
} else { |
115
|
|
|
// 計算処理 |
116
|
|
|
$Order = $app['eccube.service.shopping']->getAmount($Order); |
117
|
16 |
|
} |
118
|
|
|
|
119
|
|
|
// 受注関連情報を最新状態に更新 |
120
|
|
|
$app['orm.em']->refresh($Order); |
121
|
|
|
|
122
|
|
|
// form作成 |
123
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
124
|
|
|
|
125
|
|
|
// 複数配送の場合、エラーメッセージを一度だけ表示 |
126
|
|
|
if (!$app['session']->has($this->sessionMultipleKey)) { |
127
|
|
|
if (count($Order->getShippings()) > 1) { |
128
|
|
|
$app->addRequestError('shopping.multiple.delivery'); |
129
|
|
|
} |
130
|
|
|
$app['session']->set($this->sessionMultipleKey, 'multiple'); |
131
|
|
|
} |
132
|
|
|
|
133
|
16 |
|
return $app->render('Shopping/index.twig', array( |
134
|
16 |
|
'form' => $form->createView(), |
135
|
|
|
'Order' => $Order, |
136
|
|
|
)); |
137
|
19 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
|
|
|
|
140
|
|
|
* 購入処理 |
141
|
|
|
*/ |
|
|
|
|
142
|
4 |
|
public function confirm(Application $app, Request $request) |
143
|
|
|
{ |
144
|
|
|
$cartService = $app['eccube.service.cart']; |
145
|
|
|
|
146
|
|
|
// カートチェック |
147
|
|
|
if (!$cartService->isLocked()) { |
148
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
149
|
|
|
return $app->redirect($app->url('cart')); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
153
|
4 |
|
if (!$Order) { |
154
|
|
|
$app->addError('front.shopping.order.error'); |
155
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// form作成 |
159
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
160
|
|
|
$form->handleRequest($request); |
161
|
|
|
|
162
|
|
|
if ($form->isSubmitted()) { |
163
|
|
|
if ($form->isValid()) { |
164
|
|
|
$data = $form->getData(); |
165
|
|
|
|
166
|
|
|
// トランザクション制御 |
167
|
|
|
$em = $app['orm.em']; |
168
|
|
|
$em->getConnection()->beginTransaction(); |
169
|
|
|
try { |
170
|
|
|
// 商品公開ステータスチェック、商品制限数チェック、在庫チェック |
171
|
|
|
$check = $app['eccube.service.shopping']->isOrderProduct($em, $Order); |
172
|
4 |
|
if (!$check) { |
173
|
|
|
$em->getConnection()->rollback(); |
174
|
|
|
$em->close(); |
175
|
|
|
|
176
|
|
|
$app->addError('front.shopping.stock.error'); |
177
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
// 受注情報、配送情報を更新 |
181
|
|
|
$app['eccube.service.shopping']->setOrderUpdate($Order, $data); |
182
|
|
|
// 在庫情報を更新 |
183
|
|
|
$app['eccube.service.shopping']->setStockUpdate($em, $Order); |
184
|
|
|
|
185
|
|
|
if ($app->isGranted('ROLE_USER')) { |
186
|
|
|
// 会員の場合、購入金額を更新 |
187
|
|
|
$app['eccube.service.shopping']->setCustomerUpdate($Order, $app->user()); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$em->getConnection()->commit(); |
191
|
|
|
$em->flush(); |
192
|
|
|
} catch (\Exception $e) { |
193
|
|
|
$em->getConnection()->rollback(); |
194
|
|
|
$em->close(); |
195
|
|
|
|
196
|
|
|
$app->log($e); |
197
|
|
|
|
198
|
|
|
$app->addError('front.shopping.system.error'); |
199
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
200
|
4 |
|
} |
201
|
|
|
|
202
|
|
|
// カート削除 |
203
|
|
|
$app['eccube.service.cart']->clear()->save(); |
204
|
|
|
|
205
|
|
|
// メール送信 |
206
|
|
|
$app['eccube.service.mail']->sendOrderMail($Order); |
207
|
|
|
|
208
|
|
|
// 受注IDをセッションにセット |
209
|
|
|
$app['session']->set($this->sessionOrderKey, $Order->getId()); |
210
|
|
|
|
211
|
|
|
// 送信履歴を保存. |
212
|
|
|
$MailTemplate = $app['eccube.repository.mail_template']->find(1); |
213
|
|
|
|
214
|
4 |
|
$body = $app->renderView($MailTemplate->getFileName(), array( |
215
|
4 |
|
'header' => $MailTemplate->getHeader(), |
216
|
4 |
|
'footer' => $MailTemplate->getFooter(), |
217
|
|
|
'Order' => $Order, |
218
|
|
|
)); |
219
|
|
|
|
220
|
|
|
$MailHistory = new MailHistory(); |
221
|
|
|
$MailHistory |
222
|
|
|
->setSubject('[' . $app['eccube.repository.base_info']->get()->getShopName() . '] ' . $MailTemplate->getSubject()) |
|
|
|
|
223
|
4 |
|
->setMailBody($body) |
224
|
4 |
|
->setMailTemplate($MailTemplate) |
225
|
|
|
->setSendDate(new \DateTime()) |
226
|
|
|
->setOrder($Order); |
227
|
|
|
$app['orm.em']->persist($MailHistory); |
228
|
|
|
$app['orm.em']->flush($MailHistory); |
229
|
|
|
|
230
|
|
|
$em->close(); |
231
|
|
|
|
232
|
|
|
// 完了画面表示 |
233
|
|
|
return $app->redirect($app->url('shopping_complete')); |
234
|
|
|
} else { |
235
|
|
|
return $app->render('Shopping/index.twig', array( |
236
|
|
|
'form' => $form->createView(), |
237
|
|
|
'Order' => $Order, |
238
|
|
|
)); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
return $app->redirect($app->url('cart')); |
243
|
4 |
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
/** |
|
|
|
|
247
|
|
|
* 購入完了画面表示 |
248
|
|
|
*/ |
|
|
|
|
249
|
1 |
|
public function complete(Application $app) |
250
|
|
|
{ |
251
|
|
|
// 受注IDを取得 |
252
|
|
|
$orderId = $app['session']->get($this->sessionOrderKey); |
253
|
|
|
|
254
|
|
|
// 受注IDセッションを削除 |
255
|
|
|
$app['session']->remove($this->sessionOrderKey); |
256
|
|
|
|
257
|
1 |
|
return $app->render('Shopping/complete.twig', array( |
258
|
|
|
'orderId' => $orderId, |
259
|
|
|
)); |
260
|
1 |
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
/** |
|
|
|
|
264
|
|
|
* 配送業者選択処理 |
265
|
|
|
*/ |
|
|
|
|
266
|
3 |
|
public function delivery(Application $app, Request $request) |
267
|
|
|
{ |
268
|
|
|
// カートチェック |
269
|
|
|
if (!$app['eccube.service.cart']->isLocked()) { |
270
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
271
|
|
|
return $app->redirect($app->url('cart')); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
275
|
3 |
|
if (!$Order) { |
276
|
|
|
$app->addError('front.shopping.order.error'); |
277
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
281
|
|
|
$form->handleRequest($request); |
282
|
|
|
|
283
|
|
|
if ($form->isSubmitted()) { |
284
|
|
|
if ($form->isValid()) { |
285
|
|
|
$data = $form->getData(); |
286
|
|
|
|
287
|
1 |
|
$shippings = $data['shippings']; |
288
|
|
|
|
289
|
1 |
|
$productDeliveryFeeTotal = 0; |
290
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
291
|
|
|
|
292
|
|
|
foreach ($shippings as $Shipping) { |
293
|
|
|
$Delivery = $Shipping->getDelivery(); |
294
|
|
|
|
295
|
1 |
|
if ($Delivery) { |
296
|
|
|
$deliveryFee = $app['eccube.repository.delivery_fee']->findOneBy(array( |
|
|
|
|
297
|
|
|
'Delivery' => $Delivery, |
298
|
1 |
|
'Pref' => $Shipping->getPref() |
299
|
|
|
)); |
300
|
|
|
|
301
|
|
|
// 商品ごとの配送料合計 |
302
|
|
|
if (!is_null($BaseInfo->getOptionProductDeliveryFee())) { |
303
|
|
|
$productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
$Shipping->setDeliveryFee($deliveryFee); |
307
|
|
|
$Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
308
|
|
|
$Shipping->setShippingDeliveryName($Delivery->getName()); |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
// 支払い情報をセット |
313
|
1 |
|
$payment = $data['payment']; |
314
|
1 |
|
$message = $data['message']; |
315
|
|
|
|
316
|
|
|
$Order->setPayment($payment); |
317
|
|
|
$Order->setPaymentMethod($payment->getMethod()); |
318
|
|
|
$Order->setMessage($message); |
319
|
|
|
$Order->setCharge($payment->getCharge()); |
320
|
|
|
|
321
|
|
|
$Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings)); |
322
|
|
|
|
323
|
|
|
$total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal(); |
324
|
|
|
|
325
|
|
|
$Order->setTotal($total); |
326
|
|
|
$Order->setPaymentTotal($total); |
327
|
|
|
|
328
|
|
|
// 受注関連情報を最新状態に更新 |
329
|
|
|
$app['orm.em']->flush(); |
330
|
|
|
} else { |
331
|
1 |
|
return $app->render('Shopping/index.twig', array( |
332
|
1 |
|
'form' => $form->createView(), |
333
|
|
|
'Order' => $Order, |
334
|
|
|
)); |
335
|
1 |
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
return $app->redirect($app->url('shopping')); |
339
|
|
|
|
340
|
3 |
|
} |
341
|
|
|
|
342
|
|
|
/** |
|
|
|
|
343
|
|
|
* 支払い方法選択処理 |
344
|
|
|
*/ |
|
|
|
|
345
|
2 |
|
public function payment(Application $app, Request $request) |
346
|
|
|
{ |
347
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
348
|
2 |
|
if (!$Order) { |
349
|
|
|
$app->addError('front.shopping.order.error'); |
350
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
354
|
|
|
$form->handleRequest($request); |
355
|
|
|
|
356
|
|
|
if ($form->isSubmitted()) { |
357
|
|
|
if ($form->isValid()) { |
358
|
|
|
$data = $form->getData(); |
359
|
1 |
|
$payment = $data['payment']; |
360
|
1 |
|
$message = $data['message']; |
361
|
|
|
|
362
|
|
|
$Order->setPayment($payment); |
363
|
|
|
$Order->setPaymentMethod($payment->getMethod()); |
364
|
|
|
$Order->setMessage($message); |
365
|
|
|
$Order->setCharge($payment->getCharge()); |
366
|
|
|
|
367
|
|
|
$total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal(); |
368
|
|
|
|
369
|
|
|
$Order->setTotal($total); |
370
|
|
|
$Order->setPaymentTotal($total); |
371
|
|
|
|
372
|
|
|
// 受注関連情報を最新状態に更新 |
373
|
|
|
$app['orm.em']->flush(); |
374
|
|
|
} else { |
375
|
1 |
|
return $app->render('Shopping/index.twig', array( |
376
|
1 |
|
'form' => $form->createView(), |
377
|
|
|
'Order' => $Order, |
378
|
|
|
)); |
379
|
1 |
|
} |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
return $app->redirect($app->url('shopping')); |
383
|
2 |
|
} |
384
|
|
|
|
385
|
|
|
/** |
|
|
|
|
386
|
|
|
* お届け先変更がクリックされた場合の処理 |
387
|
|
|
*/ |
|
|
|
|
388
|
3 |
View Code Duplication |
public function shippingChange(Application $app, Request $request, $id) |
|
|
|
|
389
|
|
|
{ |
390
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
391
|
3 |
|
if (!$Order) { |
392
|
|
|
$app->addError('front.shopping.order.error'); |
393
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
397
|
|
|
$form->handleRequest($request); |
398
|
|
|
|
399
|
|
|
if ($form->isSubmitted()) { |
400
|
|
|
if ($form->isValid()) { |
401
|
|
|
$data = $form->getData(); |
402
|
3 |
|
$message = $data['message']; |
403
|
|
|
$Order->setMessage($message); |
404
|
|
|
// 受注情報を更新 |
405
|
|
|
$app['orm.em']->flush(); |
406
|
|
|
|
407
|
|
|
// お届け先設定一覧へリダイレクト |
408
|
|
|
return $app->redirect($app->url('shopping_shipping', array('id' => $id))); |
409
|
|
|
} else { |
410
|
|
|
return $app->render('Shopping/index.twig', array( |
411
|
|
|
'form' => $form->createView(), |
412
|
|
|
'Order' => $Order, |
413
|
|
|
)); |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
return $app->redirect($app->url('shopping')); |
418
|
3 |
|
} |
419
|
|
|
|
420
|
|
|
/** |
|
|
|
|
421
|
|
|
* お届け先の設定一覧からの選択 |
422
|
|
|
*/ |
|
|
|
|
423
|
2 |
|
public function shipping(Application $app, Request $request, $id) |
424
|
|
|
{ |
425
|
|
|
// カートチェック |
426
|
|
|
if (!$app['eccube.service.cart']->isLocked()) { |
427
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
428
|
|
|
return $app->redirect($app->url('cart')); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
if ('POST' === $request->getMethod()) { |
432
|
|
|
$address = $request->get('address'); |
433
|
|
|
|
434
|
|
|
if (is_null($address)) { |
435
|
|
|
// 選択されていなければエラー |
436
|
|
|
return $app->render( |
437
|
|
|
'Shopping/shipping.twig', |
438
|
|
|
array( |
439
|
|
|
'Customer' => $app->user(), |
440
|
|
|
'shippingId' => $id, |
441
|
|
|
'error' => true, |
442
|
|
|
) |
443
|
|
|
); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
// 選択されたお届け先情報を取得 |
447
|
|
|
$CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array( |
448
|
|
|
'Customer' => $app->user(), |
449
|
|
|
'id' => $address, |
450
|
|
|
)); |
451
|
|
|
if (is_null($CustomerAddress)) { |
452
|
|
|
throw new NotFoundHttpException(); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
456
|
|
|
if (!$Order) { |
457
|
|
|
$app->addError('front.shopping.order.error'); |
458
|
|
|
|
459
|
|
|
return $app->redirect($app->url('shopping_error')); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
$Shipping = $Order->findShipping($id); |
463
|
|
|
if (!$Shipping) { |
464
|
|
|
throw new NotFoundHttpException(); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
// お届け先情報を更新 |
468
|
|
|
$Shipping |
469
|
|
|
->setFromCustomerAddress($CustomerAddress); |
470
|
|
|
|
471
|
|
|
// 配送料金の設定 |
472
|
|
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
473
|
|
|
|
474
|
|
|
// 配送先を更新 |
475
|
|
|
$app['orm.em']->flush(); |
476
|
|
|
|
477
|
|
|
return $app->redirect($app->url('shopping')); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
return $app->render( |
481
|
2 |
|
'Shopping/shipping.twig', |
482
|
|
|
array( |
483
|
2 |
|
'Customer' => $app->user(), |
484
|
|
|
'shippingId' => $id, |
485
|
2 |
|
'error' => false, |
486
|
|
|
) |
487
|
|
|
); |
488
|
2 |
|
} |
489
|
|
|
|
490
|
|
|
/** |
|
|
|
|
491
|
|
|
* お届け先の設定(非会員)がクリックされた場合の処理 |
492
|
|
|
*/ |
|
|
|
|
493
|
5 |
View Code Duplication |
public function shippingEditChange(Application $app, Request $request, $id) |
|
|
|
|
494
|
|
|
{ |
495
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
496
|
5 |
|
if (!$Order) { |
497
|
|
|
$app->addError('front.shopping.order.error'); |
498
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
502
|
|
|
$form->handleRequest($request); |
503
|
|
|
|
504
|
|
|
if ($form->isSubmitted()) { |
505
|
|
|
if ($form->isValid()) { |
506
|
|
|
$data = $form->getData(); |
507
|
3 |
|
$message = $data['message']; |
508
|
|
|
$Order->setMessage($message); |
509
|
|
|
// 受注情報を更新 |
510
|
|
|
$app['orm.em']->flush(); |
511
|
|
|
|
512
|
|
|
// お届け先設定一覧へリダイレクト |
513
|
|
|
return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id))); |
514
|
|
|
} else { |
515
|
|
|
return $app->render('Shopping/index.twig', array( |
516
|
|
|
'form' => $form->createView(), |
517
|
|
|
'Order' => $Order, |
518
|
|
|
)); |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
return $app->redirect($app->url('shopping')); |
523
|
5 |
|
} |
524
|
|
|
|
525
|
|
|
/** |
|
|
|
|
526
|
|
|
* お届け先の設定(非会員でも使用する) |
527
|
|
|
*/ |
|
|
|
|
528
|
2 |
|
public function shippingEdit(Application $app, Request $request, $id) |
529
|
|
|
{ |
530
|
|
|
// 配送先住所最大値判定 |
531
|
|
|
$Customer = $app->user(); |
532
|
2 |
|
if ($Customer instanceof Customer) { |
|
|
|
|
533
|
|
|
$addressCurrNum = count($app->user()->getCustomerAddresses()); |
534
|
|
|
$addressMax = $app['config']['deliv_addr_max']; |
535
|
|
|
if ($addressCurrNum >= $addressMax) { |
536
|
|
|
throw new NotFoundHttpException(); |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
// カートチェック |
541
|
|
|
if (!$app['eccube.service.cart']->isLocked()) { |
542
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
543
|
|
|
return $app->redirect($app->url('cart')); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
547
|
2 |
|
if (!$Order) { |
548
|
|
|
$app->addError('front.shopping.order.error'); |
549
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
$Shipping = $Order->findShipping($id); |
553
|
2 |
|
if (!$Shipping) { |
554
|
|
|
throw new NotFoundHttpException(); |
555
|
|
|
} |
556
|
2 |
|
if ($Customer instanceof Customer) { |
|
|
|
|
557
|
|
|
$Shipping->clearCustomerAddress(); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$CustomerAddress = new CustomerAddress(); |
561
|
2 |
|
if ($Customer instanceof Customer) { |
|
|
|
|
562
|
|
|
$CustomerAddress->setCustomer($Customer); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
$builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress); |
566
|
|
|
$form = $builder->getForm(); |
567
|
|
|
$form->handleRequest($request); |
568
|
|
|
|
569
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
570
|
|
|
// 会員の場合、お届け先情報を新規登録 |
571
|
|
|
$Shipping->setFromCustomerAddress($CustomerAddress); |
572
|
|
|
|
573
|
2 |
|
if ($Customer instanceof Customer) { |
|
|
|
|
574
|
|
|
$app['orm.em']->persist($CustomerAddress); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
// 配送料金の設定 |
578
|
|
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
579
|
|
|
|
580
|
|
|
// 配送先を更新 |
581
|
|
|
$app['orm.em']->flush(); |
|
|
|
|
582
|
|
|
|
583
|
|
|
return $app->redirect($app->url('shopping')); |
584
|
|
|
} |
585
|
|
|
|
586
|
2 |
|
return $app->render('Shopping/shipping_edit.twig', array( |
587
|
2 |
|
'form' => $form->createView(), |
588
|
|
|
'shippingId' => $id, |
589
|
|
|
)); |
590
|
2 |
|
} |
591
|
|
|
|
592
|
|
|
/** |
|
|
|
|
593
|
|
|
* お客様情報の変更(非会員) |
594
|
|
|
*/ |
|
|
|
|
595
|
|
|
public function customer(Application $app, Request $request) |
596
|
|
|
{ |
597
|
|
|
if ($request->isXmlHttpRequest()) { |
598
|
|
|
try { |
599
|
|
|
$data = $request->request->all(); |
600
|
|
|
|
601
|
|
|
// 入力チェック |
602
|
|
|
$errors = $this->customerValidation($app, $data); |
603
|
|
|
|
604
|
|
|
foreach ($errors as $error) { |
605
|
|
View Code Duplication |
if ($error->count() != 0) { |
|
|
|
|
606
|
|
|
$response = new Response(json_encode('NG'), 500); |
607
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
608
|
|
|
return $response; |
|
|
|
|
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
$pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref'])); |
613
|
|
View Code Duplication |
if (!$pref) { |
|
|
|
|
614
|
|
|
$response = new Response(json_encode('NG'), 500); |
615
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
616
|
|
|
return $response; |
|
|
|
|
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
620
|
|
|
if (!$Order) { |
621
|
|
|
$app->addError('front.shopping.order.error'); |
622
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
$Order |
626
|
|
|
->setName01($data['customer_name01']) |
627
|
|
|
->setName02($data['customer_name02']) |
628
|
|
|
->setCompanyName($data['customer_company_name']) |
629
|
|
|
->setTel01($data['customer_tel01']) |
630
|
|
|
->setTel02($data['customer_tel02']) |
631
|
|
|
->setTel03($data['customer_tel03']) |
632
|
|
|
->setZip01($data['customer_zip01']) |
633
|
|
|
->setZip02($data['customer_zip02']) |
634
|
|
|
->setZipCode($data['customer_zip01'] . $data['customer_zip02']) |
|
|
|
|
635
|
|
|
->setPref($pref) |
636
|
|
|
->setAddr01($data['customer_addr01']) |
637
|
|
|
->setAddr02($data['customer_addr02']) |
638
|
|
|
->setEmail($data['customer_email']); |
639
|
|
|
|
640
|
|
|
// 配送先を更新 |
641
|
|
|
$app['orm.em']->flush(); |
642
|
|
|
|
643
|
|
|
// 受注関連情報を最新状態に更新 |
644
|
|
|
$app['orm.em']->refresh($Order); |
645
|
|
|
|
646
|
|
|
$response = new Response(json_encode('OK')); |
647
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
648
|
|
|
} catch (\Exception $e) { |
649
|
|
|
$app->log($e); |
650
|
|
|
|
651
|
|
|
$response = new Response(json_encode('NG'), 500); |
652
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
return $response; |
656
|
|
|
} |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
|
|
|
|
660
|
|
|
* ログイン |
661
|
|
|
*/ |
|
|
|
|
662
|
2 |
|
public function login(Application $app, Request $request) |
663
|
|
|
{ |
664
|
|
|
if (!$app['eccube.service.cart']->isLocked()) { |
665
|
|
|
return $app->redirect($app->url('cart')); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { |
669
|
|
|
return $app->redirect($app->url('shopping')); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
673
|
|
|
$builder = $app['form.factory']->createNamedBuilder('', 'customer_login'); |
674
|
|
|
|
675
|
|
View Code Duplication |
if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
|
|
|
|
676
|
|
|
$Customer = $app->user(); |
677
|
|
|
if ($Customer) { |
678
|
|
|
$builder->get('login_email')->setData($Customer->getEmail()); |
679
|
|
|
} |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
$form = $builder->getForm(); |
683
|
|
|
|
684
|
|
|
return $app->render('Shopping/login.twig', array( |
685
|
|
|
'error' => $app['security.last_error']($request), |
686
|
|
|
'form' => $form->createView(), |
687
|
|
|
)); |
688
|
2 |
|
} |
689
|
|
|
|
690
|
|
|
/** |
|
|
|
|
691
|
|
|
* 非会員処理 |
692
|
|
|
*/ |
|
|
|
|
693
|
11 |
|
public function nonmember(Application $app, Request $request) |
694
|
|
|
{ |
695
|
|
|
$cartService = $app['eccube.service.cart']; |
696
|
|
|
|
697
|
|
|
// カートチェック |
698
|
|
|
if (!$cartService->isLocked()) { |
699
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
700
|
|
|
return $app->redirect($app->url('cart')); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
// ログイン済みの場合は, 購入画面へリダイレクト. |
704
|
|
|
if ($app->isGranted('ROLE_USER')) { |
705
|
|
|
return $app->redirect($app->url('shopping')); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
// カートチェック |
709
|
|
|
if (count($cartService->getCart()->getCartItems()) <= 0) { |
710
|
|
|
// カートが存在しない時はエラー |
711
|
|
|
return $app->redirect($app->url('cart')); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
$Customer = new Customer(); |
715
|
|
|
$form = $app['form.factory']->createBuilder('nonmember', $Customer)->getForm(); |
716
|
|
|
$form->handleRequest($request); |
717
|
|
|
|
718
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
719
|
|
|
$CustomerAddress = new CustomerAddress(); |
720
|
|
|
$CustomerAddress |
721
|
|
|
->setFromCustomer($Customer); |
722
|
|
|
$Customer->addCustomerAddress($CustomerAddress); |
723
|
|
|
|
724
|
|
|
// 受注情報を取得 |
725
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
726
|
|
|
|
727
|
|
|
// 初回アクセス(受注データがない)の場合は, 受注情報を作成 |
728
|
|
|
if (is_null($Order)) { |
729
|
|
|
// 受注情報を作成 |
730
|
|
|
try { |
731
|
|
|
// 受注情報を作成 |
732
|
|
|
$app['eccube.service.shopping']->createOrder($Customer); |
733
|
|
|
} catch (CartException $e) { |
734
|
|
|
$app->addRequestError($e->getMessage()); |
735
|
|
|
return $app->redirect($app->url('cart')); |
|
|
|
|
736
|
8 |
|
} |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
// 非会員用セッションを作成 |
740
|
8 |
|
$nonMember = array(); |
741
|
8 |
|
$nonMember['customer'] = $Customer; |
742
|
|
|
$nonMember['pref'] = $Customer->getPref()->getId(); |
743
|
|
|
$app['session']->set($this->sessionKey, $nonMember); |
744
|
|
|
|
745
|
8 |
|
$customerAddresses = array(); |
746
|
8 |
|
$customerAddresses[] = $CustomerAddress; |
747
|
|
|
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); |
748
|
|
|
|
749
|
|
|
return $app->redirect($app->url('shopping')); |
750
|
|
|
} |
751
|
|
|
|
752
|
1 |
|
return $app->render('Shopping/nonmember.twig', array( |
753
|
1 |
|
'form' => $form->createView(), |
754
|
|
|
)); |
755
|
11 |
|
} |
756
|
|
|
|
757
|
|
|
/** |
|
|
|
|
758
|
|
|
* 複数配送処理がクリックされた場合の処理 |
759
|
|
|
*/ |
|
|
|
|
760
|
|
View Code Duplication |
public function shippingMultipleChange(Application $app, Request $request) |
|
|
|
|
761
|
|
|
{ |
762
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
763
|
|
|
if (!$Order) { |
764
|
|
|
$app->addError('front.shopping.order.error'); |
765
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
$form = $app['eccube.service.shopping']->getShippingForm($Order); |
769
|
|
|
$form->handleRequest($request); |
770
|
|
|
|
771
|
|
|
if ($form->isSubmitted()) { |
772
|
|
|
if ($form->isValid()) { |
773
|
|
|
$data = $form->getData(); |
774
|
|
|
$message = $data['message']; |
775
|
|
|
$Order->setMessage($message); |
776
|
|
|
// 受注情報を更新 |
777
|
|
|
$app['orm.em']->flush(); |
778
|
|
|
|
779
|
|
|
// 複数配送設定へリダイレクト |
780
|
|
|
return $app->redirect($app->url('shopping_shipping_multiple')); |
781
|
|
|
} else { |
782
|
|
|
return $app->render('Shopping/index.twig', array( |
783
|
|
|
'form' => $form->createView(), |
784
|
|
|
'Order' => $Order, |
785
|
|
|
)); |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
return $app->redirect($app->url('shopping')); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
|
793
|
|
|
/** |
|
|
|
|
794
|
|
|
* 複数配送処理 |
795
|
|
|
*/ |
|
|
|
|
796
|
|
|
public function shippingMultiple(Application $app, Request $request) |
797
|
|
|
{ |
798
|
|
|
$cartService = $app['eccube.service.cart']; |
799
|
|
|
|
800
|
|
|
// カートチェック |
801
|
|
|
if (!$cartService->isLocked()) { |
802
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
803
|
|
|
return $app->redirect($app->url('cart')); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
// カートチェック |
807
|
|
|
if (count($cartService->getCart()->getCartItems()) <= 0) { |
808
|
|
|
// カートが存在しない時はエラー |
809
|
|
|
return $app->redirect($app->url('cart')); |
810
|
|
|
} |
811
|
|
|
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); |
812
|
|
|
if (!$Order) { |
813
|
|
|
$app->addError('front.shopping.order.error'); |
814
|
|
|
return $app->redirect($app->url('shopping_error')); |
|
|
|
|
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
// 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定 |
818
|
|
|
$compItemQuantities = array(); |
819
|
|
View Code Duplication |
foreach ($Order->getShippings() as $Shipping) { |
|
|
|
|
820
|
|
|
foreach ($Shipping->getShipmentItems() as $ShipmentItem) { |
821
|
|
|
$itemId = $ShipmentItem->getProductClass()->getId(); |
822
|
|
|
$quantity = $ShipmentItem->getQuantity(); |
823
|
|
|
if (array_key_exists($itemId, $compItemQuantities)) { |
824
|
|
|
$compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity; |
825
|
|
|
} else { |
826
|
|
|
$compItemQuantities[$itemId] = $quantity; |
827
|
|
|
} |
828
|
|
|
} |
829
|
|
|
} |
830
|
|
|
|
831
|
|
|
// 商品に紐づく商品情報を取得 |
832
|
|
|
$shipmentItems = array(); |
833
|
|
|
$productClassIds = array(); |
834
|
|
|
foreach ($Order->getShippings() as $Shipping) { |
835
|
|
|
foreach ($Shipping->getShipmentItems() as $ShipmentItem) { |
836
|
|
|
if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) { |
837
|
|
|
$shipmentItems[] = $ShipmentItem; |
838
|
|
|
} |
839
|
|
|
$productClassIds[] = $ShipmentItem->getProductClass()->getId(); |
840
|
|
|
} |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
$form = $app->form()->getForm(); |
844
|
|
|
$form |
845
|
|
|
->add('shipping_multiple', 'collection', array( |
846
|
|
|
'type' => 'shipping_multiple', |
847
|
|
|
'data' => $shipmentItems, |
848
|
|
|
'allow_add' => true, |
849
|
|
|
'allow_delete' => true, |
850
|
|
|
)); |
851
|
|
|
$form->handleRequest($request); |
852
|
|
|
|
853
|
|
|
$errors = array(); |
854
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
855
|
|
|
$data = $form['shipping_multiple']; |
856
|
|
|
|
857
|
|
|
// 数量が超えていないか、同一でないとエラー |
858
|
|
|
$itemQuantities = array(); |
859
|
|
|
foreach ($data as $mulitples) { |
860
|
|
|
/** @var \Eccube\Entity\ShipmentItem $multipleItem */ |
861
|
|
|
$multipleItem = $mulitples->getData(); |
862
|
|
View Code Duplication |
foreach ($mulitples as $items) { |
|
|
|
|
863
|
|
|
foreach ($items as $item) { |
864
|
|
|
$quantity = $item['quantity']->getData(); |
865
|
|
|
$itemId = $multipleItem->getProductClass()->getId(); |
866
|
|
|
if (array_key_exists($itemId, $itemQuantities)) { |
867
|
|
|
$itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity; |
868
|
|
|
} else { |
869
|
|
|
$itemQuantities[$itemId] = $quantity; |
870
|
|
|
} |
871
|
|
|
} |
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
foreach ($compItemQuantities as $key => $value) { |
876
|
|
|
if (array_key_exists($key, $itemQuantities)) { |
877
|
|
|
if ($itemQuantities[$key] != $value) { |
878
|
|
|
$errors[] = array('message' => '数量の数が異なっています。'); |
879
|
|
|
|
880
|
|
|
// 対象がなければエラー |
881
|
|
|
return $app->render('Shopping/shipping_multiple.twig', array( |
882
|
|
|
'form' => $form->createView(), |
883
|
|
|
'shipmentItems' => $shipmentItems, |
884
|
|
|
'compItemQuantities' => $compItemQuantities, |
885
|
|
|
'errors' => $errors, |
886
|
|
|
)); |
887
|
|
|
} |
888
|
|
|
} |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
// お届け先情報をdelete/insert |
892
|
|
|
$shippings = $Order->getShippings(); |
893
|
|
|
foreach ($shippings as $Shipping) { |
894
|
|
|
$Order->removeShipping($Shipping); |
895
|
|
|
$app['orm.em']->remove($Shipping); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
foreach ($data as $mulitples) { |
899
|
|
|
/** @var \Eccube\Entity\ShipmentItem $multipleItem */ |
900
|
|
|
$multipleItem = $mulitples->getData(); |
901
|
|
|
|
902
|
|
|
foreach ($mulitples as $items) { |
903
|
|
|
foreach ($items as $item) { |
904
|
|
|
// 追加された配送先情報を作成 |
905
|
|
|
$Delivery = $multipleItem->getShipping()->getDelivery(); |
906
|
|
|
|
907
|
|
|
// 選択された情報を取得 |
908
|
|
|
$data = $item['customer_address']->getData(); |
909
|
|
|
if ($data instanceof CustomerAddress) { |
|
|
|
|
910
|
|
|
// 会員の場合、CustomerAddressオブジェクトを取得 |
911
|
|
|
$CustomerAddress = $data; |
912
|
|
|
} else { |
913
|
|
|
// 非会員の場合、選択されたindexが取得される |
914
|
|
|
$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); |
915
|
|
|
$customerAddresses = unserialize($customerAddresses); |
916
|
|
|
$CustomerAddress = $customerAddresses[$data]; |
917
|
|
|
$pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId()); |
918
|
|
|
$CustomerAddress->setPref($pref); |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
$Shipping = new Shipping(); |
922
|
|
|
$Shipping |
923
|
|
|
->setFromCustomerAddress($CustomerAddress) |
924
|
|
|
->setDelivery($Delivery) |
925
|
|
|
->setDelFlg(Constant::DISABLED) |
926
|
|
|
->setOrder($Order); |
927
|
|
|
$app['orm.em']->persist($Shipping); |
928
|
|
|
|
929
|
|
|
$ProductClass = $multipleItem->getProductClass(); |
930
|
|
|
$Product = $multipleItem->getProduct(); |
931
|
|
|
$quantity = $item['quantity']->getData(); |
932
|
|
|
|
933
|
|
|
$ShipmentItem = new ShipmentItem(); |
934
|
|
|
$ShipmentItem->setShipping($Shipping) |
935
|
|
|
->setOrder($Order) |
936
|
|
|
->setProductClass($ProductClass) |
937
|
|
|
->setProduct($Product) |
938
|
|
|
->setProductName($Product->getName()) |
939
|
|
|
->setProductCode($ProductClass->getCode()) |
940
|
|
|
->setPrice($ProductClass->getPrice02()) |
941
|
|
|
->setQuantity($quantity); |
942
|
|
|
|
943
|
|
|
$ClassCategory1 = $ProductClass->getClassCategory1(); |
944
|
|
|
if (!is_null($ClassCategory1)) { |
945
|
|
|
$ShipmentItem->setClasscategoryName1($ClassCategory1->getName()); |
946
|
|
|
$ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName()); |
947
|
|
|
} |
948
|
|
|
$ClassCategory2 = $ProductClass->getClassCategory2(); |
949
|
|
|
if (!is_null($ClassCategory2)) { |
950
|
|
|
$ShipmentItem->setClasscategoryName2($ClassCategory2->getName()); |
951
|
|
|
$ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName()); |
952
|
|
|
} |
953
|
|
|
$Shipping->addShipmentItem($ShipmentItem); |
954
|
|
|
$app['orm.em']->persist($ShipmentItem); |
955
|
|
|
|
956
|
|
|
// 配送料金の設定 |
957
|
|
|
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); |
958
|
|
|
} |
959
|
|
|
} |
960
|
|
|
} |
961
|
|
|
// 配送先を更新 |
962
|
|
|
$app['orm.em']->flush(); |
963
|
|
|
|
964
|
|
|
return $app->redirect($app->url('shopping')); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
return $app->render('Shopping/shipping_multiple.twig', array( |
968
|
|
|
'form' => $form->createView(), |
969
|
|
|
'shipmentItems' => $shipmentItems, |
970
|
|
|
'compItemQuantities' => $compItemQuantities, |
971
|
|
|
'errors' => $errors, |
972
|
|
|
)); |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
/** |
|
|
|
|
976
|
|
|
* 非会員用複数配送設定時の新規お届け先の設定 |
977
|
|
|
*/ |
|
|
|
|
978
|
|
|
public function shippingMultipleEdit(Application $app, Request $request) |
979
|
|
|
{ |
980
|
|
|
// カートチェック |
981
|
|
|
if (!$app['eccube.service.cart']->isLocked()) { |
982
|
|
|
// カートが存在しない、カートがロックされていない時はエラー |
983
|
|
|
return $app->redirect($app->url('cart')); |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
// 非会員用Customerを取得 |
987
|
|
|
$Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); |
988
|
|
|
$CustomerAddress = new CustomerAddress(); |
989
|
|
|
$CustomerAddress->setCustomer($Customer); |
990
|
|
|
$Customer->addCustomerAddress($CustomerAddress); |
991
|
|
|
|
992
|
|
|
$form = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress)->getForm(); |
993
|
|
|
$form->handleRequest($request); |
994
|
|
|
|
995
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
996
|
|
|
// 非会員用のセッションに追加 |
997
|
|
|
$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); |
998
|
|
|
$customerAddresses = unserialize($customerAddresses); |
999
|
|
|
$customerAddresses[] = $CustomerAddress; |
1000
|
|
|
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); |
1001
|
|
|
|
1002
|
|
|
return $app->redirect($app->url('shopping_shipping_multiple')); |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
return $app->render('Shopping/shipping_multiple_edit.twig', array( |
1006
|
|
|
'form' => $form->createView(), |
1007
|
|
|
)); |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
/** |
|
|
|
|
1011
|
|
|
* 購入エラー画面表示 |
1012
|
|
|
*/ |
|
|
|
|
1013
|
1 |
|
public function shoppingError(Application $app) |
1014
|
|
|
{ |
1015
|
|
|
return $app->render('Shopping/shopping_error.twig'); |
1016
|
1 |
|
} |
1017
|
|
|
|
1018
|
|
|
/** |
1019
|
|
|
* 非会員でのお客様情報変更時の入力チェック |
1020
|
|
|
*/ |
1021
|
|
|
private function customerValidation($app, $data) |
1022
|
|
|
{ |
1023
|
|
|
// 入力チェック |
1024
|
|
|
$errors = array(); |
1025
|
|
|
|
1026
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name01'], array( |
|
|
|
|
1027
|
|
|
new Assert\NotBlank(), |
1028
|
|
|
new Assert\Length(array('max' => $app['config']['name_len'],)), |
|
|
|
|
1029
|
|
|
new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) |
1030
|
|
|
)); |
1031
|
|
|
|
1032
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_name02'], array( |
|
|
|
|
1033
|
|
|
new Assert\NotBlank(), |
1034
|
|
|
new Assert\Length(array('max' => $app['config']['name_len'], )), |
1035
|
|
|
new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) |
1036
|
|
|
)); |
1037
|
|
|
|
1038
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_company_name'], array( |
1039
|
|
|
new Assert\Length(array('max' => $app['config']['stext_len'])), |
1040
|
|
|
)); |
1041
|
|
|
|
1042
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel01'], array( |
1043
|
|
|
new Assert\NotBlank(), |
1044
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1045
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1046
|
|
|
)); |
1047
|
|
|
|
1048
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel02'], array( |
1049
|
|
|
new Assert\NotBlank(), |
1050
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1051
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1052
|
|
|
)); |
1053
|
|
|
|
1054
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_tel03'], array( |
1055
|
|
|
new Assert\NotBlank(), |
1056
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1057
|
|
|
new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), |
1058
|
|
|
)); |
1059
|
|
|
|
1060
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip01'], array( |
1061
|
|
|
new Assert\NotBlank(), |
1062
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1063
|
|
|
new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])), |
1064
|
|
|
)); |
1065
|
|
|
|
1066
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_zip02'], array( |
1067
|
|
|
new Assert\NotBlank(), |
1068
|
|
|
new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), |
1069
|
|
|
new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])), |
1070
|
|
|
)); |
1071
|
|
|
|
1072
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr01'], array( |
1073
|
|
|
new Assert\NotBlank(), |
1074
|
|
|
new Assert\Length(array('max' => $app['config']['address1_len'])), |
1075
|
|
|
)); |
1076
|
|
|
|
1077
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_addr02'], array( |
1078
|
|
|
new Assert\NotBlank(), |
1079
|
|
|
new Assert\Length(array('max' => $app['config']['address2_len'])), |
1080
|
|
|
)); |
1081
|
|
|
|
1082
|
|
|
$errors[] = $app['validator']->validateValue($data['customer_email'], array( |
1083
|
|
|
new Assert\NotBlank(), |
1084
|
|
|
new Assert\Email(), |
1085
|
|
|
)); |
1086
|
|
|
|
1087
|
|
|
return $errors; |
1088
|
|
|
} |
1089
|
|
|
} |
1090
|
|
|
|