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