src/Controller/Front/ShopController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Application\Service\Session\SessionService;
  4. use App\Entity\System\Language;
  5. use App\Manager\System\BrandLanguageManager;
  6. use App\Manager\System\ProductManager;
  7. use App\Manager\System\TagManager;
  8. use App\Manager\System\TaxonomyLanguageManager;
  9. use App\Service\LegacyControllerService;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class ShopController extends AbstractController
  15. {
  16.     private TaxonomyLanguageManager $taxonomyLanguageManager;
  17.     private BrandLanguageManager $brandLanguageManager;
  18.     private TagManager $tagManager;
  19.     private LegacyControllerService $legacyControllerService;
  20.     private SessionService $sessionService;
  21.     private ProductManager $productManager;
  22.     public function __construct(
  23.         LegacyControllerService $legacyControllerService,
  24.         TaxonomyLanguageManager $taxonomyLanguageManager,
  25.         BrandLanguageManager $brandLanguageManager,
  26.         TagManager $tagManager,
  27.         SessionService $sessionService,
  28.         ProductManager $productManager
  29.     ) {
  30.         $this->taxonomyLanguageManager $taxonomyLanguageManager;
  31.         $this->brandLanguageManager $brandLanguageManager;
  32.         $this->tagManager $tagManager;
  33.         $this->legacyControllerService $legacyControllerService;
  34.         $this->sessionService $sessionService;
  35.         $this->productManager $productManager;
  36.     }
  37.     /**
  38.      * @Route("/{lang}/shop/category/{url}", name="shop_category", requirements={"lang"="[a-zA-Z]{2}", "url"="^((?!rest/).)*$"})
  39.      */
  40.     public function shopCategory(Request $requeststring $url): Response
  41.     {
  42.         $taxonomyLanguage $this->taxonomyLanguageManager->findOneByLinkRewriteAndLanguage(
  43.             $url,
  44.             $request->getSession()->get('id_lang'Language::ENGLISH_LANGUAGE_ID)
  45.         );
  46.         if (!$taxonomyLanguage) {
  47.             throw $this->createNotFoundException();
  48.         }
  49.         try {
  50.             $this->sessionService->set('controller''taxonomyController');
  51.             $this->sessionService->set('id_model'$taxonomyLanguage->getTaxonomy()->getId());
  52.             $legacyController = new \taxonomyController($taxonomyLanguage->getTaxonomy()->getId());
  53.         } catch (\Throwable $t) {
  54.             throw $this->createNotFoundException();
  55.         }
  56.         $legacyController->view($taxonomyLanguage->getTaxonomy()->getId());
  57.         return new Response($this->legacyControllerService->getHtmlFromLegacyController($legacyController));
  58.     }
  59.     /**
  60.      * @Route("/{lang}/shop/brand/{url}", name="shop_brand", requirements={"lang"="[a-zA-Z]{2}", "url"="^((?!rest/).)*$"})
  61.      */
  62.     public function shopBrand(Request $requeststring $url): Response
  63.     {
  64.         $brandLanguage $this->brandLanguageManager->findOneByLinkRewriteAndLanguage(
  65.             $url,
  66.             $request->getSession()->get('id_lang'Language::ENGLISH_LANGUAGE_ID)
  67.         );
  68.         if (!$brandLanguage) {
  69.             throw $this->createNotFoundException();
  70.         }
  71.         try {
  72.             $legacyController = new \manufacturerController();
  73.             $this->sessionService->set('controller''manufacturerController');
  74.             $this->sessionService->set('id_model'$brandLanguage->getBrand()->getId());
  75.         } catch (\Throwable $t) {
  76.             throw $this->createNotFoundException();
  77.         }
  78.         $legacyController->view($brandLanguage->getBrand()->getId());
  79.         return new Response($this->legacyControllerService->getHtmlFromLegacyController($legacyController));
  80.     }
  81.     /**
  82.      * @Route("/{lang}/shop/tag/{url}", name="shop_tag", requirements={"lang"="[a-zA-Z]{2}", "url"="^((?!rest/).)*$"})
  83.      */
  84.     public function shopTag(Request $requeststring $url): Response
  85.     {
  86.         $url trim($url'/');
  87.         $tag $this->tagManager->findOneByLinkRewriteAndLanguage(
  88.             $url,
  89.             $request->getSession()->get('id_lang'Language::ENGLISH_LANGUAGE_ID)
  90.         );
  91.         if (!$tag) {
  92.             throw $this->createNotFoundException();
  93.         }
  94.         try {
  95.             $legacyController = new \tagController();
  96.             $this->sessionService->set('controller''tagController');
  97.         } catch (\Throwable $t) {
  98.             throw $this->createNotFoundException();
  99.         }
  100.         $legacyController->view($url);
  101.         return new Response($this->legacyControllerService->getHtmlFromLegacyController($legacyController));
  102.     }
  103.     /**
  104.      * @Route("/{lang}/shop/product/{url}", name="shop_product", requirements={"lang"="[a-zA-Z]{2}", "url"="^((?!rest/).)*$"})
  105.      */
  106.     public function shopProduct(Request $requeststring $url): Response
  107.     {
  108.         $url trim($url'/');
  109.         $lang $request->getSession()->get('lang'Language::ENGLISH_ISO);
  110.         $product $this->productManager->findOneByLinkRewriteAndLanguage(
  111.             $url,
  112.             $lang
  113.         );
  114.         if (!$product) {
  115.             throw $this->createNotFoundException();
  116.         }
  117.         if ($product->isVirtual()) {
  118.             return $this->redirectToRoute('shop_service', ['url' => $url'lang' => $lang]);
  119.         }
  120.         try {
  121.             $legacyController = new \productController($product->getId());
  122.             $this->sessionService->set('controller''productController');
  123.             $this->sessionService->set('id_model'$product->getId());
  124.         } catch (\Throwable $t) {
  125.             throw $this->createNotFoundException();
  126.         }
  127.         $legacyController->view();
  128.         return new Response($this->legacyControllerService->getHtmlFromLegacyController($legacyController));
  129.     }
  130.     /**
  131.      * @Route("/{lang}/shop/service/{url}", name="shop_service", requirements={"lang"="[a-zA-Z]{2}", "url"="^((?!rest/).)*$"})
  132.      */
  133.     public function shopService(Request $requeststring $url): Response
  134.     {
  135.         $url trim($url'/');
  136.         $product $this->productManager->findOneByLinkRewriteAndLanguage(
  137.             $url,
  138.             $request->getSession()->get('lang'Language::ENGLISH_ISO)
  139.         );
  140.         if (!$product || !$product->isVirtual()) {
  141.             throw $this->createNotFoundException();
  142.         }
  143.         try {
  144.             $legacyController = new \productController($product->getId());
  145.             $this->sessionService->set('controller''productController');
  146.             $this->sessionService->set('id_model'$product->getId());
  147.         } catch (\Throwable $t) {
  148.             throw $this->createNotFoundException();
  149.         }
  150.         $legacyController->view();
  151.         return new Response($this->legacyControllerService->getHtmlFromLegacyController($legacyController));
  152.     }
  153. }