<?php declare(strict_types = 1);
namespace App\Controller;
use NexCRM\ShopBundle\Entity\Category;
use NexCRM\ShopBundle\Entity\Product;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ShopController extends BaseController
{
public function productAction()
{
$message = $this->request->query->get("message");
$this->initialize();
$routeId = explode('_', $this->request->get('_route'));
/** @var \NexCRM\ShopBundle\Entity\Product $product */
$product = $this->getDoctrine()->getRepository(Product::class)->findOneBy(['seo' => end($routeId)]);
if (empty($product)) {
return new Response('', 404, ['Content-Type' => 'text/html']);
}
$category = $this->getDoctrine()->getRepository(Category::class)->findOneBy(['id' => $product->getCategory()]);
$products = $this->getDoctrine()->getRepository(Product::class)->findBy(['category' => $product->getCategory(), 'active' => 1], ['sort' => 'ASC']);
$template_uri = 'front/product.html.twig';
return $this->render(
$template_uri, [
"meta" => $this->metaTagsService->getMetaTags($product),
"product" => $product,
"category" => $category,
"products" => $products,
"response" => $message,
"page" => $product,
"lang" => $this->request->getLocale()
],
);
}
public function categoryAction()
{
$message = $this->request->query->get("message");
$this->initialize();
$routeId = explode('_', $this->request->get('_route'));
/** @var \NexCRM\ShopBundle\Entity\Category $category */
$category = $this->getDoctrine()->getRepository(Category::class)->findOneBy(['seo' => end($routeId)]);
if (empty($category)) {
return new Response('', 404, ['Content-Type' => 'text/html']);
}
$products = $this->getDoctrine()->getRepository(Product::class)->findBy(['category' => $category, 'active' => 1], ['sort' => 'ASC']);
$template_uri = 'front/category.html.twig';
return $this->render(
$template_uri, [
"meta" => $this->metaTagsService->getMetaTags($category),
"category" => $category,
"products" => $products,
"response" => $message,
"page" => $category
],
);
}
/**
* @Route("/product/variant/{lang}/{id}", name="product_variant")
*/
public function variantAction(string $lang, int $id)
{
/** @var \NexCRM\ShopBundle\Entity\Product $product */
$product = $this->getDoctrine()->getRepository(Product::class)->find($id);
if (empty($product)) {
return new Response('', 404, ['Content-Type' => 'text/html']);
}
$gallery = $this->renderView(
'front/product/media.html.twig', [
'product' => $product,
'lang' => $lang
]
);
$parameters = $this->renderView(
'front/product/parameters.html.twig',
[
'product' => $product,
'lang' => $lang
],
);
$shortDescription = $this->renderView(
'front/product/shortDescription.html.twig',
[
'product' => $product,
'lang' => $lang
],
);
$description = $this->renderView(
'front/product/description.html.twig',
[
'product' => $product,
'lang' => $lang
],
);
$name = $lang . '_' . $product
->getSEO()
->getId();
return $this->json(
[
'parameters' => $parameters,
'shortDescription' => $shortDescription,
'description' => $description,
'galleryBox' => $gallery,
'url' => $this->generateUrl($name)
]
);
}
}