custom/plugins/NetiNextStoreLocator/src/Storefront/Controller/StoreLocatorController.php line 53

Open in your IDE?
  1. <?php
  2. namespace NetInventors\NetiNextStoreLocator\Storefront\Controller;
  3. use NetInventors\NetiNextStoreLocator\Storefront\Page\Store\Detail\StoreDetailPageLoader;
  4. use NetInventors\NetiNextStoreLocator\Storefront\Page\Store\Listing\StoreListingPageLoader;
  5. use NetInventors\NetiNextStoreLocator\Storefront\Route\ContactRoute;
  6. use NetInventors\NetiNextStoreLocator\Storefront\Route\GetStoresRoute;
  7. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Shopware\Core\System\SystemConfig\SystemConfigService;
  10. use Shopware\Storefront\Controller\StorefrontController;
  11. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. /**
  19.  * @RouteScope(scopes={"storefront"})
  20.  */
  21. class StoreLocatorController extends StorefrontController
  22. {
  23.     private StoreDetailPageLoader  $storeDetailPageLoader;
  24.     private StoreListingPageLoader $storeListingPageLoader;
  25.     private SystemConfigService    $systemConfig;
  26.     private ContactRoute           $contactRoute;
  27.     private GetStoresRoute         $getStoresRoute;
  28.     public function __construct(
  29.         StoreDetailPageLoader  $storeDetailPageLoader,
  30.         StoreListingPageLoader $storeListingPageLoader,
  31.         SystemConfigService    $systemConfig,
  32.         ContactRoute           $contactRoute,
  33.         GetStoresRoute         $getStoresRoute
  34.     ) {
  35.         $this->storeDetailPageLoader  $storeDetailPageLoader;
  36.         $this->storeListingPageLoader $storeListingPageLoader;
  37.         $this->systemConfig           $systemConfig;
  38.         $this->contactRoute           $contactRoute;
  39.         $this->getStoresRoute         $getStoresRoute;
  40.     }
  41.     /**
  42.      * @Route("/StoreLocator", name="frontend.store_locator.index", methods={"GET"})
  43.      */
  44.     public function index(Request $requestSalesChannelContext $context): Response
  45.     {
  46.         if (
  47.             $this->systemConfig->get('NetiNextStoreLocator.config.active'$context->getSalesChannel()->getId())
  48.             !== true
  49.         ) {
  50.             throw new NotFoundHttpException();
  51.         }
  52.         $page $this->storeListingPageLoader->load($request$context);
  53.         return $this->renderStorefront(
  54.             'storefront/store_locator/index.twig',
  55.             [
  56.                 'page' => $page,
  57.             ]
  58.         );
  59.     }
  60.     /**
  61.      * @HttpCache()
  62.      * @Route("/StoreLocator/getStores", name="frontend.store_locator.get_stores", methods={"GET"},
  63.      *                                   defaults={"XmlHttpRequest"=true})
  64.      */
  65.     public function getStores(Request $requestSalesChannelContext $context): JsonResponse
  66.     {
  67.         if (
  68.             $this->systemConfig->get('NetiNextStoreLocator.config.active'$context->getSalesChannel()->getId())
  69.             !== true
  70.         ) {
  71.             throw new NotFoundHttpException();
  72.         }
  73.         return $this->getStoresRoute->getStores($request$context);
  74.     }
  75.     /**
  76.      * @Route("/StoreLocator/detail/{id}", name="frontend.store_locator.detail", methods={"GET"})
  77.      */
  78.     public function detail(Request $requestSalesChannelContext $context): Response
  79.     {
  80.         if (
  81.             $this->systemConfig->get('NetiNextStoreLocator.config.active'$context->getSalesChannel()->getId())
  82.             !== true
  83.         ) {
  84.             throw new NotFoundHttpException();
  85.         }
  86.         $page $this->storeDetailPageLoader->load($request$context);
  87.         return $this->renderStorefront(
  88.             'storefront/store_locator/detail.twig',
  89.             [
  90.                 'page' => $page,
  91.             ]
  92.         );
  93.     }
  94.     /**
  95.      * @deprecated Use `\NetInventors\NetiNextStoreLocator\Storefront\Route\ContactRoute::contact` instead.
  96.      * @Route("/StoreLocator/contact", name="frontend.store_locator.contact", methods={"POST"},
  97.      *                                 defaults={"XmlHttpRequest"=true})
  98.      */
  99.     public function contact(Request $requestSalesChannelContext $context): JsonResponse
  100.     {
  101.         if (
  102.             $this->systemConfig->get('NetiNextStoreLocator.config.active'$context->getSalesChannel()->getId())
  103.             !== true
  104.         ) {
  105.             throw new NotFoundHttpException();
  106.         }
  107.         return $this->contactRoute->contact($request$context);
  108.     }
  109.     /**
  110.      * @Route("/StoreLocator/cms", name="frontend.store_locator.cms", methods={"POST"})
  111.      *
  112.      */
  113.     public function cms(Request $requestSalesChannelContext $context): RedirectResponse
  114.     {
  115.         $data             $request->request->all();
  116.         $redirectResponse $this->redirectToRoute('frontend.store_locator.index');
  117.         $url $redirectResponse->getTargetUrl() . "?search=" $data['search'];
  118.         if (isset($data['additionalParams']) && "" !== $data['additionalParams']) {
  119.             $url .= "&" $data['additionalParams'];
  120.         }
  121.         $redirectResponse->setTargetUrl($url);
  122.         return $redirectResponse;
  123.     }
  124. }