<?php
namespace App\Controller\Publico;
use App\Entity\Ajustes\Pagina;
use App\Entity\Catalogo\Producto;
use App\Repository\Ajustes\PaginaRepository;
use App\Repository\Catalogo\ProductoRepository;
use App\Utils\FilterSession;
use App\Utils\HelperUtil;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Sonata\SeoBundle\Seo\SeoPageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
/**
* @Route("/tienda", name="tienda_")
*/
class TiendaController extends AbstractController
{
public const BASEDIR = Producto::BASEDIR;
public const BASEDIRTIENDA = Producto::BASEDIRPUBLIC;
public const ICON = Producto::ICON;
protected $em;
protected $bd;
protected $bag;
protected $pag;
protected $hlp;
protected $repo;
protected $trans;
protected $seo;
public function __construct(EntityManagerInterface $em, Breadcrumbs $bd, PaginatorInterface $pg, ProductoRepository $repo, HelperUtil $hlp, ParameterBagInterface $pb, TranslatorInterface $trans, SeoPageInterface $seo)
{
$this->em = $em;
$this->bd = $bd;
$this->bag = $pb;
$this->pag = $pg;
$this->repo = $repo;
$this->hlp = $hlp;
$this->trans = $trans;
$this->seo = $seo;
}
/**
* @Route("/{id}/ver", name="prod_view", methods = {"GET"}, requirements = {"id"="\d+"})
*
* @param mixed $force
*/
public function view(Producto $entity): Response
{
//SEO
$titulo =$entity->getProdNombre() != null ? $entity->getProdNombre() : '' ;
$descripcion =$entity->getProdDescripcion() !=null ? $entity->getProdDescripcion() : '';
$this->seo
->setTitle($titulo)
->addMeta('name', 'description', $descripcion)
->addMeta('property', 'og:title', $titulo)
->addMeta('property', 'og:description', $descripcion)
;
return $this->render(self::BASEDIR.'/prod_view.html.twig', [
'prod' => $entity,
'BaseDirTienda' => self::BASEDIRTIENDA,
'BaseDir' => self::BASEDIR,
'ICON' => self::ICON,
'url_include' => 'include_prod_entity_view.html.twig',
]);
}
/**
* @Route("/", name="index", options={"expose"=true})
*
*/
public function index(Request $request): Response
{
// Filter data
$default_values = ['sort' => 'prod.id', 'order' => 'desc', 'page' => 1, 'limit' => 12];
$filtro = new FilterSession($request, $default_values, 'product_list_filter', $this->bag);
$data = [
'locale' => true,
'enabled' => 1,
];
// Pagination values
$resultBD = $this->repo->filter($data, ['getQuery' => true]);
$pagination = $this->pag->paginate(
$resultBD, // query NOT result
$filtro->getPage(), // page number
$filtro->getLimit(), // limit per page
$filtro->getSortKnp()
);
//SEO
$titulo =$this->trans->trans('tienda.seo.title', [], 'tienda');
$descripcion =$this->trans->trans('tienda.seo.description', [], 'tienda');
$this->seo
->setTitle($titulo)
->addMeta('name', 'description', $descripcion)
->addMeta('property', 'og:title', $titulo)
->addMeta('property', 'og:description', $descripcion)
;
return $this->render(self::BASEDIRTIENDA.'/tienda_index.html.twig', [
'BaseDirTienda' => self::BASEDIRTIENDA,
'BaseDir' => self::BASEDIR,
'ICON' => self::ICON,
'pagination' => $pagination,
]);
}
}