src/Eccube/Controller/FloorController.php line 45

Open in your IDE?
  1. <?php
  2. namespace Eccube\Controller;
  3. use Customize\Entity\Floor;
  4. use Customize\Service\FloorDistributionService;
  5. use Eccube\Controller\AbstractController;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. use Symfony\Component\Routing\RouterInterface;
  10. use Symfony\Component\Security\Core\Security;
  11. class FloorController extends AbstractController
  12. {
  13.     /** @var RouterInterface */
  14.     protected $router;
  15.     /** @var FloorDistributionService */
  16.     protected $floorDistributionService;
  17.     /** @var Security */
  18.     protected $security;
  19.     public function __construct(
  20.         RouterInterface $router,
  21.         FloorDistributionService $floorDistributionService,
  22.         Security $security
  23.     ) {
  24.         $this->router $router;
  25.         $this->floorDistributionService $floorDistributionService;
  26.         $this->security $security;
  27.     }
  28.     /**
  29.      * @Route("/yazawa-meat/", name="yazawa_meat")
  30.      * @Route("/yazawa-meat/{route}", name="yazawa_meat_included_route", requirements={"route"=".+"})
  31.      * @Route("/valuet-sweets/", name="valuet_sweets")
  32.      * @Route("/valuet-sweets/{route}", name="valuet_sweets_included_route", requirements={"route"=".+"})
  33.      * @Route("/drogheria-sancricca/", name="drogheria_sancricca")
  34.      * @Route("/drogheria-sancricca/{route}", name="drogheria_sancricca_included_route", requirements={"route"=".+"})
  35.      * @Route("/special/", name="special")
  36.      * @Route("/special/{route}", name="special_included_route", requirements={"route"=".+"})
  37.      */
  38.     public function index(Request $request$route null)
  39.     {
  40.         if ($this->floorDistributionService->getSubdomain() !== Floor::NAME_DEPARTMENT) {
  41.             throw new NotFoundHttpException();
  42.         }
  43.         $matched $this->router->match('/' $route);
  44.         if (!$this->floorDistributionService->checkIncludedRouteNameAddingRoutes($matched['_route'])) {
  45.             throw new NotFoundHttpException();
  46.         }
  47.         $pathParams $matched;
  48.         $pathParams['_route_params'] = $matched;
  49.         unset($pathParams['_route_params']['_route']);
  50.         unset($pathParams['_route_params']['_controller']);
  51.         try {
  52.             $pathParams['_route_floor'] = $this->floorDistributionService->getFloorTemplateCodeFromPath() ?? Floor::NAME_DEPARTMENT;
  53.             $request->attributes->set('_route_floor'$pathParams['_route_floor']);
  54.             // ログイン中(会員)、会員情報のvisited_shopsに当フロア名の登録がなければ登録
  55.             $currentFloor $pathParams['_route_floor'];
  56.             $Customer $this->security->getUser();
  57.             if ($currentFloor && $Customer instanceof \Eccube\Entity\Customer) {
  58.                 $visitedShops $Customer->getVisitedShops();
  59.                 if (!in_array($currentFloor$visitedShops)) {
  60.                     $Customer->setVisitedShops($currentFloor);
  61.                     $this->entityManager->persist($Customer);
  62.                     $this->entityManager->flush();
  63.                 }
  64.             }
  65.         } catch (\Exception $e) {
  66.             log_error('会員情報に訪れたフロアを登録する処理でエラー: ' $e->getMessage());
  67.         }
  68.         return $this->forwardToRoute($matched['_route'], $pathParams$request->query->all());
  69.     }
  70. }