<?php
namespace Eccube\Controller;
use Customize\Entity\Floor;
use Customize\Service\FloorDistributionService;
use Eccube\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
class FloorController extends AbstractController
{
/** @var RouterInterface */
protected $router;
/** @var FloorDistributionService */
protected $floorDistributionService;
/** @var Security */
protected $security;
public function __construct(
RouterInterface $router,
FloorDistributionService $floorDistributionService,
Security $security
) {
$this->router = $router;
$this->floorDistributionService = $floorDistributionService;
$this->security = $security;
}
/**
* @Route("/yazawa-meat/", name="yazawa_meat")
* @Route("/yazawa-meat/{route}", name="yazawa_meat_included_route", requirements={"route"=".+"})
* @Route("/valuet-sweets/", name="valuet_sweets")
* @Route("/valuet-sweets/{route}", name="valuet_sweets_included_route", requirements={"route"=".+"})
* @Route("/drogheria-sancricca/", name="drogheria_sancricca")
* @Route("/drogheria-sancricca/{route}", name="drogheria_sancricca_included_route", requirements={"route"=".+"})
* @Route("/special/", name="special")
* @Route("/special/{route}", name="special_included_route", requirements={"route"=".+"})
*/
public function index(Request $request, $route = null)
{
if ($this->floorDistributionService->getSubdomain() !== Floor::NAME_DEPARTMENT) {
throw new NotFoundHttpException();
}
$matched = $this->router->match('/' . $route);
if (!$this->floorDistributionService->checkIncludedRouteNameAddingRoutes($matched['_route'])) {
throw new NotFoundHttpException();
}
$pathParams = $matched;
$pathParams['_route_params'] = $matched;
unset($pathParams['_route_params']['_route']);
unset($pathParams['_route_params']['_controller']);
try {
$pathParams['_route_floor'] = $this->floorDistributionService->getFloorTemplateCodeFromPath() ?? Floor::NAME_DEPARTMENT;
$request->attributes->set('_route_floor', $pathParams['_route_floor']);
// ログイン中(会員)、会員情報のvisited_shopsに当フロア名の登録がなければ登録
$currentFloor = $pathParams['_route_floor'];
$Customer = $this->security->getUser();
if ($currentFloor && $Customer instanceof \Eccube\Entity\Customer) {
$visitedShops = $Customer->getVisitedShops();
if (!in_array($currentFloor, $visitedShops)) {
$Customer->setVisitedShops($currentFloor);
$this->entityManager->persist($Customer);
$this->entityManager->flush();
}
}
} catch (\Exception $e) {
log_error('会員情報に訪れたフロアを登録する処理でエラー: ' . $e->getMessage());
}
return $this->forwardToRoute($matched['_route'], $pathParams, $request->query->all());
}
}