src/Controller/Publico/TiendaController.php line 82

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Publico;
  3. use App\Entity\Ajustes\Pagina;
  4. use App\Entity\Catalogo\Producto;
  5. use App\Repository\Ajustes\PaginaRepository;
  6. use App\Repository\Catalogo\ProductoRepository;
  7. use App\Utils\FilterSession;
  8. use App\Utils\HelperUtil;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Knp\Component\Pager\PaginatorInterface;
  11. use Sonata\SeoBundle\Seo\SeoPageInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
  19. /**
  20.  * @Route("/tienda", name="tienda_")
  21.  */
  22. class TiendaController extends AbstractController
  23. {
  24.     public const BASEDIR Producto::BASEDIR;
  25.     public const BASEDIRTIENDA Producto::BASEDIRPUBLIC;
  26.     public const ICON Producto::ICON;
  27.     protected $em;
  28.     protected $bd;
  29.     protected $bag;
  30.     protected $pag;
  31.     protected $hlp;
  32.     protected $repo;
  33.     protected $trans;
  34.     protected $seo;
  35.     public function __construct(EntityManagerInterface $emBreadcrumbs $bdPaginatorInterface $pgProductoRepository $repoHelperUtil $hlpParameterBagInterface $pbTranslatorInterface $transSeoPageInterface $seo)
  36.     {
  37.         $this->em $em;
  38.         $this->bd $bd;
  39.         $this->bag $pb;
  40.         $this->pag $pg;
  41.         $this->repo $repo;
  42.         $this->hlp $hlp;
  43.         $this->trans $trans;
  44.         $this->seo $seo;
  45.     }
  46.     /**
  47.      * @Route("/{id}/ver", name="prod_view", methods = {"GET"}, requirements = {"id"="\d+"})
  48.      *
  49.      * @param mixed $force
  50.      */
  51.     public function view(Producto $entity): Response
  52.     {
  53.         //SEO
  54.         $titulo =$entity->getProdNombre() != null $entity->getProdNombre() : '' ;
  55.         $descripcion =$entity->getProdDescripcion() !=null $entity->getProdDescripcion() : '';
  56.         $this->seo 
  57.             ->setTitle($titulo)
  58.             ->addMeta('name''description'$descripcion)
  59.             ->addMeta('property''og:title'$titulo)
  60.             ->addMeta('property''og:description'$descripcion)
  61.         ;
  62.         return $this->render(self::BASEDIR.'/prod_view.html.twig', [
  63.             'prod' => $entity,
  64.             'BaseDirTienda' => self::BASEDIRTIENDA,
  65.             'BaseDir' => self::BASEDIR,
  66.             'ICON' => self::ICON,
  67.             'url_include' => 'include_prod_entity_view.html.twig',
  68.         ]);
  69.     }
  70.     /**
  71.      * @Route("/", name="index", options={"expose"=true})
  72.      * 
  73.      */
  74.     public function index(Request $request): Response
  75.     {
  76.         // Filter data
  77.         $default_values = ['sort' => 'prod.id''order' => 'desc''page' => 1'limit' => 12];
  78.         $filtro = new FilterSession($request$default_values'product_list_filter'$this->bag);
  79.         $data = [
  80.             'locale' => true,
  81.             'enabled' => 1,
  82.         ];
  83.         // Pagination values
  84.         $resultBD $this->repo->filter($data, ['getQuery' => true]);
  85.         $pagination $this->pag->paginate(
  86.             $resultBD// query NOT result
  87.             $filtro->getPage(), // page number
  88.             $filtro->getLimit(), // limit per page
  89.             $filtro->getSortKnp()
  90.         );
  91.         //SEO
  92.         $titulo =$this->trans->trans('tienda.seo.title', [], 'tienda');
  93.         $descripcion =$this->trans->trans('tienda.seo.description', [], 'tienda');
  94.         $this->seo 
  95.             ->setTitle($titulo)
  96.             ->addMeta('name''description'$descripcion)
  97.             ->addMeta('property''og:title'$titulo)
  98.             ->addMeta('property''og:description'$descripcion)
  99.         ;
  100.         return $this->render(self::BASEDIRTIENDA.'/tienda_index.html.twig', [
  101.             'BaseDirTienda' => self::BASEDIRTIENDA,
  102.             'BaseDir' => self::BASEDIR,
  103.             'ICON' => self::ICON,
  104.             'pagination' => $pagination,
  105.         ]);
  106.     }
  107. }