Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ShoppingController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ShoppingController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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) |
|
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) |
|
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) |
||
661 | |||
662 | /** |
||
663 | * ログイン |
||
664 | */ |
||
665 | 2 | public function login(Application $app, Request $request) |
|
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) |
||
977 | |||
978 | /** |
||
979 | * 非会員用複数配送設定時の新規お届け先の設定 |
||
980 | */ |
||
981 | public function shippingMultipleEdit(Application $app, Request $request) |
||
1012 | |||
1013 | /** |
||
1014 | * 購入エラー画面表示 |
||
1015 | */ |
||
1016 | 1 | public function shoppingError(Application $app) |
|
1020 | |||
1021 | /** |
||
1022 | * 非会員でのお客様情報変更時の入力チェック |
||
1023 | */ |
||
1024 | private function customerValidation($app, $data) |
||
1092 | } |
||
1093 |