src/Controller/ShopController.php line 14

Open in your IDE?
  1. <?php declare(strict_types 1);
  2. namespace App\Controller;
  3. use NexCRM\ShopBundle\Entity\Category;
  4. use NexCRM\ShopBundle\Entity\Product;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class ShopController extends BaseController
  9. {
  10.     public function productAction()
  11.     {
  12.         $message $this->request->query->get("message");
  13.         $this->initialize();
  14.         $routeId explode('_'$this->request->get('_route'));
  15.         /** @var \NexCRM\ShopBundle\Entity\Product $product */
  16.         $product $this->getDoctrine()->getRepository(Product::class)->findOneBy(['seo' => end($routeId)]);
  17.         if (empty($product)) {
  18.             return new Response(''404, ['Content-Type' => 'text/html']);
  19.         }
  20.         $category $this->getDoctrine()->getRepository(Category::class)->findOneBy(['id' => $product->getCategory()]);
  21.         $products $this->getDoctrine()->getRepository(Product::class)->findBy(['category' => $product->getCategory(), 'active' => 1], ['sort' => 'ASC']);
  22.         $template_uri 'front/product.html.twig';
  23.         return $this->render(
  24.             $template_uri, [
  25.             "meta" => $this->metaTagsService->getMetaTags($product),
  26.             "product" => $product,
  27.             "category" => $category,
  28.             "products" => $products,
  29.             "response" => $message,
  30.             "page" => $product,
  31.             "lang" => $this->request->getLocale()
  32.         ],
  33.         );
  34.     }
  35.     public function categoryAction()
  36.     {
  37.         $message $this->request->query->get("message");
  38.         $this->initialize();
  39.         $routeId explode('_'$this->request->get('_route'));
  40.         /** @var \NexCRM\ShopBundle\Entity\Category $category */
  41.         $category $this->getDoctrine()->getRepository(Category::class)->findOneBy(['seo' => end($routeId)]);
  42.         if (empty($category)) {
  43.             return new Response(''404, ['Content-Type' => 'text/html']);
  44.         }
  45.         $products $this->getDoctrine()->getRepository(Product::class)->findBy(['category' => $category'active' => 1], ['sort' => 'ASC']);
  46.         $template_uri 'front/category.html.twig';
  47.         return $this->render(
  48.             $template_uri, [
  49.             "meta" => $this->metaTagsService->getMetaTags($category),
  50.             "category" => $category,
  51.             "products" => $products,
  52.             "response" => $message,
  53.             "page" => $category
  54.         ],
  55.         );
  56.     }
  57.     /**
  58.      * @Route("/product/variant/{lang}/{id}", name="product_variant")
  59.      */
  60.     public function variantAction(string $langint $id)
  61.     {
  62.         /** @var \NexCRM\ShopBundle\Entity\Product $product */
  63.         $product $this->getDoctrine()->getRepository(Product::class)->find($id);
  64.         if (empty($product)) {
  65.             return new Response(''404, ['Content-Type' => 'text/html']);
  66.         }
  67.         $gallery $this->renderView(
  68.             'front/product/media.html.twig', [
  69.                'product' => $product,
  70.                 'lang' => $lang
  71.             ]
  72.         );
  73.         $parameters $this->renderView(
  74.             'front/product/parameters.html.twig',
  75.             [
  76.                 'product' => $product,
  77.                 'lang' => $lang
  78.             ],
  79.         );
  80.         $shortDescription $this->renderView(
  81.             'front/product/shortDescription.html.twig',
  82.             [
  83.                 'product' => $product,
  84.                 'lang' => $lang
  85.             ],
  86.         );
  87.         $description $this->renderView(
  88.             'front/product/description.html.twig',
  89.             [
  90.                 'product' => $product,
  91.                 'lang' => $lang
  92.             ],
  93.         );
  94.         $name $lang '_' $product
  95.                 ->getSEO()
  96.                 ->getId();
  97.         return $this->json(
  98.             [
  99.                 'parameters' => $parameters,
  100.                 'shortDescription' => $shortDescription,
  101.                 'description' => $description,
  102.                 'galleryBox' => $gallery,
  103.                 'url' =>  $this->generateUrl($name)
  104.             ]
  105.         );
  106.     }
  107. }