app/Customize/Controller/Mypage/MyPageController.php line 183

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 Customize\Controller\Mypage;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\BaseInfo;
  15. use Eccube\Entity\Customer;
  16. use Eccube\Entity\Order;
  17. use Eccube\Entity\Product;
  18. use Eccube\Event\EccubeEvents;
  19. use Eccube\Event\EventArgs;
  20. use Eccube\Exception\CartException;
  21. use Eccube\Form\Type\Front\CustomerLoginType;
  22. use Eccube\Repository\BaseInfoRepository;
  23. use Eccube\Repository\CustomerFavoriteProductRepository;
  24. use Eccube\Repository\OrderRepository;
  25. use Eccube\Repository\ProductRepository;
  26. use Customize\Repository\SchoolRepository;
  27. use Customize\Repository\DeliveryPeriodRepository;
  28. use Customize\Service\CartService;
  29. use Eccube\Service\PurchaseFlow\PurchaseContext;
  30. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  31. use Knp\Component\Pager\PaginatorInterface;
  32. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  35. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  38. use Customize\Repository\ProductStoreRepository;
  39. use Customize\Repository\OrderItemRepository;
  40. use Eccube\Repository\Master\OrderStatusRepository;
  41. use Eccube\Repository\ProductClassRepository;
  42. use Eccube\Repository\DeliveryFeeRepository;
  43. use Eccube\Repository\Master\CustomerOrderStatusRepository;
  44. class MyPageController extends AbstractController
  45. {
  46.     /**
  47.      * @var ProductRepository
  48.      */
  49.     protected $productRepository;
  50.     /**
  51.      * @var CustomerFavoriteProductRepository
  52.      */
  53.     protected $customerFavoriteProductRepository;
  54.     /**
  55.      * @var BaseInfo
  56.      */
  57.     protected $BaseInfo;
  58.     /**
  59.      * @var CartService
  60.      */
  61.     protected $cartService;
  62.     /**
  63.      * @var OrderRepository
  64.      */
  65.     protected $orderRepository;
  66.     /**
  67.      * @var SchoolRepository
  68.      */
  69.     protected $schoolRepository;
  70.     /**
  71.      * @var DeliveryPeriodRepository
  72.      */
  73.     protected $deliveryPeriodRepository;
  74.     /**
  75.      * @var PurchaseFlow
  76.      */
  77.     protected $purchaseFlow;
  78.     /**
  79.      * @var productStoreRepository
  80.      */
  81.     protected $productStoreRepository;
  82.     /**
  83.      * @var orderStatusRepository
  84.      */
  85.     protected $orderStatusRepository;
  86.     /**
  87.      * @var customerOrderStatusRepository
  88.      */
  89.     protected $customerOrderStatusRepository;
  90.     /**
  91.      * @var ProductClassRepository
  92.      */
  93.     protected $productClassRepository;
  94.     /**
  95.      * @var OrderItemRepository
  96.      */
  97.     protected $orderItemRepository;
  98.     /**
  99.      * @var DeliveryFeeRepository
  100.      */
  101.     protected $deliveryFeeRepository;
  102.     /**
  103.      * MypageController constructor.
  104.      *
  105.      * @param OrderRepository $orderRepository
  106.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  107.      * @param CartService $cartService
  108.      * @param BaseInfoRepository $baseInfoRepository
  109.      * @param PurchaseFlow $purchaseFlow
  110.      * @param SchoolRepository $schoolRepository
  111.      * @param DeliveryPeriodRepository $deliveryPeriodRepository
  112.      * @param ProductStoreRepository $productStoreRepository
  113.      * @param OrderStatusRepository $orderStatusRepository
  114.      */
  115.     public function __construct(
  116.         OrderRepository $orderRepository,
  117.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  118.         CartService $cartService,
  119.         BaseInfoRepository $baseInfoRepository,
  120.         PurchaseFlow $purchaseFlow,
  121.         SchoolRepository $schoolRepository,
  122.         DeliveryPeriodRepository $deliveryPeriodRepository,
  123.         ProductStoreRepository $productStoreRepository,
  124.         OrderStatusRepository $orderStatusRepository,
  125.         CustomerOrderStatusRepository $customerOrderStatusRepository,
  126.         ProductRepository $productRepository,
  127.         ProductClassRepository $productClassRepository,
  128.         OrderItemRepository $orderItemRepository,
  129.         DeliveryFeeRepository $deliveryFeeRepository
  130.     ) {
  131.         $this->orderRepository $orderRepository;
  132.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  133.         $this->BaseInfo $baseInfoRepository->get();
  134.         $this->cartService $cartService;
  135.         $this->purchaseFlow $purchaseFlow;
  136.         $this->schoolRepository $schoolRepository;
  137.         $this->deliveryPeriodRepository $deliveryPeriodRepository;
  138.         $this->productStoreRepository $productStoreRepository;
  139.         $this->orderStatusRepository $orderStatusRepository;
  140.         $this->productRepository $productRepository;
  141.         $this->productClassRepository $productClassRepository;
  142.         $this->orderItemRepository $orderItemRepository;
  143.         $this->deliveryFeeRepository $deliveryFeeRepository;
  144.         $this->customerOrderStatusRepository $customerOrderStatusRepository;
  145.     }
  146.     /**
  147.      * ログイン画面.
  148.      *
  149.      * @Route("/mypage/login", name="mypage_login", methods={"GET", "POST"})
  150.      * @Template("Mypage/login.twig")
  151.      */
  152.     public function login(Request $requestAuthenticationUtils $utils)
  153.     {
  154.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  155.             log_info('認証済のためログイン処理をスキップ');
  156.             return $this->redirectToRoute('mypage');
  157.         }
  158.         /* @var $form \Symfony\Component\Form\FormInterface */
  159.         $builder $this->formFactory
  160.             ->createNamedBuilder(''CustomerLoginType::class);
  161.         $builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
  162.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  163.             $Customer $this->getUser();
  164.             if ($Customer instanceof Customer) {
  165.                 $builder->get('login_email')
  166.                     ->setData($Customer->getEmail());
  167.             }
  168.         }
  169.         $event = new EventArgs(
  170.             [
  171.                 'builder' => $builder,
  172.             ],
  173.             $request
  174.         );
  175.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE);
  176.         $form $builder->getForm();
  177.         return [
  178.             'error' => $utils->getLastAuthenticationError(),
  179.             'form' => $form->createView(),
  180.             'store_id' => $request->get('store_id'null),
  181.             'school_id' => $request->get('school_id'null)
  182.         ];
  183.     }
  184.     /**
  185.      * マイページ.
  186.      *
  187.      * @Route("/mypage/", name="mypage", methods={"GET"})
  188.      * @Template("Mypage/index.twig")
  189.      */
  190.     public function index(Request $requestPaginatorInterface $paginator)
  191.     {
  192.         $Customer $this->getUser();
  193.         // 購入処理中/決済処理中ステータスの受注を非表示にする.
  194.         $this->entityManager
  195.             ->getFilters()
  196.             ->enable('incomplete_order_status_hidden');
  197.         // paginator
  198.         $qb $this->orderRepository->getQueryBuilderByCustomer($Customer);
  199.         $event = new EventArgs(
  200.             [
  201.                 'qb' => $qb,
  202.                 'Customer' => $Customer,
  203.             ],
  204.             $request
  205.         );
  206.         // $this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH);
  207.         $pagination $paginator->paginate(
  208.             $qb,
  209.             $request->get('pageno'1),
  210.             $this->eccubeConfig['eccube_search_pmax']
  211.         );
  212.         return [
  213.             'pagination' => $pagination,
  214.             'order_temporary' => $this->eccubeConfig['order_temporary']
  215.         ];
  216.     }
  217.     /**
  218.      * 購入履歴詳細を表示する.
  219.      *
  220.      * @Route("/mypage/history/{order_no}", name="mypage_history", methods={"GET"})
  221.      * @Template("Mypage/history.twig")
  222.      */
  223.     public function history(Request $request$order_no)
  224.     {
  225.         if (!$this->session->get('is_from_history'false)) {
  226.             $this->entityManager->getFilters()
  227.                 ->enable('incomplete_order_status_hidden');
  228.         }
  229.         $this->session->set('is_temporary_order'false);
  230.         $this->session->set('temporary_order_id'null);
  231.         $Order $this->orderRepository->findOneBy(
  232.             [
  233.                 'id' => $order_no,
  234.                 'Customer' => $this->getUser(),
  235.             ]
  236.         );
  237.         $event = new EventArgs(
  238.             [
  239.                 'Order' => $Order,
  240.             ],
  241.             $request
  242.         );
  243.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE);
  244.         /** @var Order $Order */
  245.         $Order $event->getArgument('Order');
  246.         if (!$Order) {
  247.             throw new NotFoundHttpException();
  248.         }
  249.         if ($this->session->get('is_from_history'false)) {
  250.             $OrderStatus $this->orderStatusRepository->find($this->eccubeConfig['order_temporary']);
  251.             $Order->setOrderStatus($OrderStatus);
  252.             $Order->setCustomerOrderStatus($this->customerOrderStatusRepository->find($this->eccubeConfig['order_temporary']));
  253.             $this->entityManager->persist($Order);
  254.             $this->entityManager->flush($Order);
  255.             foreach ($Order->getOrderItems() as $OrderDetail) {
  256.                 try {
  257.                     if ($OrderDetail->getProduct() &&
  258.                         $OrderDetail->getProductClass()) {
  259.                         for ($i 0$i $OrderDetail->getQuantity(); $i++) {
  260.                             $this->cartService->removeProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getSetProductClass());
  261.                         }
  262.                         $Carts $this->cartService->getCarts();
  263.                         $this->execPurchaseFlow($Carts);
  264.                     }
  265.                 } catch (CartException $e) {
  266.                     log_info($e->getMessage());
  267.                     $this->addRequestError($e->getMessage());
  268.                 }
  269.             }
  270.         }
  271.         $DeliveryPeriodIdArr = [];
  272.         foreach ($Order['OrderItems'] as $OrderDetail) {
  273.             if($OrderDetail->getDeliveryPeriod())
  274.                 $DeliveryPeriodIdArr[] = $OrderDetail->getDeliveryPeriod()->getDeliveryPeriodId();
  275.         }
  276.         $DeliveryPeriodIdArr array_unique($DeliveryPeriodIdArr);
  277.         // 手数料取得
  278.         $charge $Order->getCharge();
  279.         $shippings $Order->getShippings();
  280.         /** @var DeliveryFee|null $DeliveryFee */
  281.         $DeliveryFee $this->deliveryFeeRepository->findOneBy([
  282.             'Delivery' => $shippings[0]->getDelivery(),
  283.             'Pref' => $shippings[0]->getPref(),
  284.         ]);
  285.         $shipping is_object($DeliveryFee) ? $DeliveryFee->getFee() : 0;
  286.         $deliveryPriceTotal 0;
  287.         $deliveryAmountTotal 0;
  288.         $deliveryPriceTotalPer 0;
  289.         $deliveryAmountTotalPer 0;
  290.         $school $this->getUser()->getSchool();
  291.         $perDeliveryPeriodPrice = [];
  292.         foreach ($DeliveryPeriodIdArr as $DeliveryPeriodId) {
  293.             foreach($Order['OrderItems'] as $OrderDetail){
  294.                 if($OrderDetail->getDeliveryPeriod() && $OrderDetail->getDeliveryPeriod()->getDeliveryPeriodId() ===  $DeliveryPeriodId){
  295.                     $deliveryPriceTotal += $OrderDetail->getPrice() * $OrderDetail->getQuantity();
  296.                     $deliveryAmountTotal += $OrderDetail->getQuantity();
  297.                     $deliveryPriceTotalPer += $OrderDetail->getPrice() * $OrderDetail->getQuantity();
  298.                     $deliveryAmountTotalPer += $OrderDetail->getQuantity();
  299.                 }
  300.             }
  301.             $DeliveryPeriod $this->deliveryPeriodRepository->find($DeliveryPeriodId);
  302.             if($school['delivery_free_type'] === 2){
  303.                 $DeliveryPeriod $this->deliveryPeriodRepository->find($DeliveryPeriodId);
  304.                 if($DeliveryPeriod['delivery_free_amount'] <= $deliveryPriceTotalPer || $DeliveryPeriod['delivery_free_quantity'] <= $deliveryAmountTotalPer){
  305.                     $perDeliveryPeriodPrice[] = array(
  306.                         'delivery_period_id' => $DeliveryPeriod['delivery_period_id'],
  307.                         'product_label_name' => $DeliveryPeriod['product_label_name'],
  308.                         'delivery_label_name' => $DeliveryPeriod['delivery_label_name'],
  309.                         'totalPrice' => intval($deliveryPriceTotalPer),
  310.                         'deliveryFeeTotal' => intval($charge),
  311.                         'sum_label_name' => $DeliveryPeriod['sum_label_name'],
  312.                     );
  313.                 }else {
  314.                     $perDeliveryPeriodPrice[] = array(
  315.                         'delivery_period_id' => $DeliveryPeriod['delivery_period_id'],
  316.                         'product_label_name' => $DeliveryPeriod['product_label_name'],
  317.                         'delivery_label_name' => $DeliveryPeriod['delivery_label_name'],
  318.                         'totalPrice' => intval($deliveryPriceTotalPer),
  319.                         'deliveryFeeTotal' =>  intval($shipping $charge),
  320.                         'sum_label_name' => $DeliveryPeriod['sum_label_name'],
  321.                     );
  322.                 }
  323.             } else if($school['delivery_free_type'] === 1) {
  324.                 // 配送無料条件が決済ごと
  325.                 if($school['delivery_free_amount'] <= $deliveryPriceTotal || $school['delivery_free_quantity'] <= $deliveryAmountTotal){
  326.                     $perDeliveryPeriodPrice[] = array(
  327.                         'delivery_period_id' => $DeliveryPeriod['delivery_period_id'],
  328.                         'product_label_name' => $DeliveryPeriod['product_label_name'],
  329.                         'delivery_label_name' => $DeliveryPeriod['delivery_label_name'],
  330.                         'totalPrice' => intval($deliveryPriceTotalPer),
  331.                         intval($charge),
  332.                         'sum_label_name' => $DeliveryPeriod['sum_label_name'],
  333.                     );
  334.                 } else {
  335.                     $perDeliveryPeriodPrice[] = array(
  336.                         'delivery_period_id' => $DeliveryPeriod['delivery_period_id'],
  337.                         'product_label_name' => $DeliveryPeriod['product_label_name'],
  338.                         'delivery_label_name' => $DeliveryPeriod['delivery_label_name'],
  339.                         'totalPrice' => intval($deliveryPriceTotalPer),
  340.                         'deliveryFeeTotal' =>  intval($shipping $charge),
  341.                         'sum_label_name' => $DeliveryPeriod['sum_label_name'],
  342.                     );
  343.                 }
  344.             } else {
  345.                 $perDeliveryPeriodPrice[] = array(
  346.                     'delivery_period_id' => $DeliveryPeriod['delivery_period_id'],
  347.                     'product_label_name' => $DeliveryPeriod['product_label_name'],
  348.                     'delivery_label_name' => $DeliveryPeriod['delivery_label_name'],
  349.                     'totalPrice' => intval($deliveryPriceTotalPer),
  350.                     'deliveryFeeTotal' =>  intval($shipping $charge),
  351.                     'sum_label_name' => $DeliveryPeriod['sum_label_name'],
  352.                 );
  353.             }
  354.             $deliveryPriceTotalPer 0;
  355.             $deliveryAmountTotalPer 0;
  356.         }
  357.         $delivery_period $this->deliveryPeriodRepository->findAll();
  358.         $sort = array();
  359.         foreach ((array) $perDeliveryPeriodPrice as $key => $value) {
  360.             $sort[$key] = $value['delivery_period_id'];
  361.         }
  362.         array_multisort($sortSORT_ASC$perDeliveryPeriodPrice);
  363.         // $stockOrder = true;
  364.         // foreach ($Order->getOrderItems() as $orderItem) {
  365.         //     if ($orderItem->isProduct() && $orderItem->getQuantity() < 0) {
  366.         //         $stockOrder = false;
  367.         //         break;
  368.         //     }
  369.         // }
  370.         $order_items $Order->getOrderItems();
  371.         $setProductClassArr = [];
  372.         foreach ($order_items as $OrderDetail) {
  373.             if($OrderDetail->getDeliveryPeriod())
  374.                 $DeliveryPeriodIdArr[] = $OrderDetail->getDeliveryPeriod()->getDeliveryPeriodId();
  375.             if(!empty($OrderDetail->getSetProductClass()))
  376.             {
  377.                 $setProductClassArr[$OrderDetail->getId()] = $this->orderItemRepository->getSetProductClass($OrderDetail);
  378.             }
  379.         }
  380.         return [
  381.             'Order' => $Order,
  382.             // 'stockOrder' => $stockOrder,
  383.             'order_temporary' => $this->eccubeConfig['order_temporary'],
  384.             'delivery_period' => $delivery_period,
  385.             'perDeliveryPeriodPrice' => $perDeliveryPeriodPrice,
  386.             'OrderSetProductClass' => $setProductClassArr
  387.         ];
  388.     }
  389.     /**
  390.      * 再購入を行う.
  391.      *
  392.      * @Route("/mypage/order/{order_no}", name="mypage_order", methods={"PUT"})
  393.      */
  394.     public function order(Request $request$order_no)
  395.     {
  396.         $this->isTokenValid();
  397.         log_info('再注文開始', [$order_no]);
  398.         $Customer $this->getUser();
  399.         /* @var $Order \Eccube\Entity\Order */
  400.         $Order $this->orderRepository->findOneBy(
  401.             [
  402.                 'id' => $order_no,
  403.                 'Customer' => $Customer,
  404.             ]
  405.         );
  406.         // /* @var $Order \Eccube\Entity\Order */
  407.         // $Order = $this->orderRepository->findOneBy(
  408.         //     [
  409.         //         'order_no' => $order_no,
  410.         //         'Customer' => $Customer,
  411.         //     ]
  412.         // );
  413.         $event = new EventArgs(
  414.             [
  415.                 'Order' => $Order,
  416.                 'Customer' => $Customer,
  417.             ],
  418.             $request
  419.         );
  420.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_INITIALIZE);
  421.         if (!$Order) {
  422.             log_info('対象の注文が見つかりません', [$order_no]);
  423.             throw new NotFoundHttpException();
  424.         }
  425.         // エラーメッセージの配列
  426.         $errorMessages = [];
  427.         foreach ($Order->getOrderItems() as $OrderItem) {
  428.             try {
  429.                 if ($OrderItem->getProduct() && $OrderItem->getProductClass()) {
  430.                     $this->cartService->addProduct($OrderItem->getProductClass(), $OrderItem->getQuantity(), $OrderItem->getSetProductClass(), null$OrderItem->getBrother());
  431.                     // 明細の正規化
  432.                     $Carts $this->cartService->getCarts();
  433.                     foreach ($Carts as $Cart) {
  434.                         $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  435.                         // 復旧不可のエラーが発生した場合は追加した明細を削除.
  436.                         if ($result->hasError()) {
  437.                             $this->cartService->removeProduct($OrderItem->getProductClass());
  438.                             foreach ($result->getErrors() as $error) {
  439.                                 $errorMessages[] = $error->getMessage();
  440.                             }
  441.                         }
  442.                         foreach ($result->getWarning() as $warning) {
  443.                             $errorMessages[] = $warning->getMessage();
  444.                         }
  445.                     }
  446.                     $this->cartService->save();
  447.                 }
  448.             } catch (CartException $e) {
  449.                 log_info($e->getMessage(), [$order_no]);
  450.                 $this->addRequestError($e->getMessage());
  451.             }
  452.         }
  453.         foreach ($errorMessages as $errorMessage) {
  454.             $this->addRequestError($errorMessage);
  455.         }
  456.         $event = new EventArgs(
  457.             [
  458.                 'Order' => $Order,
  459.                 'Customer' => $Customer,
  460.             ],
  461.             $request
  462.         );
  463.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_COMPLETE);
  464.         if ($event->getResponse() !== null) {
  465.             return $event->getResponse();
  466.         }
  467.         log_info('再注文完了', [$order_no]);
  468.         if($request->get('temporary')){
  469.             $Order $this->orderRepository->find($order_no);
  470.             $OrderStatus $this->orderStatusRepository->find($this->eccubeConfig['order_processing']);
  471.             $Order->setOrderStatus($OrderStatus);
  472.             $this->entityManager->persist($Order);
  473.             $this->entityManager->flush($Order);
  474.         }
  475.         return $this->redirect($this->generateUrl('cart'));
  476.     }
  477.     /**
  478.     * @param $Carts
  479.     *
  480.     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  481.     */
  482.     protected function execPurchaseFlow($Carts)
  483.     {
  484.         /** @var PurchaseFlowResult[] $flowResults */
  485.         $flowResults array_map(function ($Cart) {
  486.             $purchaseContext = new PurchaseContext($Cart$this->getUser());
  487.             return $this->purchaseFlow->validate($Cart$purchaseContext);
  488.         }, $Carts);
  489.         // 復旧不可のエラーが発生した場合はカートをクリアして再描画
  490.         $hasError false;
  491.         foreach ($flowResults as $result) {
  492.             if ($result->hasError()) {
  493.                 $hasError true;
  494.                 foreach ($result->getErrors() as $error) {
  495.                     $this->addRequestError($error->getMessage());
  496.                 }
  497.             }
  498.         }
  499.         if ($hasError) {
  500.             $this->cartService->clear();
  501.             return $this->redirectToRoute('cart');
  502.         }
  503.         $this->cartService->save();
  504.         foreach ($flowResults as $index => $result) {
  505.             foreach ($result->getWarning() as $warning) {
  506.                 if ($Carts[$index]->getItems()->count() > 0) {
  507.                     $cart_key $Carts[$index]->getCartKey();
  508.                     $this->addRequestError($warning->getMessage(), "front.cart.${cart_key}");
  509.                 } else {
  510.                     // キーが存在しない場合はグローバルにエラーを表示する
  511.                     $this->addRequestError($warning->getMessage());
  512.                 }
  513.             }
  514.         }
  515.         return null;
  516.     }
  517.     /**
  518.      * お気に入り商品を表示する.
  519.      *
  520.      * @Route("/mypage/favorite", name="mypage_favorite", methods={"GET"})
  521.      * @Template("Mypage/favorite.twig")
  522.      */
  523.     public function favorite(Request $requestPaginatorInterface $paginator)
  524.     {
  525.         if (!$this->BaseInfo->isOptionFavoriteProduct()) {
  526.             throw new NotFoundHttpException();
  527.         }
  528.         $Customer $this->getUser();
  529.         // paginator
  530.         $qb $this->customerFavoriteProductRepository->getQueryBuilderByCustomer($Customer);
  531.         $event = new EventArgs(
  532.             [
  533.                 'qb' => $qb,
  534.                 'Customer' => $Customer,
  535.             ],
  536.             $request
  537.         );
  538.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_FAVORITE_SEARCH);
  539.         $pagination $paginator->paginate(
  540.             $qb,
  541.             $request->get('pageno'1),
  542.             $this->eccubeConfig['eccube_search_pmax'],
  543.             ['wrap-queries' => true]
  544.         );
  545.         return [
  546.             'pagination' => $pagination,
  547.         ];
  548.     }
  549.     /**
  550.      * お気に入り商品を削除する.
  551.      *
  552.      * @Route("/mypage/favorite/{id}/delete", name="mypage_favorite_delete", methods={"DELETE"}, requirements={"id" = "\d+"})
  553.      */
  554.     public function delete(Request $requestProduct $Product)
  555.     {
  556.         $this->isTokenValid();
  557.         $Customer $this->getUser();
  558.         log_info('お気に入り商品削除開始', [$Customer->getId(), $Product->getId()]);
  559.         $CustomerFavoriteProduct $this->customerFavoriteProductRepository->findOneBy(['Customer' => $Customer'Product' => $Product]);
  560.         if ($CustomerFavoriteProduct) {
  561.             $this->customerFavoriteProductRepository->delete($CustomerFavoriteProduct);
  562.         } else {
  563.             throw new BadRequestHttpException();
  564.         }
  565.         $event = new EventArgs(
  566.             [
  567.                 'Customer' => $Customer,
  568.                 'CustomerFavoriteProduct' => $CustomerFavoriteProduct,
  569.             ], $request
  570.         );
  571.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_DELETE_COMPLETE);
  572.         log_info('お気に入り商品削除完了', [$Customer->getId(), $CustomerFavoriteProduct->getId()]);
  573.         return $this->redirect($this->generateUrl('mypage_favorite'));
  574.     }
  575.     /**
  576.      * 仮注文→購入手続きを進める
  577.      *
  578.      * @Route("/mypage/temporary_order/{id}", name="mypage_order_temporary", methods={"POST"}, requirements={"id" = "\d+"})
  579.      */
  580.     public function orderTemporary(Request $request$id)
  581.     {
  582.         $Customer $this->getUser();
  583.         $schoolId $Customer->getSchool()->getSchoolId();
  584.         $temporaryOrder false;
  585.         if($schoolId !== null){
  586.             $school $this->schoolRepository->find($schoolId);
  587.             $this->session->set('storeMeasuringFlag'$school->getStoreMeasuringFlag());
  588.             $this->session->set('schoolMeasuringFlag'$school->getSchoolMeasuringFlag());
  589.             $this->session->set('onlineFlag'$school->getOnlineFlag());
  590.             if($school->getOnlineFlag() == 0){
  591.                 $temporaryOrder true;
  592.             }
  593.             else{
  594.                 $temporaryOrder false;
  595.             }
  596.         }
  597.         $this->session->set('is_temporary_order'$temporaryOrder);
  598.         $this->isTokenValid();
  599.         log_info('購入手続きを進める開始', array($id));
  600.         $Customer $this->getUser();
  601.         /* @var $Order \Eccube\Entity\Order */
  602.         $Order $this->orderRepository->findOneBy(array(
  603.             'id' => $id,
  604.             'Customer' => $Customer,
  605.         ));
  606.         $event = new EventArgs(
  607.             array(
  608.                 'Order' => $Order,
  609.                 'Customer' => $Customer,
  610.             ),
  611.             $request
  612.         );
  613.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_INITIALIZE);
  614.         if (!$Order) {
  615.             log_info('対象の注文が見つかりません', array($id));
  616.             throw new NotFoundHttpException();
  617.         }
  618.         $productId 0;
  619.         $is_product_deleted false;
  620.         foreach ($Order->getOrderItems() as $OrderDetail) {
  621.             try {
  622.                 if ($OrderDetail->isProduct()) {
  623.                     if ($OrderDetail->getProduct() && $OrderDetail->getProductClass()) {
  624.                         $productId $OrderDetail->getProduct()->getId();
  625.                         $this->cartService->addProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getQuantity(), $OrderDetail->getSetProductClass());
  626.                         $Carts $this->cartService->getCarts();
  627.                         /** @var PurchaseFlowResult[] $flowResults */
  628.                         $flowResults array_map(function ($Cart) {
  629.                             $purchaseContext = new PurchaseContext($Cart$this->getUser());
  630.                             return $this->purchaseFlow->validate($Cart$purchaseContext);
  631.                         }, $Carts);
  632.                         $this->cartService->save();
  633.                     }
  634.                     else {
  635.                         if(!$is_product_deleted)
  636.                             $this->addRequestError('cart.product.delete');
  637.                         $is_product_deleted true;
  638.                     }
  639.                 }
  640.             } catch (CartException $e) {
  641.                 log_info($e->getMessage(), array($id));
  642.                 $this->addRequestError($e->getMessage());
  643.             }
  644.         }
  645.         $event = new EventArgs(
  646.             array(
  647.                 'Order' => $Order,
  648.                 'Customer' => $Customer,
  649.             ),
  650.             $request
  651.         );
  652.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_ORDER_COMPLETE);
  653.         if ($event->getResponse() !== null) {
  654.             return $event->getResponse();
  655.         }
  656.         log_info('購入手続きを進める', array($id));
  657.         // FRONT_CART_BUYSTEP_INITIALIZE
  658.         $event = new EventArgs(
  659.             array(),
  660.             $request
  661.         );
  662.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CART_BUYSTEP_INITIALIZE);
  663.         $this->cartService->save();
  664.         // FRONT_CART_BUYSTEP_COMPLETE
  665.         $event = new EventArgs(
  666.             array(),
  667.             $request
  668.         );
  669.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CART_BUYSTEP_COMPLETE);
  670.         //「対応状況」を「新規受付」にする (本注文状態にする)
  671.         // $OrderStatus = $this->orderStatusRepository->find($this->eccubeConfig['order_processing']);
  672.         // $OrderData = $this->orderRepository->find($Order->getId());
  673.         // $OrderData->setOrderStatus($OrderStatus);
  674.         // $this->entityManager->persist($OrderData);
  675.         // $this->entityManager->flush($OrderData);
  676.         $this->session->set('temporary_order_id'$id);
  677.         //product_type_idを取得する
  678.         if($productId 0){
  679.             $productStore $this->productStoreRepository->findOneBy(array(
  680.                 'Product' => $this->productRepository->findOneBy(['id'=>$productId])
  681.             ));
  682.             if($productStore)
  683.                 $this->session->set('store_id_order',$productStore->getStore()->getStoreId());
  684.         }
  685.         $this->session->set('is_from_history'true);
  686.         if($temporaryOrder) {
  687.             return $this->redirectToRoute('shopping_temporary');
  688.         }
  689.         else {
  690.             return $this->redirectToRoute('shopping');
  691.         }
  692.     }
  693. }