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