src/Eccube/Controller/AbstractShoppingController.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Eccube\Entity\ItemHolderInterface;
  14. use Eccube\Service\PurchaseFlow\PurchaseContext;
  15. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  16. use Eccube\Service\PurchaseFlow\PurchaseFlowResult;
  17. use Symfony\Component\HttpFoundation\RedirectResponse;
  18. class AbstractShoppingController extends AbstractController
  19. {
  20.     /**
  21.      * @var PurchaseFlow
  22.      */
  23.     protected $purchaseFlow;
  24.     /**
  25.      * @param PurchaseFlow $shoppingPurchaseFlow
  26.      * @required
  27.      */
  28.     public function setPurchaseFlow(PurchaseFlow $shoppingPurchaseFlow)
  29.     {
  30.         $this->purchaseFlow $shoppingPurchaseFlow;
  31.     }
  32.     /**
  33.      * @param ItemHolderInterface $itemHolder
  34.      * @param bool $returnResponse レスポンスを返すかどうか. falseの場合はPurchaseFlowResultを返す.
  35.      *
  36.      * @return PurchaseFlowResult|RedirectResponse|null
  37.      */
  38.     protected function executePurchaseFlow(ItemHolderInterface $itemHolder$returnResponse true)
  39.     {
  40.         /** @var PurchaseFlowResult $flowResult */
  41.         $flowResult $this->purchaseFlow->validate($itemHolder, new PurchaseContext(clone $itemHolder$itemHolder->getCustomer()));
  42.         foreach ($flowResult->getWarning() as $warning) {
  43.             $this->addWarning($warning->getMessage());
  44.         }
  45.         foreach ($flowResult->getErrors() as $error) {
  46.             $this->addError($error->getMessage());
  47.         }
  48.         if (!$returnResponse) {
  49.             return $flowResult;
  50.         }
  51.         if ($flowResult->hasError()) {
  52.             log_info('Errorが発生したため購入エラー画面へ遷移します.', [$flowResult->getErrors()]);
  53.             return $this->redirectToRoute('shopping_error');
  54.         }
  55.         if ($flowResult->hasWarning()) {
  56.             log_info('Warningが発生したため注文手続き画面へ遷移します.', [$flowResult->getWarning()]);
  57.             return $this->redirectToRoute('shopping');
  58.         }
  59.         return null;
  60.     }
  61. }