src/Controller/HomeController.php line 365

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Blog;
  4. use App\Entity\Categoria;
  5. use App\Entity\Ciudad;
  6. use App\Entity\Comentario;
  7. use App\Entity\CodigoDescuento;
  8. use App\Entity\ComentarioBlog;
  9. use App\Entity\Compra;
  10. use App\Entity\CompraItem;
  11. use App\Entity\Contacto;
  12. use App\Entity\Direccion;
  13. use App\Entity\Distribuidor;
  14. use App\Entity\EstadoPedido;
  15. use App\Entity\Faq;
  16. use App\Entity\Favorito;
  17. use App\Entity\FavoritoBlog;
  18. use App\Entity\Image;
  19. use App\Entity\Inventario;
  20. use App\Entity\ListaPrecioItem;
  21. use App\Entity\ListaPrecios;
  22. use App\Entity\MetodoPago;
  23. use App\Entity\PoliticaPromocion;
  24. use App\Entity\Producto;
  25. use App\Entity\Seo;
  26. use App\Entity\Tienda;
  27. use App\Entity\TipSalud;
  28. use App\Entity\Usuario;
  29. use App\Form\ComentarioType;
  30. use App\Form\ContactoType;
  31. use App\Form\DireccionType;
  32. use App\Form\PerfilType;
  33. use App\Service\QI;
  34. use App\Service\ClientifyService;
  35. use Doctrine\ORM\Query;
  36. use FOS\UserBundle\Event\GetResponseNullableUserEvent;
  37. use FOS\UserBundle\Event\GetResponseUserEvent;
  38. use FOS\UserBundle\Model\UserInterface;
  39. use FOS\UserBundle\Model\UserManagerInterface;
  40. use FOS\UserBundle\Util\TokenGeneratorInterface;
  41. use Kreait\Firebase;
  42. use Kreait\Firebase\Factory;
  43. use App\Entity\SeguimientoTracking;
  44. use Kreait\Firebase\ServiceAccount;
  45. use MercadoPago\SDK;
  46. use MercadoPago;
  47. use phpDocumentor\Reflection\Types\This;
  48. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  49. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  50. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
  51. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  52. use Symfony\Component\HttpFoundation\RedirectResponse;
  53. use Symfony\Component\HttpFoundation\Request;
  54. use Symfony\Component\HttpFoundation\Response;
  55. use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
  56. use Symfony\Component\Routing\Annotation\Route;
  57. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  58. use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
  59. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  60. use Symfony\Component\Serializer\Encoder\JsonEncode;
  61. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  62. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  63. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  64. use Symfony\Component\Serializer\Serializer;
  65. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  66. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  67. use Algolia\SearchBundle\SearchService;
  68. use Symfony\Component\HttpFoundation\JsonResponse;
  69. use function Doctrine\ORM\QueryBuilder;
  70. class HomeController extends AbstractController
  71. {
  72.     private  $qi;
  73.     private $userManager;
  74.     private $retryTtl;
  75.     private $tokenGenerator;
  76.     private $eventDispatcher;
  77.     private $authorization;
  78.     protected $searchService;
  79.     private  $clientify;
  80.     public function __construct(ClientifyService $clientifyQI $qiUserManagerInterface $userManager,TokenGeneratorInterface $tokenGeneratorEventDispatcherInterface $eventDispatcher,AuthorizationCheckerInterface $authorization,SearchService $searchService)
  81.     {
  82.         $this->clientify $clientify;
  83.         $this->qi $qi;
  84.         $this->userManager $userManager;
  85.         $this->retryTtl 7200;
  86.         $this->tokenGenerator $tokenGenerator;
  87.         $this->eventDispatcher $eventDispatcher;
  88.         $this->authorization $authorization;
  89.         $this->searchService $searchService;
  90.     }
  91.     /**
  92.      * @Route("/direcciones/romance/direcciones", name="direcciones")
  93.      */
  94.     public function direcciones(Request $request)
  95.     {
  96.         $dirs $this->getDoctrine()->getRepository('App:Direccion')->findAll();
  97.         foreach ($dirs as $dir){
  98.             $this->qi->saveFire($dir);
  99.         }
  100.         $res =$this->qi->sendMail("envio de prueba"'ferney@iridian.co'"este mensaje es de prueba");
  101.         dd($res);
  102.     }
  103.     /**
  104.      * @Route("/test_mail/romance/test_mail", name="test_mail")
  105.      */
  106.     public function testMail(Request $request)
  107.     {
  108.         $res =$this->qi->sendMail("envio de prueba"'fabian@iridian.co,fwarrior91@gmail.com'"este mensaje es de prueba");
  109.         dd($res);
  110.     }
  111.     //Rutas romance relax
  112.     /**
  113.      * @Route("/", name="homepage")
  114.      */
  115.     public function home(Request $request)
  116.     {  
  117.         $session $request->getSession();
  118.         $mostre_en_home $session->get('cierre_home','0') == '1';
  119.         $session->set('cierre_home','0');
  120.         $user $this->getUser();
  121.         if(!$user){
  122.             $idTiendaDefault $this->qi->getSetting('id-tienda-usuario-anonimo');
  123.             $tienda $this->getDoctrine()->getRepository(Tienda::class)->findOneBy(array("id" => $idTiendaDefault));
  124.             $this->qi->setTienda($tienda);
  125.         }
  126.         else{
  127.             if(!$this->qi->getDireccion()){
  128.             }
  129.             else{
  130.                 $tienda $this->qi->getTiendaFromCoordinates($this->qi->getDireccion());
  131.                 $this->qi->setTienda($tienda);
  132.                 if(!$tienda){
  133.                     $this->addFlash(
  134.                         'warning',
  135.                         'La direccion seleccionada no tiene cobertura en este momento'
  136.                     );
  137.                 }
  138.             }
  139.         }
  140.         if ($this->qi->getSetting('registro_obligatorio') != '1'){
  141.             $productos $this->getDoctrine()->getRepository('App:Producto')->findBy(array('visible'=>true,'destacado'=>true,'principal'=>true), array('orden'=>'asc'),4);
  142.             $listas=[];
  143.             if($user && $user->getConvenio())
  144.             $convenio $user->getConvenio();
  145.             else{
  146.                 $convenio $this->getDoctrine()->getRepository(ListaPrecios::class)->find(1);
  147.             }
  148.             foreach($productos as $product ){
  149.                 $lista $this->getDoctrine()->getRepository(ListaPrecioItem::class)->findOneBy(array('lista'=>$convenio,'producto'=>$product));
  150.                 $listas[]= $lista;
  151.             }                      
  152.             $blogs $this->getDoctrine()->getRepository('App:Blog')->findBy(array('visible'=>true,'destacado'=>true), array('created_at'=>'desc'));
  153.             $categorias $this->qi->getCategoriasConProductos();
  154.             $cats = [];
  155.             $categorias $this->getDoctrine()->getRepository('App:Categoria')->findBy(array('visible'=>true'home'=>true), array('orden'=>'asc'));
  156.             foreach ($categorias as $cat){
  157.                 $cats[$cat->getNombre()] = $this->qi->prodsCategoria($tienda$cat->getId());
  158.             }
  159.             $subcategorias $this->getDoctrine()->getRepository('App:Subcategoria')->findBy(array('home'=>true'visible'=>true), array('orden'=>'asc'));
  160.             $idprincipal=null;
  161.             return $this->render('home/home_new.html.twig', [
  162.                 'productos' => $productos,
  163.                 'listas' => $listas,
  164.                 'idprincipal' => $idprincipal,
  165.                 'categorias' => $categorias,
  166.                 'subcategorias' => $subcategorias,
  167.                 'cats' => $cats,
  168.                 'mostre_en_home' => $mostre_en_home,
  169.                 'blogs'=> $blogs
  170.             ]);
  171.         }else{
  172.             $direcciones $this->getDoctrine()->getRepository(Direccion::class)->findBy(array('usuario'=>$user,'visible'=>true));
  173.             return $this->render('basic/addDir.html.twig', [
  174.                 'direcciones' => $direcciones,
  175.             ]);
  176.         }
  177.     }
  178.     /**
  179.      * @Route("/nosotros/romance/nosotros", name="nosotros")
  180.      */
  181.     public function nosotros(Request $request)
  182.     {
  183.         $tiendas $this->getDoctrine()->getRepository(Tienda::class)->findBy(array("visible"=>true));
  184.         return $this->render('basic/nosotros.html.twig', [
  185.             "tiendas"=>$tiendas,
  186.             'idprincipal' => $idprincipal=null
  187.         ]);
  188.     }
  189.     /**
  190.      * @Route("/tiendas/romance/tiendas", name="tiendas")
  191.      * @Route("/tiendas/{ciudad_id}/{nombre}", name="tiendas_ciudada")
  192.      */
  193.     public function tiendas(Request $request$ciudad_id null)
  194.     {
  195.         $search = array('visible'=>true);
  196.         if($ciudad_id){
  197.             $ciudad $this->getDoctrine()->getRepository('App:Ciudad')->find($ciudad_id);
  198.             if($ciudad)
  199.                 $search array_merge($search,array('ciudad'=>$ciudad));
  200.         }
  201.         $tiendas $this->getDoctrine()->getRepository('App:TiendaInfo')->findBy($search);
  202.         $tiendasall $this->getDoctrine()->getRepository('App:TiendaInfo')->findBy(array('visible'=>true));
  203.         $distribuidores $this->getDoctrine()->getRepository(Distribuidor::class)->findBy($search,array('orden'=>"asc"));
  204.         $ciudades = [];
  205.         foreach ($tiendasall as $tienda){
  206.             if($tienda->getCiudad())
  207.                 $ciudades[$tienda->getCiudad()->getId()] = $tienda->getCiudad()->getNombre();
  208.         }
  209.         foreach ($distribuidores as $d){
  210.             if($d->getCiudad())
  211.                 $ciudades[$d->getCiudad()->getId()] = $d->getCiudad()->getNombre();
  212.         }
  213.         // dd($distribuidores);
  214.         return $this->render('basic/tiendas.html.twig', [
  215.             'tiendas' => $tiendas,
  216.             'distribuidores' => $distribuidores,
  217.             'ciudades' => $ciudades,
  218.             'ciudad_id' => $ciudad_id,
  219.             'idprincipal' => $idprincipal=null
  220.         ]);
  221.     }
  222.     
  223.     /**
  224.      * @Route("/tienda/{id}", name="tienda")
  225.      */
  226.     public function tienda(Request $request$id)
  227.     {   
  228.         // dd($id);
  229.         $tienda $this->getDoctrine()->getRepository('App:TiendaInfo')->find($id);
  230.         // $tienda = $this->getDoctrine()->getRepository('App:TiendaInfo')->createQueryBuilder('t')
  231.         // ->where('t.id =:tienda_id ')
  232.         // ->setParameter('tienda_id', $id)
  233.         // ->andWhere('t.visible = 1')
  234.         // ->getQuery()
  235.         // ->getResult();
  236.         $tiendas $this->getDoctrine()->getRepository('App:TiendaInfo')->createQueryBuilder('t')
  237.             ->where('t.id !=:tienda_id ')
  238.             ->setParameter('tienda_id'$id)
  239.             ->andWhere('t.visible = 1')
  240.             ->getQuery()
  241.             ->getResult();        
  242.         $imgstienda $this->getDoctrine()->getRepository('App:Image')->findBy(array('tienda'=>$id));
  243.         return $this->render('basic/tienda.html.twig', [
  244.             'tiendas' => $tiendas,
  245.             'tienda' => $tienda,
  246.             'imgs_tienda'=>$imgstienda,
  247.             'idprincipal' => $idprincipal=null
  248.         ]);
  249.     }
  250.     /**
  251.      * @Route("/logo/{id}", name="logo")
  252.      */
  253.     public function logo(Request $request,$id)
  254.     {
  255.         $distribuidor $this->getDoctrine()->getRepository(Distribuidor::class)->find($id);
  256.         return $this->render('basic/logo.html.twig', [
  257.             'distribuidor' => $distribuidor
  258.         ]);
  259.     }
  260.     
  261.     /**
  262.      * @Route("/envio/romance/envio", name="envio")
  263.      */
  264.     public function envio(Request $request)
  265.     {
  266.         return $this->render('basic/envios.html.twig', [
  267.             'idprincipal' => $idprincipal=null
  268.         ]);
  269.     }
  270.     /**
  271.      * @Route("/promociones/romance/promociones", name="promociones")
  272.      */
  273.     public function promociones(Request $request)
  274.     {
  275.         return $this->render('basic/promociones.html.twig', [
  276.             'idprincipal' => $idprincipal=null
  277.         ]);
  278.     }
  279.     /**
  280.      * @Route("/checkout/romance/checkout", name="checkout")
  281.      */
  282.     public function checkout(Request $request)
  283.     {
  284.         $accessToken $this->qi->getSetting("access_token_mercado_pago");
  285.         SDK::setAccessToken($accessToken);
  286.         $payment_methods SDK::get("/v1/payment_methods")["body"];
  287.         $pse null;
  288.         $efecty=null;
  289.         $baloto=null;
  290.         foreach ($payment_methods as $p){
  291.             if (! $pse && $p["id"] == "pse"){
  292.                 $pse $p;
  293.             }
  294.             if (! $efecty && $p["id"] == "efecty"){
  295.                 $efecty $p;
  296.             }
  297.             if (! $baloto && $p["id"] == "baloto"){
  298.                 $baloto $p;
  299.             }
  300.         }
  301.         /* @var $user Usuario */
  302.         $user $this->getUser();
  303.         $departamentos $this->getDoctrine()->getRepository('App:Departamento')->findBy(array('visible'=>true),array('nombre'=>'asc'));
  304.         $ciudades $this->getDoctrine()->getRepository('App:Ciudad')->findBy(array('visible'=>true),array('nombre'=>'asc'));
  305.         $empty_user = array('nombre'=>'''apellido'=>'''email'=>'''celular'=>'','documento'=>'');
  306.         $direcciones $this->getDoctrine()->getRepository('App:Direccion')->findBy(array('usuario'=>$this->getUser()));
  307.         if($this->qi->carritoLength() > 0){
  308.             return $this->render('basic/checkout.html.twig',
  309.             array("user" => $user"ciudades" => $ciudades"departamentos" => $departamentos,"pse"=>$pse,'efecty'=>$efecty,'baloto'=>$baloto,'empty_user'=>$empty_user,'direcciones'=>$direcciones,'idprincipal' => $idprincipal null)
  310.         );
  311.         }else{
  312.             return $this->redirectToRoute('homepage'); 
  313.         }
  314.         
  315.         
  316.     }
  317.     /**
  318.      * @Route("/{producto}/romancerelax", name="producto_slug") 
  319.      * @Route("/{idproducto}/{categoria}/{producto}/romancerelax/ro", name="producto_slug_cat")  
  320.      * @Route("/{idproducto}/{producto}/romancerelax", name="producto_slug_subcat")            
  321.      * @Route("/product/{id}/{nombre}", name="product")
  322.      * @Route("/product/{id}/{nombre}/{medida}", name="product_medida")
  323.      * @Route("/{idproducto}/{subcategoria}/{categoria}/{producto}/romancerelax/ro", name="producto_slug_subcategoria")      
  324.      */
  325.     public function product(Request $request$id=null$medida=null)
  326.     {
  327.         $routeName $request->attributes->get('_route');
  328.         $routeParameters $request->attributes->get('_route_params');
  329.         // dd($routeName);
  330.         $vieneconsubcategoria=null;
  331.         if($routeName == 'producto_slug'){
  332.             $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('slug'=>$routeParameters['producto']));
  333.             $id=$prod->getId();
  334.         }
  335.         if($routeName == 'producto_slug_cat'){
  336.             $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto'], 'slug'=>$routeParameters['producto'], 'principal'=>));
  337.             if(!$prod){
  338.                 $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto']));
  339.             }
  340.             if($prod != null){
  341.                 $id=$prod->getId();
  342.             }
  343.         }
  344.         if($routeName == 'producto_slug_subcat'){
  345.             $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto'],'slug'=>$routeParameters['producto'], 'principal'=>));
  346.             if(!$prod){
  347.                 $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto']));
  348.             }
  349.             $id=$prod->getId();
  350.         }
  351.         if($routeName == 'producto_slug_subcategoria'){
  352.             $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto'],'slug'=>$routeParameters['producto'], 'principal'=>));
  353.             if(!$prod){
  354.                 $prod=$this->getDoctrine()->getRepository('App:Producto')->findOneBy(array('plu'=>$routeParameters['idproducto']));
  355.             }
  356.             $id=$prod->getId();
  357.             $vieneconsubcategoria=$routeParameters['subcategoria'];
  358.         }
  359.         $product $this->getDoctrine()->getRepository('App:Producto')->find($id);
  360.         $idsub=$product->getSubcategoria()->getId();
  361.         $subcateg $this->getDoctrine()->getRepository('App:Subcategoria')->findOneBy(array('id'=>$idsub));
  362.         $idcateg $subcateg->getCategoria();
  363.         $categoria=$this->getDoctrine()->getRepository('App:Categoria')->findBy(array('id'=>$idcateg));
  364.         $subcategorias $this->qi->getSubCategoriasConProductos($idcateg);
  365.         $idmaterialproduct=$product->getMaterial();
  366.         if($idmaterialproduct){
  367.             $materialproduct=$this->getDoctrine()->getRepository('App:Material')->findOneBy(array('id'=>$idmaterialproduct));
  368.             $namemat=$materialproduct->getNombre();
  369.         }else{
  370.             $namemat=null
  371.         }
  372.         $user $this->getUser();
  373.         if($user && $user->getConvenio())
  374.             $convenio $user->getConvenio();
  375.         else{
  376.             $convenio $this->getDoctrine()->getRepository(ListaPrecios::class)->find(1);
  377.         }
  378.         $lista $this->getDoctrine()->getRepository(ListaPrecioItem::class)->findOneBy(array('lista'=>$convenio,'producto'=>$product));
  379.         $padre $product->getPadre();
  380.         if(!$padre)
  381.             $padre $product;
  382.         $hermanos $this->getDoctrine()->getRepository(Producto::class)->createQueryBuilder('p')
  383.             ->select('p.plu''p.nombre''p.tamanio''p.maestro','p.tipologia''p.materiales','medida.nombre as nombremed','material.nombre as nombremat','medida.id as idmed','medida.orden as medidaorden')
  384.             ->leftJoin('p.medidas''medida')
  385.             ->leftJoin('p.material''material')
  386.             ->Where('p.maestro = :maestro')
  387.             ->setParameter('maestro',$product->getMaestro())
  388.             ->orderBy('medidaorden','asc')
  389.             ->getQuery()
  390.             ->getResult();
  391.         $medidas=[];
  392.         foreach($hermanos as $h){
  393.             $medidas[$h['nombremed']]=$h;
  394.         }
  395.         
  396.         $url_combos "categoria/2/combo";
  397.         $med=null;
  398.         if($medida != null){
  399.             $med=$medida;
  400.         }
  401.         $idprincipal=null;
  402.         $slugcat=$categoria[0]->getSlug();
  403.         $imgsprod $this->getDoctrine()->getRepository(Image::class)->createQueryBuilder('i')
  404.         ->select('i')
  405.         ->leftJoin('i.producto''prod')
  406.         ->where('prod.plu = '.$product->getId())
  407.         ->andWhere('i.visible = 1')
  408.         ->orderBy('i.orden','asc')
  409.         ->getQuery()
  410.         ->getResult();
  411.         $maestros $this->qi->themaestros($product->getMaestro());
  412.         foreach($maestros as $m){
  413.             $princ $m['principal'];
  414.             if($princ == 1){
  415.                 $principal $m;
  416.             }
  417.         }
  418.         $relacionados $principal['relacionados'];
  419.         if($product->getsubCategoria()->getCategoria()->getId() == 1){
  420.             $imgsprod $this->getDoctrine()->getRepository(Image::class)->createQueryBuilder('i')
  421.             ->select('i')
  422.             ->leftJoin('i.producto''prod')
  423.             ->where('prod.plu = '.$principal['plu'])
  424.             ->andWhere('i.visible = 1')
  425.             ->orderBy('i.orden','asc')
  426.             ->getQuery()
  427.             ->getResult();
  428.         }
  429.         
  430.         return $this->render('basic/product.html.twig', array(
  431.                 'principal_padre'=>$principal,
  432.                 'medidaroute' => $medida,
  433.                 'product' => $product,
  434.                 'materialproduct'=>$namemat,
  435.                 'hermanos'  => $hermanos,
  436.                 'idprincipal' => $idprincipal,
  437.                 'lista' => $lista,
  438.                 'relacionados' => $relacionados,
  439.                 'medida' => $med,
  440.                 'subcategorias'=>$subcategorias,
  441.                 'idcateg'=>$idcateg,
  442.                 'slugcat'=>$slugcat,
  443.                 'imgsprod'=>$imgsprod,
  444.                 'medidas'=>$medidas,
  445.                 'vieneconsubcategoria'=>$vieneconsubcategoria,
  446.                 'idsub'=>$idsub,
  447.                 'idcateg'=>$idcateg
  448.             )
  449.         );
  450.     }
  451.     /**
  452.      * @Route("/contacto/romance/contacto", name="contacto")
  453.      */
  454.     public function contacto(Request $request)
  455.     {
  456.         $contacto= new Contacto();
  457.         $form $this->createForm(ContactoType::class, $contacto);
  458.         $form->handleRequest($request);
  459.         if ($form->isSubmitted() && $form->isValid()) {
  460.             $entityManager $this->getDoctrine()->getManager();
  461.             $entityManager->persist($contacto);
  462.             $entityManager->flush();
  463.             $asunto $this->qi->getSetting('asunto_mail_contacto');
  464.             $html $this->renderView('mailing/contacto.html.twig', array(
  465.              ));
  466.             $this->qi->sendMail($asunto,$contacto->getEmail(),$html);
  467.             $htmlenvio $this->renderView('mailing/contactoenvio.html.twig', array(
  468.                 'nombre'=>$contacto->getNombre(),
  469.                 'email'=>$contacto->getEmail(),
  470.                 'telefono'=>$contacto->getTelefono(),
  471.                 'mensaje'=>$contacto->getMensaje(),
  472.             ));
  473.             $to $this->qi->getSetting('mail_recepcion_contacto');
  474.              $this->qi->sendMail($asunto,$to,$htmlenvio);
  475.             return $this->render('basic/contacto.html.twig', [
  476.                 'gracias'=>true,
  477.                 'idprincipal' => $idprincipal=null
  478.             ]);
  479.         }
  480.         return $this->render('basic/contacto.html.twig', [
  481.             'gracias'=>false,
  482.             'form'=> $form->createView(),
  483.             'idprincipal' => $idprincipal=null
  484.         ]);
  485.     }
  486.     /**
  487.      * @Route("/blog/romance/blog", name="blog")
  488.      * @Route("/blog/{id}/{nombre}", name="blog_categoria")
  489.      */
  490.     public function blog(Request $request$id null)
  491.     {
  492.         $categorias $this->getDoctrine()->getRepository('App:CategoriaBlog')->findAll();
  493.         if($id){
  494.             $categoria $this->getDoctrine()->getRepository('App:CategoriaBlog')->find($id);
  495.             $blogs $this->getDoctrine()->getManager()->getRepository('App:Blog')->findBy(array('visible'=>true,'categoria'=>$categoria),array('fecha'=>'desc'));
  496.         }else
  497.             $blogs $this->getDoctrine()->getManager()->getRepository('App:Blog')->findBy(array('visible'=>true),array('fecha'=>'desc'));
  498.         return $this->render('blog/blog.html.twig', [
  499.             'blogs' => $blogs,
  500.             'categorias' => $categorias,
  501.             'idprincipal' => $idprincipal null
  502.         ]);
  503.     }
  504.     /**
  505.      * @Route("/blog-interna/{id}/{nombre}", name="blog-interna")
  506.      */
  507.     public function blogInterna(Request $request$id)
  508.     {
  509.         $blog $this->getDoctrine()->getRepository('App:Blog')->find($id);
  510.         $blog_next $this->getDoctrine()->getRepository('App:Blog')->createQueryBuilder('b')
  511.             ->select('b.id','b.titulo','b.created_at')
  512.             ->where('b.created_at <= :fecha')
  513.             ->andWhere('b.id != '.$blog->getId())
  514.             ->orderBy('b.created_at','desc')
  515.             ->setMaxResults(1)
  516.             ->setParameter('fecha'$blog->getCreatedAt())
  517.             ->getQuery()
  518.             ->getOneOrNullResult();
  519.         if(!$blog_next){
  520.             $blog_next $this->getDoctrine()->getRepository('App:Blog')->createQueryBuilder('b')
  521.                 ->select('b.id','b.titulo')
  522.                 ->orderBy('b.created_at','desc')
  523.                 ->andWhere('b.id != '.$blog->getId())
  524.                 ->setMaxResults(1)
  525.                 ->getQuery()
  526.                 ->getOneOrNullResult();
  527.         }
  528.         $blog_prev $this->getDoctrine()->getRepository('App:Blog')->createQueryBuilder('b')
  529.             ->select('b.id','b.titulo')
  530.             ->where('b.created_at >= :fecha')
  531.             ->andWhere('b.id != '.$blog->getId())
  532.             ->orderBy('b.created_at','asc')
  533.             ->setMaxResults(1)
  534.             ->setParameter('fecha'$blog->getCreatedAt())
  535.             ->getQuery()
  536.             ->getOneOrNullResult();
  537.         if(!$blog_prev){
  538.             $blog_prev $this->getDoctrine()->getRepository('App:Blog')->createQueryBuilder('b')
  539.                 ->select('b.id','b.titulo')
  540.                 ->orderBy('b.created_at','asc')
  541.                 ->andWhere('b.id != '.$blog->getId())
  542.                 ->setMaxResults(1)
  543.                 ->getQuery()
  544.                 ->getOneOrNullResult();
  545.         }
  546.         $likes $this->getDoctrine()->getRepository('App:Like')->createQueryBuilder('q')
  547.             ->select('count(q)')
  548.             ->leftJoin('q.blog','b')
  549.             ->where('b.id = '.$blog->getId())
  550.             ->getQuery()
  551.             ->getSingleResult();
  552.         $comentario = new ComentarioBlog();
  553.         $comentario->setBlog($blog);
  554.         $like_user false;
  555.         $user_id 0;
  556.         if($this->getUser()){
  557.             $user_id $this->getUser()->getId();
  558.             $usuario $this->getDoctrine()->getRepository('App:Usuario')->find($user_id);
  559.             $comentario->setUsuario($usuario);        
  560.             $idblog=$blog->getId();
  561.             $like_user $this->getDoctrine()->getRepository('App:Like')->findBy(array('blog'=>$idblog));
  562.         }               
  563.         $form $this->createForm(ComentarioType::class, $comentario);
  564.         $creado false;
  565.         if($request->isMethod('POST')){
  566.             $form->handleRequest($request);
  567.             if ($form->isSubmitted() && $form->isValid()) {
  568.                 $entityManager $this->getDoctrine()->getManager();
  569.                 $entityManager->persist($comentario);
  570.                 $entityManager->flush();
  571.                 $creado true;
  572.                 $comentario = new ComentarioBlog();
  573.                 $comentario->setBlog($blog);
  574.                 if($this->getUser()){
  575.                     $usuario $this->getDoctrine()->getRepository('App:Usuario')->find($this->getUser()->getId());
  576.                     $comentario->setUsuario($usuario);
  577.                 }
  578.                 $form $this->createForm(ComentarioType::class, $comentario);
  579.             }
  580.         }
  581.         $comentarios $this->getDoctrine()->getRepository('App:ComentarioBlog')->createQueryBuilder('q')
  582.             ->select('q.id','q.comentario''q.created_at'"concat(u.nombre, ' ', u.apellido) usuario")
  583.             ->leftJoin('q.blog','b')
  584.             ->leftJoin('q.usuario','u')
  585.             ->where('b.id = '.$blog->getId())
  586.             ->getQuery()
  587.             ->getResult();
  588.         return $this->render('blog/blog-interna.html.twig', [
  589.             'blog' => $blog,
  590.             'likes' => $likes,
  591.             'comentarios' => $comentarios,
  592.             'blog_next' => $blog_next,
  593.             'blog_prev' => $blog_prev,
  594.             'form' => $form->createView(),
  595.             'creado' => $creado,
  596.             'like_user' => $like_user,
  597.             'user_id' => $user_id,
  598.             'idprincipal' => $idprincipal null
  599.         ]);
  600.     }
  601.     /**
  602.      * @Route("/comentario/romance/comentario", name="comentario")
  603.      */
  604.     public function comentario(Request $request)
  605.     {
  606.         $contacto= new Comentario();
  607.         $form $this->createForm(ContactoType::class, $contacto);
  608.         $form->handleRequest($request);
  609.         if ($form->isSubmitted() && $form->isValid()) {
  610.             $entityManager $this->getDoctrine()->getManager();
  611.             $entityManager->persist($contacto);
  612.             $entityManager->flush();
  613.             $asunto $this->qi->getSetting('asunto_mail_contacto');
  614.             $html $this->renderView('contact/contact_mail.html.twig', array(
  615.                 'nombre'=>$contacto->getNombre(),
  616.                 'email'=>$contacto->getEmail(),
  617.                 'telefono'=>$contacto->getTelefono(),
  618.                 'mensaje'=>$contacto->getMensaje(),
  619.             ));
  620.             $this->qi->sendMail($asunto,$contacto->getEmail(),$html);
  621.             $to $this->qi->getSetting('mail_recepcion_pedidos');
  622.             $this->qi->sendMail($asunto,$to,$html);
  623.             return $this->render('basic/contacto.html.twig', [
  624.                 'gracias'=>true
  625.             ]);
  626.         }
  627.         return $this->render('basic/contacto.html.twig', [
  628.             'gracias'=>false,
  629.             'form'=> $form->createView(),
  630.             'idprincipal' => $idprincipal=null
  631.         ]);
  632.     }
  633.     /**
  634.      * @Route("/buscador_old/romance/buscador_old", name="buscador_old")
  635.      */
  636.     public function buscadorOld(Request $request)
  637.     {
  638.        /*  if (!$this->qi->getDireccion()) {
  639.             $tienda = null;
  640.         } else {
  641.             if (!$this->qi->getTienda()) {
  642.                 $tienda = $this->qi->getTiendaFromCoordinates($this->qi->getDireccion());
  643.                 if (!$tienda) {
  644.                     $this->addFlash(
  645.                         'warning',
  646.                         'La direccion seleccionada no tiene cobertura en este momento'
  647.                     );
  648.                     return $this->redirectToRoute('misdirecciones');
  649.                 }
  650.             } else {
  651.                 $tienda = $this->qi->getTienda();
  652.             }
  653.         } */
  654.         /* $query = $request->query->get('query', "");
  655.         $productos = $this->getDoctrine()->getRepository(Producto::class)->createQueryBuilder('p')
  656.             ->select('p')
  657.             ->leftJoin('p.categorias', 'c')
  658.             ->where('(p.nombre like :query or p.nombreComercial like :query or p.resumen like :query or p.contraindicaciones like :query or p.interacciones like :query or p.posologia like :query) and p.visible = 1')
  659.             ->andWhere('c.visible = 1')
  660.             ->setParameter('query', '%' . $query . '%');
  661.         if ($tienda) {
  662.             $productos->leftJoin('p.inventarios', 'i')
  663.                 ->leftJoin('i.tienda', 't')
  664.                 ->andWhere('i.cantidad >= 0 and t.id = :tienda')
  665.             ->setParameter('tienda', $tienda->getId());
  666.         }
  667.         $productos= $productos->groupBy('p.plu')->orderBy('p.orden','asc')
  668.             ->getQuery()
  669.             ->getArrayResult();*/
  670.         return false;
  671.         /*return $this->render('basic/buscador.html.twig', [
  672.         ]);*/
  673.     }
  674.     /**
  675.      * @Route("/buscadorapi/romance/buscadorapi", name="buscadorapi")
  676.      */
  677.     public function buscadorapi(Request $request)
  678.     {
  679.         $msg '';
  680.         $status 0;
  681.         $resp = [];
  682.         if (!$this->qi->getDireccion()) {
  683.             $tienda null;
  684.         } else {
  685.             if (!$this->qi->getTienda()) {
  686.                 $tienda $this->qi->getTiendaFromCoordinates($this->qi->getDireccion());
  687.                 if (!$tienda) {
  688.                     $resp = [];
  689.                 }
  690.             } else {
  691.                 $tienda $this->qi->getTienda();
  692.             }
  693.         }
  694.         $query $request->request->get('search'"");
  695.         $productos $this->getDoctrine()->getRepository(Producto::class)->createQueryBuilder('p')
  696.             ->select('p.plu value''p.nombre label')
  697.             ->leftJoin('p.categorias''c')
  698.             ->where('(p.nombre like :query or p.nombreComercial like :query or p.resumen like :query or p.contraindicaciones like :query or p.interacciones like :query or p.posologia like :query) and p.visible = 1')
  699.             ->andWhere('c.visible = 1')
  700.             ->setParameter('query''%' $query '%');
  701.         if ($tienda) {
  702.             $productos->leftJoin('p.inventarios''i')
  703.                 ->leftJoin('i.tienda''t')
  704.                 ->andWhere('i.cantidad > 0 and t.id = :tienda')
  705.                 ->setParameter('tienda'$tienda->getId());
  706.         }
  707.         $productos$productos->groupBy('p.plu')->orderBy('p.orden','asc')
  708.             ->getQuery()
  709.             ->getArrayResult();
  710.         return new Response(json_encode($productos));
  711.     }
  712.     /**
  713.      * @Route("/misdirecciones/romance/misdirecciones", name="misdirecciones")
  714.      */
  715.     public function misdirecciones(Request $request)
  716.     {
  717.         $user $this->getUser();
  718.         if(!$user){
  719.             return $this->redirectToRoute('homepage');
  720.         }
  721.         $tiendas $this->getDoctrine()->getRepository(Tienda::class)->findBy(array('visible'=>true),array('orden'=>'asc'));
  722.         $direcciones $this->getDoctrine()->getRepository(Direccion::class)->findBy(array('usuario'=>$user,'visible'=>true));
  723.         return $this->render('basic/addDir.html.twig', [
  724.             'tiendas' => $tiendas,
  725.             'direcciones' => $direcciones,
  726.             'idprincipal' => $idprincipal=null
  727.         ]);
  728.     }
  729.     /**
  730.      * @Route("/perfil/romance/perfil", name="perfil")
  731.      */
  732.     public function perfil(Request $request$id null)
  733.     {
  734.         $user $this->getUser();
  735.         $borre_dir false;
  736.         if($id){
  737.             $direccion $this->getDoctrine()->getRepository(Direccion::class)->find($id);
  738.             $direccion->setVisible(false);
  739.             $entityManager $this->getDoctrine()->getManager();
  740.             $entityManager->persist($direccion);
  741.             $entityManager->flush();
  742.             $borre_dir true;
  743.         }
  744.         $direcciones $this->getDoctrine()->getRepository(Direccion::class)->createQueryBuilder('d')
  745.             ->select('d')
  746.             ->leftJoin('d.usuario','u')
  747.             ->where('u.id = '.$user->getId())
  748.             ->andWhere('d.visible is null or d.visible = 1')
  749.             ->getQuery()
  750.             ->getResult();
  751.         $form $this->createForm(PerfilType::class, $user);
  752.         $form->handleRequest($request);
  753.         if ($form->isSubmitted() && $form->isValid()) {
  754.             $entityManager $this->getDoctrine()->getManager();
  755.             $entityManager->persist($user);
  756.             $entityManager->flush();
  757.             return $this->render('user/perfil.html.twig', [
  758.                 'gracias'=>true,
  759.                 'borre_dir'=>$borre_dir,
  760.                 'direcciones' => $direcciones,
  761.                 'form'=> $form->createView()
  762.             ]);
  763.         }
  764.         return $this->render('user/perfil.html.twig', [
  765.             'gracias'=>false,
  766.             'borre_dir'=>$borre_dir,
  767.             'direcciones' => $direcciones,
  768.             'form'=> $form->createView()
  769.         ]);
  770.     }
  771.     /**
  772.      * @Route("/recomendaciones-para-pacientes/romance/recomendaciones-para-pacientes", name="recomendaciones")
  773.      */
  774.     public function recomendaciones(Request $request)
  775.     {
  776.         return $this->render('recomendaciones/recomendaciones.html.twig', [
  777.             'gracias'=>false,
  778.             'form'=> null
  779.         ]);
  780.     }
  781.     /**
  782.      * @Route("/tips/romance/tips", name="tips")
  783.      */
  784.     public function tips(Request $request)
  785.     {
  786.         $tips $this->getDoctrine()->getRepository(TipSalud::class)->findBy(array("visible" => true), array('orden'=>'asc'));
  787.         return $this->render('tips/index.html.twig', [
  788.             "tips"=>$tips,
  789.             'gracias'=>false,
  790.             'form'=> null
  791.         ]);
  792.     }
  793.     /**
  794.      * @Route("/tip/{id}", name="tip")
  795.      */
  796.     public function tip(Request $request$id)
  797.     {
  798.         $tip $this->getDoctrine()->getRepository(TipSalud::class)->find($id);
  799.         return $this->render('tips/tip.html.twig', [
  800.             "tip"=>$tip,
  801.             'gracias'=>false,
  802.             'form'=> null
  803.         ]);
  804.     }
  805.     /**
  806.      * @Route("/covid-19", name="covid")
  807.      */
  808.     public function covid(Request $request)
  809.     {
  810.         $articulos $this->getDoctrine()->getRepository('App:Covid')->findBy(array('visible'=>true),array('orden'=>'asc'));
  811.         return $this->render('recomendaciones/recomendaciones.html.twig', [
  812.             'gracias'=>false,
  813.             'form'=> null,
  814.             'articulos'=>$articulos
  815.         ]);
  816.     }
  817.     /**
  818.      * @Route("/servicios-de-enfermeria", name="enfermeria")
  819.      */
  820.     public function enfermeria(Request $request)
  821.     {
  822.         $first 1;
  823.         $size 100;
  824.         $productos $this->getDoctrine()->getRepository('App:Inventario')->createQueryBuilder('i')
  825.         ->select('i.precio','p.nombre','p.imagen','p.plu')
  826.         ->addSelect(
  827.             'CASE WHEN p.nombreComercial is not null and p.nombreComercial <> \'\' THEN p.nombreComercial ELSE p.nombre END AS nombrePublico')
  828.         ->leftJoin('i.producto','p')
  829.         ->leftJoin('p.categorias','c')
  830.         ->where('i.cantidad > 0')
  831.         ->andWhere('p.visible = 1')
  832.         ->andWhere("p.imagen not like '%icon%'")
  833.         ->setFirstResult($first)
  834.         ->setMaxResults($size)
  835.         ->getQuery()
  836.         ->getArrayResult();
  837.         shuffle($productos);
  838.         $productos array_slice($productos,0,4);
  839.         return $this->render('enfermeria/enfermeria.html.twig', [
  840.             'gracias'=>false,
  841.             'form'=> null,
  842.             'productos'=>$productos
  843.         ]);
  844.     }
  845.     /**
  846.      * @Route("/pedir/romance/pedir", name="pedir")
  847.      */
  848.     public function pedir(Request $request)
  849.     { 
  850.         try {
  851.             $user $this->getUser();
  852.             $direccion $this->getDoctrine()->getRepository(Direccion::class)->find($this->qi->getDireccion()->getId());
  853.             $metodo_sel $request->request->get('metodo');
  854.             $metodo $this->getDoctrine()->getRepository(MetodoPago::class)->findOneBy(array('id' => $metodo_sel));
  855.             $tienda $this->getDoctrine()->getRepository(Tienda::class)->find($this->qi->getTienda()->getId());
  856.             $costo_domicilio $tienda->getCostoDomicilio();
  857.             $comentarios $request->request->get('comentarios');
  858.             $medico $request->request->get('medico');
  859.             $lifemiles $request->request->get('lifemiles');
  860.             $peticion$this->qi->getCarrito();
  861.             $paga_con 0;
  862.             $canal "web";
  863.             $carrito=[];
  864.             if($metodo_sel == "2"){
  865.                 return $this->redirectToRoute('pagos_payu',array(
  866.                     "comentarios"=>$comentarios,
  867.                     "medico" => $medico,
  868.                     "lifemiles" => $lifemiles
  869.                 ));
  870.             }
  871.             foreach ($this->qi->getCarrito() as $item){
  872.                 $elem = array("product_id"=>$item["producto"]->getPlu(),"count"=>$item["cantidad"]);
  873.                 array_push($carrito,$elem);
  874.             }
  875.             $res $this->qi->crearPedido($metodo,$canal,$comentarios,$this->getUser()); 
  876.             /* @var $compra Compra */
  877.             $compra =$res["compra"];
  878.             $resultado = array("ok" => true'obj' => array("compra"=>array("id"=>$compra->getId())));
  879.             // dd('entra a pedir',$compra);
  880.             if($this->qi->getSetting('enviar_correo') == "1"){
  881.                 $asunto $this->qi->getTexto('asunto_compra_cliente');
  882.                 $this->qi->sendMail($asunto$this->getUser()->getEmail(), $compra->getBody());
  883.                 $asunto $this->qi->getTexto('asunto_compra_tienda');
  884.                 if($compra->getTienda()) {
  885.                     $this->qi->sendMail($asunto$compra->getTienda()->getEmail(), $compra->getBody());
  886.                 }else{
  887.                     $this->qi->sendMail($asunto$this->qi->getSetting('mail_recepcion_pedidos'), $compra->getBody());
  888.                 }
  889.             }
  890.         }catch (\Exception $e){
  891.             $resultado = array("ok" => false'obj' => $e->getCode()." - ".$e->getMessage());
  892.         }
  893.         if($resultado["ok"]) {
  894.             return $this->redirectToRoute('confirmacion'$resultado);
  895.         }else{
  896.             return $this->redirectToRoute('carrito'$resultado);
  897.         }
  898.     }
  899.     /**
  900.      * @Route("/set-direccion/{id}", name="set-direccion")
  901.      */
  902.     public function setDireccion(Request $request,$id)
  903.     {
  904.         $user $this->getUser();
  905.         $dir $this->getDoctrine()->getRepository(Direccion::class)->find($id);
  906.         $this->qi->setDireccion($dir);
  907.         $tienda $this->qi->getTiendaFromCoordinates($dir);
  908.         if(!$tienda){
  909.             $this->addFlash(
  910.                 'warning',
  911.                 'La direccion seleccionada no tiene cobertura en este momento'
  912.             );
  913.             return $this->redirectToRoute('misdirecciones');
  914.         }
  915.         $this->qi->setTienda($tienda);
  916.         if($this->qi->carritoLength() > 0)
  917.             return $this->redirectToRoute('carrito');
  918.         return $this->redirectToRoute('homepage');
  919.     }
  920.     /**
  921.      * @Route("/add-direccion/romance/add-direccion", name="add-direccion")
  922.      */
  923.     public function addDireccion(Request $request)
  924.     {
  925.         $user $this->getUser();
  926.         // dd($user);
  927.         if($user) {
  928.             $dir = new Direccion();
  929.             $dirarr $request->request->get('direccion');
  930.             $ciudad $request->request->get('ciudad');
  931.             $prede $request->request->get('predeterminada');
  932.             $prede=$prede ?? 0;
  933.             $ciudad $this->getDoctrine()->getRepository(Ciudad::class)->find($ciudad);
  934.             $dir->setUsuario($user);
  935.             $dir->setDireccion($dirarr);
  936.             $dir->setUid($user->getUid() ?? '');
  937.             $dir->setCiudad($ciudad);
  938.             $dir->setPredeterminada($prede);
  939.             $entityManager $this->getDoctrine()->getManager();
  940.             $entityManager->persist($dir);
  941.             $entityManager->flush();
  942.             $this->qi->setDireccion($dir);
  943.             return $this->redirectToRoute('mis-direcciones');
  944.         }else{
  945.             return $this->redirectToRoute('login');
  946.         }
  947.     }
  948.     function existeCatProds($productos,$c){
  949.         $encontrado false;
  950.         for ($i 0$i<count($productos);$i++){
  951.             for($k 0$k count($productos[$i]["producto"]["categorias"]);$k++){
  952.                 $encontrado $c->getId() == $productos[$i]["producto"]["categorias"][$k]['id'];
  953.                 if($encontrado){
  954.                     $k=count($productos[$i]["producto"]["categorias"])+1;
  955.                     $i=count($productos)+1;
  956.                     break;
  957.                 }
  958.             }
  959.             if($encontrado){
  960.                 break;
  961.             }
  962.         }
  963.         return $encontrado;
  964.     }
  965.     function arePointsNear($checkPoint$centerPoint$km) {
  966.         $ky 40000 360;
  967.         $kx cos(pi() * $centerPoint->getLat() / 180.0) * $ky;
  968.         $dx abs($centerPoint->getLng() - $checkPoint->getLng()) * $kx;
  969.         $dy abs($centerPoint->getLat() - $checkPoint->getLat()) * $ky;
  970.         return sqrt($dx $dx $dy $dy) <= $km;
  971.     }
  972.     /**
  973.      * @Route("/categoria", name="categoria")
  974.      * @Route("/subcategoria/{id_sub}/{nombre}/{referencia}", name="subcategoria_nombre")
  975.      * @Route("/{subcategoria}/{categoria_slug}", name="subcategoria_slug") 
  976.      * @Route("/buscador/romance/buscador", name="buscador")
  977.      * @Route("/{categoria}", name="categoria_slug")
  978.      * @Route("/{categoria}/{medida}/romance/ro", name="medida")    
  979.      * @Route("/{categoria}/{material}/romance", name="material")     
  980.      */
  981.     public function categoria(Request $request$id_cat null$id_sub null$referencia=null$medidaid=null$materialid=null )
  982.     {
  983.         $subcategorianull;
  984.         $titulo "";
  985.         $query $this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  986.             ->select('p.plu')
  987.             ->where('p.visible=1')
  988.             ->leftJoin('p.subcategoria','s');
  989.         $routeName $request->attributes->get('_route');
  990.         $routeParameters $request->attributes->get('_route_params');
  991.         $parameter_med='';
  992.         $medidaparameter=[];
  993.         $medidassel=[];
  994.         $material=null;
  995.         if($routeName == 'categoria_slug'){
  996.             $cat=$this->getDoctrine()->getRepository('App:Categoria')->findOneBy(array('slug'=>$routeParameters['categoria']));
  997.             if(!$cat){
  998.                 return $this->redirectToRoute("homepage");
  999.             }
  1000.             $id_cat=$cat->getId();
  1001.         }
  1002.         if($routeName == 'subcategoria_slug' ){
  1003.             $cat=$this->getDoctrine()->getRepository('App:Categoria')->findOneBy(array('slug'=>$routeParameters['categoria_slug']));
  1004.             if(!$cat){
  1005.                 return $this->redirectToRoute("homepage");
  1006.             }
  1007.             $subcat=$this->getDoctrine()->getRepository('App:Subcategoria')->findOneBy(array('slug'=>$routeParameters['subcategoria'],'categoria'=>$cat->getId()));
  1008.             if(!$subcat){
  1009.                 return $this->redirectToRoute("homepage");
  1010.             }
  1011.             $id_sub=$subcat->getId();
  1012.         }
  1013.         if($routeName == 'medida' ){
  1014.             $parameter_med=str_replace '-' ' ' ,$routeParameters['medida'] );
  1015.             $routeParameters['categoria'];
  1016.             $cat=$this->getDoctrine()->getRepository('App:Categoria')->findOneBy(array('slug'=>$routeParameters['categoria']));
  1017.             $id_cat=$cat->getId();
  1018.             //$medidaparameter=$this->getDoctrine()->getRepository('App:Medidas')->findBy(array('nombre'=>$parameter_med));
  1019.             $medidaspa=$this->getDoctrine()->getRepository('App:Medidas')->createQueryBuilder('m')
  1020.                 ->select('m.id')
  1021.                 ->where('m.nombre like :nombremedidas')
  1022.                 ->setParameter('nombremedidas','%'.$parameter_med.'%');
  1023.              if($cat){
  1024.                  $medidaspa=$medidaspa->leftJoin('m.categoria','cat')
  1025.                  ->andWhere('cat.id = :catid')
  1026.                      ->setParameter('catid',$cat->getId());
  1027.              }
  1028.             $medidaspa$medidaspa->groupBy('m.id')->getQuery()
  1029.                 ->getArrayResult();
  1030.             foreach ($medidaspa as $result) {
  1031.                array_push($medidaparameter,$result['id']);
  1032.             }
  1033.         }
  1034.         if($routeName == 'material' ){
  1035.             $cat=$this->getDoctrine()->getRepository('App:Categoria')->findOneBy(array('slug'=>$routeParameters['categoria']));
  1036.             $id_cat=$cat->getId();
  1037.             $material=$this->getDoctrine()->getRepository('App:Material')->findOneBy(array('nombre'=>$routeParameters['material']));
  1038.         }
  1039.         if($id_cat) {
  1040.             $categoria $this->getDoctrine()->getRepository('App:Categoria')->find($id_cat);
  1041.             $subcategorias $this->qi->getSubCategoriasConProductos($id_cat);
  1042.             if($id_cat != 6){
  1043.                 $query $query->leftJoin('s.categoria','c')
  1044.                 ->andWhere('c.id = :cat')
  1045.                 ->setParameter('cat',$id_cat);
  1046.             }          
  1047.             $titulo $categoria->getNombre();
  1048.         }else if($id_sub){
  1049.             $subcategoria $this->getDoctrine()->getRepository('App:Subcategoria')->find($id_sub);
  1050.             $categoria $subcategoria->getCategoria();
  1051.             $id_cat=$categoria->getId();
  1052.             $subcategorias $this->qi->getSubCategoriasConProductos($id_cat);
  1053.             $query $query->andWhere('s.id = :sub')
  1054.                 ->setParameter('sub',$id_sub);
  1055.             $titulo $subcategoria->getNombre();
  1056.         }else{
  1057.             $subcategoria null;
  1058.             $categoria null;
  1059.             $subcategorias = [];
  1060.         }
  1061.         $preciomin $request->query->get('preciomin',"");
  1062.         $preciomax $request->query->get('preciomax',"");
  1063.         $preciomin_mobile $request->query->get('preciomin_mobile',"");
  1064.         $preciomax_mobile $request->query->get('preciomax_mobile',"");
  1065.         $medida $request->query->get('medida',"");
  1066.         $tipologia $request->query->get('tipologia',"");
  1067.         if($request->get('search')) {
  1068.             $search $request->get('search',"");
  1069.             $prods_alg false;
  1070.             $em $this->getDoctrine()->getManagerForClass(Producto::class);
  1071.             $prods_alg $this->searchService->rawSearch(Producto::class, $search)['hits'];
  1072.             $query $query
  1073.                 ->andWhere('p.plu in (:idsalg)')
  1074.                 ->setParameter('idsalg',array_column($prods_alg,'plu'));
  1075.         }
  1076.         $tecnologias = array();
  1077.         $tipologias = array();
  1078.         $adaptabilidades = array();
  1079.         $independencias = array();
  1080.         $gammas = array();
  1081.         $medidas = array();
  1082.         $filtros = array(
  1083.             "Tipología" => $tipologias,
  1084.             "Medida" => $medidas
  1085.         );
  1086.         $plus $query->getQuery()->getArrayResult();
  1087.         $user $this->getUser();
  1088.         if($user && $user->getConvenio())
  1089.             $convenio $user->getConvenio();
  1090.         else{
  1091.             $convenio $this->getDoctrine()->getRepository(ListaPrecios::class)->find(1);
  1092.         }
  1093.         // consulta productos
  1094.         $productos=[];
  1095.         $productospadres $this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  1096.             ->select('pa.plu,pa.slug, pa.nombre, pa.resumen , pa.imagen, pa.tamanio, pa.tecnologia, pa.tipologia, pa.adaptabilidad, pa.independencia,pa.gamma,
  1097.             pa.color_texto,pa.descuento ,pa.alt,pa.tela,pa.maestro,pa.principal,pa.visible,pa.orden,pa.dctoic,pa.incarrito,
  1098.                         me.nombre as medida, mat.nombre as material, l.precio')
  1099.             ->leftJoin('p.padre','pa')
  1100.             ->leftJoin('pa.listas','l')
  1101.             ->leftJoin('l.lista','li')
  1102.             ->leftJoin('pa.medidas','me')
  1103.                 ->leftJoin('pa.material','mat')
  1104.             ->Where('p.plu in (:ids)')
  1105.             ->andWhere('pa is not null')
  1106.             ->setParameter('ids',array_column($plus,'plu'))
  1107.             ->andWhere('li.id = :l_id')
  1108.              ->setParameter('l_id',$convenio->getId());
  1109.         $productosunicos=$this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  1110.         ->select('p.plu, p.slug,p.nombre, p.resumen , p.imagen, p.tamanio, p.tecnologia, p.tipologia, p.adaptabilidad, p.independencia,p.gamma,
  1111.             p.color_texto,p.descuento ,p.alt,p.tela,p.maestro,p.principal,p.visible,p.orden,p.dctoic,p.incarrito,
  1112.                         me.nombre as medida, mat.nombre as material, l.precio,pa.visible padre_visible, pa.plu padre_id')
  1113.         ->leftJoin('p.padre','pa')
  1114.         ->leftJoin('p.listas','l')
  1115.         ->leftJoin('l.lista','li')
  1116.         ->leftJoin('p.medidas','me')
  1117.         ->leftJoin('p.material','mat')
  1118.         ->Where('p.plu in (:ids)')
  1119.             ->andWhere("(p.padre is null and p.visible = 1) or (pa.visible = 1)")
  1120.        // ->andWhere('p.padre is null')
  1121.         ->setParameter('ids',array_column($plus,'plu'))
  1122.             ->andWhere('li.id = :l_id')
  1123.             ->setParameter('l_id',$convenio->getId());
  1124.         /*$productos = $this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  1125.         ->select(
  1126.         'DISTINCT (CASE WHEN p.padre is not null THEN pa.plu ELSE p.plu END) AS plu',
  1127.                 'CASE WHEN p.padre is not null THEN pa.slug ELSE p.slug END AS slug',
  1128.                 'CASE WHEN p.padre  is not null  THEN pa.nombre ELSE p.nombre END AS nombre',
  1129.                 'CASE WHEN p.padre  is not null  THEN pa.resumen ELSE p.resumen END AS resumen',
  1130.                 'CASE WHEN p.padre  is not null  THEN pa.imagen ELSE p.imagen END AS imagen',
  1131.                 'CASE WHEN p.padre  is not null  THEN pa.tamanio ELSE p.tamanio END AS tamanio',
  1132.                 'CASE WHEN p.padre  is not null  THEN me.nombre ELSE me.nombre END AS medida',
  1133.                 'CASE WHEN p.padre  is not null  THEN mat.nombre ELSE me.nombre END AS material',
  1134.                 'CASE WHEN p.padre  is not null  THEN pa.tecnologia ELSE p.tecnologia END AS tecnologia',
  1135.                 'CASE WHEN p.padre  is not null  THEN pa.tipologia ELSE p.tipologia END AS tipologia',
  1136.                 'CASE WHEN p.padre  is not null  THEN pa.adaptabilidad ELSE p.adaptabilidad END AS adaptabilidad',
  1137.                 'CASE WHEN p.padre  is not null  THEN pa.independencia ELSE p.independencia END AS independencia',
  1138.                 'CASE WHEN p.padre  is not null  THEN pa.gamma ELSE p.gamma END AS gamma',
  1139.                 'CASE WHEN p.padre  is not null  THEN pa.color_texto ELSE p.color_texto END AS color_texto',
  1140.                 'CASE WHEN p.padre  is not null  THEN pa.descuento ELSE p.descuento END AS descuento',
  1141.                 'CASE WHEN p.padre  is not null  THEN pa.alt ELSE p.alt END AS alt',
  1142.                 'CASE WHEN p.padre  is not null  THEN pa.tela ELSE p.tela END AS tela',
  1143.                 'CASE WHEN p.padre  is not null  THEN pa.maestro ELSE p.maestro END AS maestro',
  1144.                 'CASE WHEN p.padre  is not null  THEN pa.principal ELSE p.principal END AS principal',
  1145.                 'CASE WHEN p.padre  is not null  THEN pa.visible ELSE p.visible END AS visible',
  1146.                  'CASE WHEN p.padre  is not null  THEN pa.orden ELSE p.orden END AS orden',
  1147.                 'CASE WHEN p.dctoic  is not null  THEN pa.dctoic ELSE pa.dctoic END AS dctoic',
  1148.                 'CASE WHEN p.incarrito  is not null  THEN pa.incarrito ELSE pa.dctoic END AS incarrito',
  1149.                  'CASE WHEN p.padre  is not null  THEN lipadre.id ELSE l.id END AS lista',
  1150.                  'CASE WHEN p.padre  is not null  THEN lpadre.precio ELSE l.precio END AS precio')
  1151.         ->leftJoin('p.padre','pa')
  1152.         ->leftJoin('p.listas','l')
  1153.         ->leftJoin('l.lista','li')
  1154.         ->leftJoin('pa.listas','lpadre')
  1155.         ->leftJoin('lpadre.lista','lipadre')
  1156.         ->leftJoin('p.medidas','me')
  1157.         ->leftJoin('p.material','mat')
  1158.         ->Where('p.plu in (:ids)')
  1159.         ->setParameter('ids',array_column($plus,'plu'));
  1160.         //->andWhere('li.id = :l_id or lipadre.id =:l_id')
  1161.         //->setParameter('l_id',$convenio->getId());*/
  1162.         if($preciomin){
  1163.             $productospadres->andWhere('l.precio >='.$preciomin);
  1164.             $productosunicos->andWhere('l.precio >='.$preciomin);
  1165.         }
  1166.         if($preciomin_mobile){
  1167.             $productospadres->andWhere('l.precio >='.$preciomin_mobile);
  1168.             $productosunicos->andWhere('l.precio >='.$preciomin_mobile);
  1169.         }
  1170.         if($preciomax){
  1171.             $productospadres->andWhere('l.precio <='.$preciomax);
  1172.             $productosunicos->andWhere('l.precio <='.$preciomax);
  1173.         }
  1174.         if($preciomax_mobile){
  1175.             $productospadres->andWhere('l.precio <='.$preciomax_mobile);
  1176.             $productosunicos->andWhere('l.precio <='.$preciomax_mobile);
  1177.         }
  1178.         if($id_cat){
  1179.             if($id_cat==6){
  1180.                 $productosunicos->andwhere('p.padre is null');
  1181.             }
  1182.             $productospadres->leftJoin('pa.categorias','c')
  1183.                 ->andWhere('c.id = '.$id_cat);
  1184.             $productosunicos->leftJoin('p.categorias','c')
  1185.             ->andWhere('c.id = '.$id_cat);
  1186.         }
  1187.         if ($id_sub){
  1188.              $productospadres->leftJoin('pa.subcategoria','sub')
  1189.                 ->andWhere('sub.id = '.$id_sub);
  1190.             $productosunicos->leftJoin('p.subcategoria','sub')
  1191.             ->andWhere('sub.id = '.$id_sub);
  1192.         }
  1193.         if(count($medidaparameter)>0){
  1194.             $productospadres=$productospadres->andWhere($productospadres->expr()->in('me.id',$medidaparameter));
  1195.             $productosunicos=$productosunicos->andWhere($productosunicos->expr()->in('me.id',$medidaparameter));
  1196.             //$productospadres->andWhere("me.id = '".$medidaparameter->getId()."'");
  1197.            // $productosunicos->andWhere("me.id = '".$medidaparameter->getId()."'");
  1198.         }
  1199.         /*
  1200.         $productospadres=$productospadres->orderBy('pa.orden', 'asc')
  1201.             ->groupby('pa.maestro')
  1202.             ->getQuery()->getSQL();
  1203.         $productosunicos=$productosunicos->orderBy('p.orden', 'asc')
  1204.             ->groupby('p.maestro')
  1205.             ->getQuery()
  1206.         ->getSQL();
  1207.         dd($productospadres,$productosunicos);
  1208.         */
  1209.         if($material){
  1210.             $productospadres->andWhere("mat.nombre like '".$material->getNombre()."'");
  1211.             $productosunicos->andWhere("mat.nombre like '".$material->getNombre()."'");
  1212.         }
  1213.         if($tipologia){
  1214.             /*$productos->andWhere('p.tipologia = :tipologia')
  1215.                 ->setParameter('tipologia',$tipologia);*/
  1216.             $tipologiasel=explode(',',$tipologia);
  1217.             $busquedatipo='';
  1218.             foreach($tipologiasel as $key=>$tipo){
  1219.                 $busquedatipo.="p.tipologia like '".$tipo."'";
  1220.                 if($key<(count($tipologiasel)-1)){
  1221.                     $busquedatipo.=" OR ";
  1222.                 }
  1223.             }
  1224.             $productospadres->andWhere($busquedatipo);
  1225.             $productosunicos->andWhere($busquedatipo);
  1226.         }
  1227.         if($medida){
  1228.             $medidassele=explode(',',$medida);
  1229.             $medidascarga=$this->getDoctrine()->getRepository('App:Medidas')->createQueryBuilder('m')
  1230.                 ->select('m.id');
  1231.             $medidascarga->where($medidascarga->expr()->in('m.nombre',$medidassele));
  1232.             if($cat){
  1233.                 $medidascarga=$medidascarga->leftJoin('m.categoria','cat')
  1234.                     ->andWhere('cat.id = :catid')
  1235.                     ->setParameter('catid',$cat->getId());
  1236.             }
  1237.             $medidascarga$medidascarga->groupBy('m.id')->getQuery()
  1238.                 ->getArrayResult();
  1239.             foreach ($medidascarga as $result) {
  1240.                 array_push($medidassel,$result['id']);
  1241.             }
  1242.             /*$productos->andWhere('p.medida = :medida')
  1243.                 ->setParameter('medida',$medida);*/
  1244.             /*$busquedasel='';
  1245.             foreach($medidassel as $key=>$me){
  1246.                 $busquedasel.="p.medida like '".$me."'";
  1247.                 if($key<(count($medidassel)-1)){
  1248.                     $busquedasel.=" OR ";
  1249.                 }
  1250.             }*/
  1251.             if(count($medidassel)>0) {
  1252.                 $productospadres->andWhere($productospadres->expr()->in('me.id'$medidassel));
  1253.                 $productosunicos->andWhere($productosunicos->expr()->in('me.id'$medidassel));
  1254.             }
  1255.         }
  1256.         $productospadres=$productospadres->orderBy('pa.orden''asc')
  1257.         ->groupby('pa.maestro')
  1258.             ->getQuery()
  1259.         ->getArrayResult();
  1260.         $productosunicos=$productosunicos->orderBy('p.orden''asc')
  1261.             ->groupby('p.maestro')
  1262.             ->getQuery()
  1263.             ->getArrayResult();
  1264.         $productos=[];
  1265.         foreach ($productospadres as $productopadre){
  1266.             $productos[$productopadre['plu']]=$productopadre;
  1267.         }
  1268.         foreach ($productosunicos as $productosunico){
  1269.             $productos[$productosunico['plu']]=$productosunico;
  1270.         }
  1271.         //$productos=array_merge($productospadres,$productosunicos);
  1272.         //$productos =array_map("unserialize", array_unique(array_map("serialize", $productos)));
  1273.         $maxprecio $this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  1274.             ->select('Max(l.precio) as precio')
  1275.             ->leftJoin('p.listas','l')
  1276.             ->leftJoin('l.lista','li')
  1277.             ->leftJoin('p.medidas','me')
  1278.             ->leftJoin('p.material','mat')
  1279.             ->where('p.visible=1')
  1280.             ->andWhere('li.id = :l_id')
  1281.             ->setParameter('l_id',$convenio->getId());
  1282.          if($id_cat){
  1283.           $maxprecio->leftJoin('p.categorias','c')
  1284.              ->andWhere('c.id = '.$id_cat);
  1285.         }
  1286.         if ($id_sub){
  1287.             $maxprecio->leftJoin('p.subcategoria','sub')
  1288.                 ->andWhere('sub.id = '.$id_sub);
  1289.         }
  1290.         if(count($medidaparameter)>0){
  1291.             $maxprecio=$maxprecio->andWhere($maxprecio->expr()->in('me.id',$medidaparameter));
  1292.             //$maxprecio->andWhere("me.nombre like '".$medidaparameter->getNombre()."'");
  1293.         }
  1294.         if($material){
  1295.             $maxprecio->andWhere("mat.nombre like '".$material->getNombre()."'");
  1296.         }
  1297.         $maxprecio=$maxprecio->setMaxResults(1)
  1298.             ->getQuery()
  1299.             ->getOneOrNullResult();
  1300.         $minprecio $this->getDoctrine()->getRepository('App:Producto')->createQueryBuilder('p')
  1301.             ->select('Min(l.precio) as precio')
  1302.             ->leftJoin('p.listas','l')
  1303.             ->leftJoin('l.lista','li')
  1304.             ->leftJoin('p.medidas','me')
  1305.             ->leftJoin('p.material','mat')
  1306.             ->where('p.visible=1')
  1307.             ->andWhere('li.id = :l_id')
  1308.             ->setParameter('l_id',$convenio->getId());
  1309.         if($id_cat){
  1310.             $minprecio->leftJoin('p.categorias','c')
  1311.                 ->andWhere('c.id = '.$id_cat);
  1312.         }
  1313.         if ($id_sub){
  1314.             $minprecio->leftJoin('p.subcategoria','sub')
  1315.                 ->andWhere('sub.id = '.$id_sub);
  1316.         }
  1317.         if(count($medidaparameter)>0){
  1318.             $minprecio=$minprecio->andWhere($minprecio->expr()->in('me.id',$medidaparameter));
  1319.             //$minprecio->andWhere("me.nombre like '".$medidaparameter->getNombre()."'");
  1320.         }
  1321.         if($material){
  1322.             $minprecio->andWhere("mat.nombre like '".$material->getNombre()."'");
  1323.         }
  1324.         $minprecio=$minprecio->setMaxResults(1)
  1325.             ->getQuery()
  1326.             ->getOneOrNullResult();
  1327.         $precios=[];
  1328.         foreach ($productos as $producto){
  1329.             $precios[]=$producto['precio'];
  1330.         }
  1331.         if($precios != null ){
  1332.             if(count($maxprecio)>0){
  1333.                 $preciomax=round($maxprecio['precio']);
  1334.             }else{
  1335.                 $preciomax=max($precios);
  1336.             }
  1337.             if(count($maxprecio)>0){
  1338.                 $preciomin=round($minprecio['precio']);
  1339.             }else{
  1340.                 $preciomin=min($precios);
  1341.             }
  1342.         }
  1343.         if($precios != null ){
  1344.             if(count($maxprecio)>0){
  1345.                 $preciomax_mobile=round($maxprecio['precio']);
  1346.             }else{
  1347.                 $preciomax_mobile=max($precios);
  1348.             }
  1349.             if(count($maxprecio)>0){
  1350.                 $preciomin_mobile=round($minprecio['precio']);
  1351.             }else{
  1352.                 $preciomin_mobile=min($precios);
  1353.             }
  1354.         }
  1355.         $hermanos = [];
  1356.         $medidas = [];
  1357.         $tipologias=[];
  1358.         foreach ($productos as $producto){
  1359.             $hermanos $this->getDoctrine()->getRepository(Producto::class)->createQueryBuilder('p')
  1360.                 ->select('p.principal','p.plu''p.medida''p.nombre''p.tamanio''p.maestro','me.nombre as medida_real','me.id')
  1361.                 ->leftJoin('p.medidas','me')
  1362.                 ->where('me is not null')
  1363.                 ->andWhere('p.maestro = :maestro')
  1364.                 // ->andWhere('p.visible = 1')
  1365.                 ->setParameter('maestro',$producto['maestro'])
  1366.                 ->orderBy('p.medida','asc')
  1367.                 ->getQuery()
  1368.                 ->getResult();
  1369.             foreach ($hermanos as $hermano){
  1370.                 /* @var $producto Producto */  
  1371.        
  1372.                 $medidas[$hermano['medida_real']] = array("nombre" => $hermano['medida_real'], "checked"=>$this->isChecked($request,'medida_real',$hermano['medida_real']) );
  1373.                 if(count($medidassel)>0){
  1374.                     if(in_array($hermano['id'],$medidassel)) {
  1375.                         $medidas[$hermano['medida_real']] = array("nombre" => $hermano['medida_real'], "checked"=>true);
  1376.                     }
  1377.                 }
  1378.                 if($parameter_med){
  1379.                     if(count($medidaparameter)>0){
  1380.                          if(in_array($hermano['id'],$medidaparameter)) {
  1381.                              $medidas[$hermano['medida_real']] = array("nombre" => $hermano['medida_real'], "checked"=>true);
  1382.                          }
  1383.                     }
  1384.                 }
  1385.             }
  1386.         }
  1387.         foreach ($productos as $producto){
  1388.             /* @var $producto Producto */
  1389.             $tecs explode('/'$producto['tecnologia']);
  1390.             foreach ($tecs as $tec){
  1391.                 $tec trim($tec);
  1392.                 $tecnologias[$tec] = array("nombre"=>$tec"checked"=>$this->isChecked($request,'tecnologia',$tec));
  1393.             }
  1394.             $tipologias[$producto['tipologia']] = array("nombre" => $producto['tipologia'], "checked"=>$this->isChecked($request,'tipologia',$producto['tipologia']));
  1395.             if(!array_key_exists($producto['medida'],$medidas))
  1396.                 $medidas[$producto['medida']] = array("nombre" => $producto['medida'], "checked"=>$this->isChecked($request,'medida',$producto['medida']));
  1397.             $adaptabilidades[$producto['adaptabilidad']] = array("nombre" => $producto['adaptabilidad'], "checked"=>$this->isChecked($request,'adaptabilidad',$producto['adaptabilidad']));
  1398.             $independencias[$producto['independencia']] = array("nombre" => $producto['independencia'], "checked"=>$this->isChecked($request,'independencia',$producto['independencia']));
  1399.             $gammas[$producto['gamma']] = array("nombre" => $producto['gamma'], "checked"=>$this->isChecked($request,'gamma',$producto['gamma']));
  1400.         }
  1401.         
  1402.         $filtros = array(
  1403.             "Medida" => $medidas,
  1404.             "Tipología" => $tipologias,
  1405.         );
  1406.         $idcategoria=null;
  1407.         if($categoria){
  1408.             $idcategoria=$categoria->getid();
  1409.         }
  1410.         $em $this->getDoctrine()->getManager();
  1411.         // cod dcto solo al agregar al carrito
  1412.         $cods $this->getDoctrine()->getRepository(CodigoDescuento::class)->createQueryBuilder('c')
  1413.                 ->select('p.nombre','p.plu')
  1414.                 ->leftJoin('c.productos','p')
  1415.                 ->where('c.incarrito = true')
  1416.                 ->andWhere('c.activo = true')
  1417.                 ->getQuery()
  1418.                 ->getResult();
  1419.         foreach($productos as $p){
  1420.             foreach($cods as $pc){
  1421.                 $pp=$p['plu'];
  1422.                 $codss=$pc['plu'];
  1423.                 if($pp == $codss){
  1424.                     $prod $this->getDoctrine()->getRepository(Producto::class)->find(array('plu'=>$p['plu']));
  1425.                     $prod->setIncarrito(true);
  1426.                     $em->persist($prod);
  1427.                     $em->flush();
  1428.                 }else{
  1429.                     $prod $this->getDoctrine()->getRepository(Producto::class)->find(array('plu'=>$p['plu']));
  1430.                     $prod->setIncarrito(false);
  1431.                     $em->persist($prod);
  1432.                     $em->flush();
  1433.                 }
  1434.             }
  1435.         }
  1436.         if($categoria && $categoria->getId() == 6){
  1437.             return $this->render('basic/promocionesIng.html.twig', [
  1438.                 'principal'=> $categoria,
  1439.                 'idprincipal'=> $idcategoria,
  1440.                 'productos' => $productos,
  1441.                 'subcategorias' => $subcategorias,
  1442.                 'titulo' => $titulo,
  1443.                 'plus' => $plus,
  1444.                 'cant' => count($productos),
  1445.             ]);
  1446.         }
  1447.         $referencia=null;
  1448.         if($id_sub != null){
  1449.             $referencia=$id_sub;
  1450.         }
  1451.         $idcategoria=null;
  1452.         if($categoria){
  1453.             $idcategoria=$categoria->getid();
  1454.         }
  1455.         return $this->render('basic/buscador.html.twig', [  
  1456.             'principal'=> $categoria,
  1457.             'idprincipal'=> $idcategoria,
  1458.             'productos' => $productos,
  1459.             'preciomaximo' => $preciomax ,
  1460.             'preciominimo' => $preciomin,   
  1461.             'preciomaximo_mobile' => $preciomax_mobile,
  1462.             'preciominimo_mobile' => $preciomin_mobile,         
  1463.             'subcategorias' => $subcategorias,
  1464.             'titulo' => $titulo,
  1465.             'plus' => $plus,
  1466.             'cant' => count($productos),
  1467.             'filtros' => $filtros,
  1468.             'idsubcategoria' => $id_sub,
  1469.             'referencia'=>$referencia,
  1470.             'subcategoria'=>$subcategoria
  1471.         ]);
  1472.     }
  1473.     private function isChecked(Request $request,$tipo,$valor){
  1474.         $qi $this->qi;
  1475.         $tipo $qi->slugify($tipo);
  1476.         $campos explode(',',$request->get($tipo));
  1477.         // dd('request in isChecked ',$tipo,$campos,$request,in_array($valor, $campos));
  1478.         return in_array($valor$campos);
  1479.     }
  1480.     /**
  1481.      * @param Request $request
  1482.      * @param $tipos
  1483.      * @param $columnas
  1484.      * @param $query
  1485.      * @return Query
  1486.      */
  1487.     private function getQueryFilter(Request $request,$tipos$columnas$query){
  1488.         $qi $this->qi;
  1489.         $keys = [];
  1490.         $i 0;
  1491.         foreach ($tipos as $key=>$val){
  1492.             $tipo $qi->slugify($key);
  1493.             if($request->get($tipo)){
  1494.                 $campos explode(',',$request->get($tipo));
  1495.                 $cad = [];
  1496.                 if(count($campos) > 0){
  1497.                     foreach ($campos as $j=>$campo){
  1498.                         array_push($cad,'p.'.$columnas[$i].' like :query_'.$columnas[$i].'_'.$j.' ');
  1499.                         $query->setParameter('query_'.$columnas[$i].'_'.$j,'%'.$campo.'%');
  1500.                     }
  1501.                     $query->andWhere(implode($cad,' or '));
  1502.                 }
  1503.             }
  1504.             $i++;
  1505.         }
  1506.         return $query;
  1507.     }
  1508.     /**
  1509.      * @Route("/producto/{id}/{tiendaId}", name="producto_old")
  1510.      */
  1511.     public function producto_old(Request $request$id,$tiendaId)
  1512.     {
  1513.         $tienda $this->getDoctrine()->getRepository('App:Tienda')->find($tiendaId);
  1514.         $productos $this->getDoctrine()->getManager()->createQueryBuilder()
  1515.             ->from('App:Inventario','i')
  1516.             ->select('i')
  1517.             ->leftJoin('i.producto','p')
  1518.             ->addSelect('p')
  1519.             ->leftJoin('p.categorias','c')
  1520.             ->addSelect('c')
  1521.             ->where('i.tienda = :tienda')
  1522.             ->addSelect(
  1523.                 'CASE WHEN p.nombreComercial is not null and p.nombreComercial <> \'\' THEN p.nombreComercial ELSE p.nombre END AS nombrePublico')
  1524.             ->andWhere('i.cantidad > 0')
  1525.             ->andWhere('p.plu = :id')
  1526.             ->setParameter('tienda',$tienda)
  1527.             ->setParameter('id',$id)
  1528.             ->getQuery()
  1529.             ->getArrayResult();
  1530.         return $this->render('basic/producto.html.twig', [
  1531.             'producto' => $productos[0]
  1532.         ]);
  1533.     }
  1534.     /**
  1535.      * @Route("/producto/{id}", name="producto")
  1536.      */
  1537.     public function producto(Request $request$id)
  1538.     {
  1539.         $tienda $this->qi->getTienda();
  1540.         if(!$tienda)
  1541.             return $this->redirectToRoute('misdirecciones');
  1542.         $producto $this->getDoctrine()->getRepository('App:Producto')->find($id);
  1543.         $inv $this->getDoctrine()->getRepository('App:Inventario')->findOneBy(array('producto'=>$producto,'tienda'=>$tienda));
  1544.         $cant 0;
  1545.         if($inv)
  1546.             $cant $inv->getCantidad();
  1547.         //dd($tienda,$inv);
  1548.         return $this->render('basic/producto.html.twig', [
  1549.             'producto' => $producto,
  1550.             'cantidad' => $cant
  1551.         ]);
  1552.     }
  1553.     /**
  1554.      * @Route("/add-to-carrito/romance/add-to-carrito", name="add-to-carrito")
  1555.      */
  1556.     public function addtocarrito(Request $request)
  1557.     {
  1558.         $body json_decode($request->getContent()); 
  1559.         $mensaje=array('ok' => false'mensaje' => "Ha ocurrido un error");
  1560.         // if($body->cantidad > 0){
  1561.             if($this->qi->addCantToCar($body->producto,$body->cantidad,$body->wish)) {
  1562.                 $mensaje = array('ok' => true'mensaje' => "Agregado al carrito ",'carrito'=>count($this->qi->getCarrito()));
  1563.                 if ($body->wish) {
  1564.                     $mensaje = array('ok' => true'mensaje' => "Agregado al wish list");
  1565.                 }
  1566.             }
  1567.         // }else{
  1568.         //     $this->qi->deleteItemFromCar($body->producto,$body->wish);
  1569.         //     $mensaje = array('ok' => true, 'mensaje' => "Eliminado del carrito");            
  1570.         // }       
  1571.         $response = new Response();
  1572.         $response->setContent(json_encode($mensaje));
  1573.         $response->headers->set('Content-Type''application/json');
  1574.         // dd($response);
  1575.         return $response;
  1576.     }
  1577.     /**
  1578.      * @Route("/eliminar-carro/{id}", name="eliminar-carro")
  1579.      */
  1580.     public function eliminarDeCarro(Request $request,$id)
  1581.     {
  1582.         $this->qi->deleteItemFromCar($id,"");
  1583.         return $this->redirectToRoute('carrito');
  1584.     }
  1585.     /**
  1586.      * @Route("/cambiar-cantidad/{id}/{cantidad}", name="cambiar-cantidad")
  1587.      */
  1588.     public function cambiarCantidad(Request $request,$id,$cantidad)
  1589.     {
  1590.         if($cantidad 0) {
  1591.             $this->qi->addItemToCar($id$cantidad"");
  1592.         }
  1593.         else{
  1594.             $this->qi->deleteItemFromCar($id,  "");
  1595.         }
  1596.         return $this->redirectToRoute('carrito');
  1597.     }
  1598.     // /**
  1599.     //  * @Route("/carrito/romance/carrito", name="carrito")
  1600.     //  */
  1601.     // public function carrito(Request $request)
  1602.     // {
  1603.     //     $session = $request->getSession();
  1604.     //     $mostre_en_carrito = $session->get('cierre_carrito','0') == '1';
  1605.     //     $session->set('cierre_carrito','1');
  1606.     //     $ok = true;
  1607.     //     if($request->get('ok') != null ){
  1608.     //         $ok = $request->get('ok');
  1609.     //     }
  1610.     //     if(!$this->qi->getDireccion()){
  1611.     //         $this->addFlash(
  1612.     //             'warning',
  1613.     //             'Debes seleccionar una dirección antes de continuar'
  1614.     //         );
  1615.     //         return $this->redirectToRoute('misdirecciones');
  1616.     //     }
  1617.     //     /* @var $user Usuario */
  1618.     //     $user = $this->getUser();
  1619.     //     if(!$user->getNombre() || !$user->getApellido() || !$user->getCelular() || !$user->getDocumento())
  1620.     //     {
  1621.     //         $this->addFlash(
  1622.     //             'warning',
  1623.     //             'Debes actualizar tus datos para continuar con la compra.'
  1624.     //         );
  1625.     //         return $this->redirectToRoute('perfil');
  1626.     //     }
  1627.     //     if(!$this->qi->getTienda()){
  1628.     //         $tienda = $this->qi->getTiendaFromCoordinates($this->qi->getDireccion());
  1629.     //         $this->qi->setTienda($tienda);
  1630.     //         if(!$tienda){
  1631.     //             $this->addFlash(
  1632.     //                 'warning',
  1633.     //                 'La dirección seleccionada no tiene cobertura en este momento'
  1634.     //             );
  1635.     //             return $this->redirectToRoute('misdirecciones');
  1636.     //         }
  1637.     //     }
  1638.     //     $noDisp = $this->qi->validarCarrito();
  1639.     //     if(count($noDisp) ){
  1640.     //         $this->addFlash(
  1641.     //             'warning',
  1642.     //             'Algunos productos de tu carrito han sido eliminados ya que en la tienda actual no hay disponibilidad'
  1643.     //         );
  1644.     //     }
  1645.     //     $productos = $this->getDoctrine()->getRepository('App:Producto')->
  1646.     //     findBy(array('visible'=>true),array('orden'=>'desc'),7, rand(1,1500));
  1647.     //     return $this->render('basic/carrito.html.twig', [
  1648.     //         'productos' => $productos,
  1649.     //         'ok'=>$ok,
  1650.     //         'mostre_en_carrito' => $mostre_en_carrito
  1651.     //     ]);
  1652.     // }
  1653.     /**
  1654.      * @Route("/resumen_pedido/{id}", name="resumen_pedido")
  1655.      */
  1656.     public function resumenPedido(Request $request,$id)
  1657.     {
  1658.         /* @var Compra $compra*/
  1659.         $compra $this->getDoctrine()->getRepository(Compra::class)->find($id);
  1660.         $productos $compra->getProductosObj();
  1661.         return $this->render('basic/resumen.html.twig', [
  1662.             'productos' => $productos,
  1663.             'compra' => $compra
  1664.         ]);
  1665.     }
  1666.     /**
  1667.      * @Route("/pedido_respuesta/romance/pedido_respuesta", name="pedido_respuesta")
  1668.      */
  1669.     public function pedido_respuesta(Request $request)
  1670.     {
  1671.         $ok true;
  1672.         if($request->get('ok') != null ){
  1673.             $ok $request->get('ok');
  1674.         }
  1675.         if(!$this->qi->getDireccion()){
  1676.             return $this->redirectToRoute('misdirecciones');
  1677.         }
  1678.         if(!$this->qi->getTienda()){
  1679.             return $this->redirectToRoute('tienda');
  1680.         }
  1681.         return $this->render('basic/pedido_respuesta.html.twig', [
  1682.             'ok'=>$ok
  1683.         ]);
  1684.     }
  1685.     // /**
  1686.     //  * @Route("/mapa_tiendas/romance/mapa_tiendas", name="mapaTiendas")
  1687.     //  */
  1688.     // public function mapaTiendas(Request $request)
  1689.     // {
  1690.     //     $tiendas = $this->getDoctrine()->getRepository(Tienda::class)->findBy(array('visible'=>true));
  1691.     //     return $this->render('basic/mapaTiendas.html.twig', [
  1692.     //         'tiendas' => $tiendas,
  1693.     //         'idprincipal' => $idprincipal=null
  1694.     //     ]);
  1695.     // }
  1696.     /**
  1697.      * @Route("/direccion/romance/direccion", name="direccion")
  1698.      */
  1699.     public function direccion(Request $request)
  1700.     {
  1701.         $productos $this->getDoctrine()->getRepository('App:Producto')->
  1702.         findBy(array('visible'=>true),array('orden'=>'desc'),7rand(1,1500));
  1703.         return $this->render('basic/direccion.html.twig', [
  1704.             'productos' => $productos,
  1705.             'idprincipal' => $idprincipal=null
  1706.         ]);
  1707.     }
  1708.     /**
  1709.      * @Route("/confirmacion/romance/confirmacion", name="confirmacion")
  1710.      */
  1711.     public function confirmation(Request $request)
  1712.     {
  1713.         $respuesta $request->get('obj');
  1714.         $compra $this->getDoctrine()->getRepository(Compra::class)->find($respuesta["compra"]["id"]);
  1715.         $productos $this->qi->getCarrito();
  1716.         $this->qi->clearCar("");
  1717.         return $this->render('basic/pedido_respuesta.html.twig', [
  1718.             'productos' => $productos,
  1719.             'compra' => $compra,
  1720.             'ok' => $request->get("ok"),
  1721.             'idprincipal' => $idprincipal=null
  1722.         ]);
  1723.     }
  1724.     /**
  1725.      * @Route("/ingresar/romance/ingresar", name="ingresar")
  1726.      */
  1727.     public function ingresar(Request $request)
  1728.     {
  1729.         $errores = [];
  1730.         $last_username '';
  1731.         /*if($request->isMethod('POST')){
  1732.             $datos = $request->request->all();
  1733.             $email = strtolower($datos['_username'] );
  1734.             $last_username = $email;
  1735.             $pass = strtolower($datos['_password'] );
  1736.             try {
  1737.                 $serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/../../miveci-firebase-adminsdk-pteyb-91be53dc7d.json');
  1738.                 $firebase = (new Factory())
  1739.                     ->withServiceAccount($serviceAccount)
  1740.                     ->create();
  1741.                 $auth = $firebase->getAuth();
  1742.                 $fbuser = $auth->getUserByEmail($email);
  1743.                 $user = $this->userManager->findUserBy(array('email'=>$email));
  1744.                 $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
  1745.                 $this->get('security.token_storage')->setToken($token);
  1746.                 $this->get('session')->set('_security_main', serialize($token));
  1747.                 $event = new InteractiveLoginEvent($request, $token);
  1748.                 //$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
  1749.                 $this->eventDispatcher->dispatch("security.interactive_login", $event);
  1750.                 if ($this->get('security.context')->isGranted('ROLE_POS_ADMIN')) {
  1751.                     return $this->redirectToRoute('easyadmin');
  1752.                 }else{
  1753.                     return $this->redirectToRoute('homepage');
  1754.                 }
  1755.             } catch (Firebase\Exception\AuthException $e) {
  1756.                 array_push($errores, $e->getMessage());
  1757.                 //echo($e->getMessage());
  1758.                 //echo(dump($e));
  1759.                 //exit();
  1760.             } catch (Firebase\Exception\FirebaseException $e) {
  1761.                 array_push($errores, $e->getMessage());
  1762.             }
  1763.         }
  1764.         return $this->render('user/login.html.twig', [
  1765.             'errores' => $errores,
  1766.             'last_username' => $last_username,
  1767.             'idprincipal' => $idprincipal=null
  1768.         ]);*/
  1769.     }
  1770.     /**
  1771.      * @Route("/olvide/romance/olvide", name="olvide")
  1772.      */
  1773.     public function olvide(Request $request)
  1774.     {
  1775.         return $this->render('user/olvide.html.twig', [
  1776.             'idprincipal' => $idprincipal=null
  1777.         ]);
  1778.     }
  1779.     /**
  1780.      * @Route("/crear-cuenta/romance/crear-cuenta", name="crear_cuenta")
  1781.      */
  1782.     public function crearCuenta(Request $request)
  1783.     {
  1784.         $errores = [];
  1785.         if($request->isMethod('POST')){
  1786.             $datos $request->request->all();
  1787.             $properties = [
  1788.                 'displayName' => $datos['nombre'] . " " $datos['apellido'] ,
  1789.                 'email' => strtolower($datos['email'] ),
  1790.                 'emailverified' => true
  1791.             ];
  1792.         }
  1793.         return $this->render('user/registro.html.twig', [
  1794.             'errores' => $errores,
  1795.             'idprincipal' => $idprincipal=null
  1796.         ]);
  1797.     }
  1798.     /**
  1799.      * @Route("/load/romance/load", name="load")
  1800.      */
  1801.     public function load(Request $request)
  1802.     {
  1803.         /*
  1804.         $prods = $this->getDoctrine()->getRepository(Inventario::class)->findAll();
  1805.         foreach ($prods as $inv){
  1806.             $this->qi->saveFire($inv);
  1807.         }
  1808.     */
  1809.         // dd(12);
  1810.         //return $this->redirectToRoute('easyadmin');
  1811.         //$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  1812.     }
  1813.     /**
  1814.      * @Route("/preguntas_frecuentes/romance/preguntas_frecuentes", name="preguntas_frecuentes")
  1815.      */
  1816.     public function preguntasFrecuentes(Request $request)
  1817.     {
  1818.         $preguntas $this->getDoctrine()->getRepository(Faq::class)->findBy(array("visible"=>true),array("orden"=>"asc"));
  1819.         return $this->render('basic/preguntas.html.twig', [
  1820.             "preguntas" => $preguntas,
  1821.             'idprincipal' => $idprincipal=null
  1822.         ]);
  1823.     }
  1824.     /**
  1825.      * @Route("/privacidad/romance/privacidad", name="privacidad")
  1826.      */
  1827.     public function privacidad(Request $request)
  1828.     {
  1829.         return $this->render('basic/politica.html.twig', [
  1830.             'llave'=>'politica_privacidad',
  1831.             'titulo'=> 'Políticas de privacidad',
  1832.             'idprincipal' => $idprincipal=null
  1833.         ]);
  1834.     }
  1835.     /**
  1836.      * @Route("/terminos/romance/terminos", name="terminos")
  1837.      */
  1838.     public function terminos(Request $request)
  1839.     {
  1840.         return $this->render('basic/politica.html.twig', [
  1841.             'llave'=>'terminos',
  1842.             'titulo'=> 'Términos y condiciones',
  1843.             'idprincipal' => $idprincipal=null
  1844.         ]);
  1845.     }
  1846.     /**
  1847.      * @Route("/politica/romance/politica", name="politica")
  1848.      */
  1849.     public function politica(Request $request)
  1850.     {
  1851.         return $this->render('basic/politica.html.twig', [
  1852.             'llave'=>'politica_promocion',
  1853.             'titulo'=> 'Políticas de promoción',
  1854.             'idprincipal' => $idprincipal=null
  1855.         ]);
  1856.     }
  1857.     /**
  1858.      * @Route("/politica_promocion/romance/politica_promocion", name="politica_promocion")
  1859.      */
  1860.     public function politicaPromocion(Request $request)
  1861.     {
  1862.         $politicas $this->getDoctrine()->getRepository(PoliticaPromocion::class)->findBy(array("visible"=>true),array("orden"=>"asc"));
  1863.         return $this->render('basic/privacidad.html.twig', [
  1864.             "politicas" => $politicas,
  1865.             'llave'=>'politica_promocion',
  1866.             'titulo'=> 'Políticas de promoción',
  1867.             'idprincipal' => $idprincipal=null
  1868.         ]);
  1869.     }
  1870.     /**
  1871.      * @Route("/politica_entrega/romance/politica_entrega", name="politica_entrega")
  1872.      */
  1873.     public function politicaEntrega(Request $request)
  1874.     {
  1875.         return $this->render('basic/politica.html.twig', [
  1876.             'llave'=>'politica_entrega',
  1877.             'titulo'=> 'Política de entrega y devolución',
  1878.             'idprincipal' => $idprincipal=null
  1879.         ]);
  1880.     }
  1881.     /**
  1882.      * @Route("/ajax-cart/romance/ajax-cart", name="ajax-cart")
  1883.      */
  1884.     public function ajaxCart(Request $request)
  1885.     {
  1886.         return $this->render('cart/ajaxcart.html.twig', [
  1887.             'idprincipal' => $idprincipal=null
  1888.         ]);
  1889.     }
  1890.     /**
  1891.      * @Method({"GET"})
  1892.      * @Route("/api/clientify/create/{id}", name="crear_usuario_clientify")
  1893.      */
  1894.     public function crearUsuarioClientify(Request $request,$id)
  1895.     {
  1896.         $usuario $this->getDoctrine()->getRepository('App:Usuario')->find($id);
  1897.         $this->clientify->CrearContacto($usuario);
  1898.         // dd($usuario);
  1899.     }
  1900.     /**
  1901.      * @Method({"POST"})
  1902.      * @Route("/api/auth/register", name="crear_actualizar_usuario")
  1903.      */
  1904.     public function crearActualizarUsuario(Request $request)
  1905.     {
  1906.         $logged $this->getUser();
  1907.         $um $this->userManager;
  1908.         $body json_decode($request->getContent());
  1909.         // dd($body);
  1910.         /* @var $user Usuario */
  1911.         $user $um->findUserBy(array('uid'=>$body->uid));
  1912.         if(!$user){
  1913.             $user $um->findUserBy(array('email'=>$body->email));
  1914.         }
  1915.         if(!$user){
  1916.             $user $um->createUser();
  1917.             $user->setUid($body->uid);
  1918.             $user->setEmail($body->email);
  1919.             $user->setUsername($body->email);
  1920.             $user->setCelular($body->telefono);
  1921.             $user->setUsernameCanonical($body->email);
  1922.             $user->setProviderData(json_encode($body->providerData));
  1923.             $user->setEnabled(true);
  1924.             $user->setPassword('redes123');
  1925.             $user->setCreatedAt(new \DateTime());
  1926.             // enviar correo de bienvenida
  1927.             // $mensaje = str_replace('%nombre%', '', $this->qi->getTextoBig('mail-bienvenida'));
  1928.             $mensaje $this->renderView('mailing/agradecimiento-registro.html.twig', array(
  1929.                 // 'nombre'=>$user->getNombre(),
  1930.                 'email'=>$user->getEmail(),
  1931.                 // 'telefono'=>$user->getTelefono(),
  1932.                 // 'mensaje'=>$user->getMensaje(),
  1933.             ));
  1934.             $this->qi->sendMail($this->qi->getTexto('asunto_bienvenida'), $body->email,$mensaje);
  1935.             if(property_exists($body,'nombre')){
  1936.                 $user->setNombre($body->nombre);
  1937.             }
  1938.             if(property_exists($body,'apellido')){
  1939.                 $user->setApellido($body->apellido);
  1940.             }
  1941.             if(property_exists($body,'telefono')){
  1942.                 $user->setCelular($body->telefono);
  1943.             }
  1944.             if(property_exists($body,'convenio')){
  1945.                 $convenio $this->getDoctrine()->getRepository('App:ListaPrecios')->findOneBy(array('codigo'=>$body->convenio));
  1946.                 if($convenio)
  1947.                     $user->setConvenio($convenio);
  1948.             }
  1949.             if(property_exists($body,'uid')){
  1950.                 $user->setUid($body->uid);
  1951.             }
  1952.         }
  1953.         $em $this->getDoctrine()->getManager();
  1954.         $em->persist($user);
  1955.         $em->flush();
  1956.         $um->updateUser($user);
  1957.         // dd($user);
  1958.         // clientify
  1959.         $this->clientify->CrearContacto($user);
  1960.         $token = new UsernamePasswordToken($usernull'main'$user->getRoles());
  1961.         $this->get('security.token_storage')->setToken($token);
  1962.         $this->get('session')->set('_security_main'serialize($token));
  1963.         $event = new InteractiveLoginEvent($request$token);
  1964.         //$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
  1965.         $this->eventDispatcher->dispatch("security.interactive_login"$event);
  1966.         if ($this->authorization->isGranted('ROLE_POS_ADMIN')) {
  1967.             $resultado= array("ok"=>true,'obj'=>$user,'url'=> $this->generateUrl('homepage'));
  1968.         }else{
  1969.             if($this->qi->carritoLength() > 0){
  1970.                 if($this->qi->getDireccion())
  1971.                     $ruta $this->generateUrl('carrito');
  1972.                 else
  1973.                     $ruta $this->generateUrl('misdirecciones');
  1974.             }
  1975.             else
  1976.                 $ruta $this->generateUrl('homepage');
  1977.             $resultado= array("ok"=>true,'obj'=>$user,'url'=> $ruta);
  1978.         }
  1979.         $prlogfalse;
  1980.         if($logged){
  1981.             $prlog true;
  1982.         }
  1983.         return new Response(json_encode(array("preloged"=>$prlog,"id"=>$user->getId())));
  1984.     }
  1985.     /**
  1986.      * @Method({"POST"})
  1987.      * @Route("/api/direccion", name="crear_direccion")
  1988.      */
  1989.     public function crearDireccion(Request $request)
  1990.     {
  1991.         $body json_decode($request->getContent());
  1992.         //dd($body);
  1993.         $qi $this->qi;
  1994.         $user $this->getDoctrine()->getRepository(Usuario::class)->findOneBy(array('uid'=>$body->uid));
  1995.         $ciudad $this->getDoctrine()->getRepository(Ciudad::class)->find($body->ciudad->id);
  1996.         $news = new Direccion();
  1997.         $news->setUsuario($user);
  1998.         $news->setNombre($body->nombre);
  1999.         $news->setCiudad($ciudad);
  2000.         $news->setDireccion($body->direccion." ".$body->adicional);
  2001.         $news->setLat($body->lat);
  2002.         $news->setLng($body->lng);
  2003.         $news->setUid($body->uid);
  2004.         $news->setPredeterminada($body->predeterminada);
  2005.         $em $this->getDoctrine()->getManager();
  2006.         $em->persist($news);
  2007.         $em->flush();
  2008.         $qi->saveFire($news);
  2009.         $resultado= array("ok"=>true,'obj'=>$news);
  2010.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  2011.         $normalizer = new ObjectNormalizer();
  2012.         $normalizer->setCircularReferenceLimit(1);
  2013.         // Add Circular reference handler
  2014.         $normalizer->setCircularReferenceHandler(function ($object) {
  2015.             return $object->getId();
  2016.         });
  2017.         $normalizers = array($normalizer);
  2018.         $serializer = new Serializer($normalizers$encoders);
  2019.         $json $serializer->serialize($resultado,'json');
  2020.         return new Response($json);
  2021.     }
  2022.     /**
  2023.      * @Method({"POST"})
  2024.      * @Route("/api/historial/{uid}", name="historial")
  2025.      */
  2026.     public function historial(Request $request,$uid)
  2027.     {
  2028.         //$body = json_decode($request->getContent());
  2029.        // dd($uid);
  2030.         $qi $this->qi;
  2031.         $user $this->getDoctrine()->getRepository(Usuario::class)->findOneBy(array('uid'=>$uid));
  2032.         $compras $this->getDoctrine()->getManager()->createQueryBuilder()
  2033.             ->from('App:Compra','c')
  2034.             ->addSelect('c')
  2035.             ->leftJoin('c.tienda','t')
  2036.             ->addSelect('t')
  2037.             ->leftJoin('c.direccion','d')
  2038.             ->addSelect('d')
  2039.             ->where('c.usuario = :usuario')
  2040.             ->setParameter('usuario',$user)
  2041.             ->getQuery()
  2042.             ->getArrayResult();
  2043.         //dd($compras);
  2044.         $resultado= array("ok"=>true,'historial'=>$compras);
  2045.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  2046.         $normalizer = new ObjectNormalizer();
  2047.         $normalizer->setCircularReferenceLimit(1);
  2048.         // Add Circular reference handler
  2049.         $normalizer->setCircularReferenceHandler(function ($object) {
  2050.             return $object->getId();
  2051.         });
  2052.         $normalizers = array($normalizer);
  2053.         $serializer = new Serializer($normalizers$encoders);
  2054.         $json $serializer->serialize($resultado,'json');
  2055.         return new Response($json);
  2056.     }
  2057.     function crearPedido($user,$direccion,$metodo,$tienda,$costo_domicilio,$comentarios,$peticion,$paga_con,$carrito,$canal){
  2058.         $qi $this->qi;
  2059.         $em $this->getDoctrine()->getManager();
  2060.         $estado $this->getDoctrine()->getRepository(EstadoPedido::class)->findOneBy(array('ref' => 'creado'));
  2061.         $subtotal 0;
  2062.         $total 0;
  2063.         $news = new Compra();
  2064.         $news->setCreatedAt(new \DateTime());
  2065.         $news->setDireccion($direccion);
  2066.         $news->setUsuario($user);
  2067.         $news->setFechaRealProcesamiento(new \DateTime());
  2068.         $news->setEstado($estado);
  2069.         $news->setEstadoProcesamiento("nuevo");
  2070.         $news->setCostoDomicilio($costo_domicilio);
  2071.         $news->setComentarios($comentarios);
  2072.         $news->setBody(json_encode($peticion));
  2073.         $news->setCanal($canal);
  2074.         $news->setMetodo($metodo);
  2075.         $news->setPagaCon($paga_con);
  2076.         $news->setSubtotal($subtotal);
  2077.         $news->setTienda($tienda);
  2078.         $total $subtotal $costo_domicilio;
  2079.         $news->setTotal($total);
  2080.         $em->persist($news);
  2081.         $em->flush();
  2082.         foreach ($carrito as $item) {
  2083.             if ($canal == 'app') {
  2084.                 $product_id $item->product_id;
  2085.                 $count $item->count;
  2086.             } else {
  2087.                 $product_id $item["product_id"];
  2088.                 $count $item["count"];
  2089.             }
  2090.             $prod $this->getDoctrine()->getRepository(Producto::class)->findOneBy(array('plu' => $product_id));
  2091.             if($this->qi->getSetting('pedido_multitienda') != '1')
  2092.                 $inv $this->getDoctrine()->getRepository(Inventario::class)->findOneBy(array('producto' => $prod'tienda' => $tienda));
  2093.             else
  2094.                 $inv $this->getDoctrine()->getRepository(Inventario::class)->findOneBy(array('producto' => $prod));
  2095.             if ($inv) {
  2096.                 $subtotal $subtotal $inv->getPrecio() * $count;
  2097.                 $newci = new CompraItem();
  2098.                 $newci->setProducto($prod);
  2099.                 $newci->setPrecio($inv->getPrecio() * $count);
  2100.                 $newci->setCantidad($count);
  2101.                 $newci->setCompra($news);
  2102.                 $newci->setCosto($inv->getPrecio());
  2103.                 $em->persist($newci);
  2104.                 $em->flush();
  2105.                 $qi->saveFire($newci);
  2106.             } else {
  2107.             }
  2108.         }
  2109.         $news->setSubtotal($subtotal);
  2110.         $total $subtotal $costo_domicilio;
  2111.         $news->setTotal($total);
  2112.         $em->persist($news);
  2113.         $em->flush();
  2114.         $qi->saveFire($news);
  2115.         $obj = array('tienda' => $tienda,
  2116.             'compra' => array('id' => $news->getId(),
  2117.                 'total' => $news->getTotal(),
  2118.                 'estado' => $news->getEstadoProcesamiento(),
  2119.                 'subtotal' => $news->getSubtotal(),
  2120.                 'costoDomicilio' => $news->getCostoDomicilio(),
  2121.             )
  2122.         );
  2123.         $resultado = array("ok" => true'obj' => $obj);
  2124.         $qi->updateListenerTienda($tienda);
  2125.         return $resultado;
  2126.     }
  2127.     /**
  2128.      * @Route("/import/romance/import", name="import")
  2129.      */
  2130.     public function import(Request $request)
  2131.     {
  2132.         /*$categorias = $this->getDoctrine()->getRepository('App:Producto')->findAll();
  2133.         foreach ($categorias as $categoria){
  2134.             $this->qi->saveFire($categoria);
  2135.         }*/
  2136.         /*
  2137.         $em = $this->getDoctrine()->getManager();
  2138.         $data = json_decode($request->getContent(), true);
  2139.         foreach ($data as $producto){
  2140.             $producto_in = new Producto();
  2141.             $producto_in->setPlu($producto['sku']);
  2142.             $producto_in->setNombre($producto['nombreEs']);
  2143.             $producto_in->setImagen($producto['imagen']);
  2144.             $producto_in->setOrden(1);
  2145.             $producto_in->setPrecio(0);
  2146.             $producto_in->setVisible(true);
  2147.             if(is_numeric($producto['id'])){
  2148.                 $categoria = $this->getDoctrine()->getRepository('App:Categoria')->find($producto['id']);
  2149.                 $producto_in->addCategoria($categoria);
  2150.             }
  2151.             $em->persist($producto_in);
  2152.         }
  2153.         $em->flush();
  2154.         die();
  2155.         foreach ($data as $categoria){
  2156.             $categoria_in = new Categoria();
  2157.             $categoria_in->setNombre($categoria['nombre']);
  2158.             $categoria_in->setImagen($categoria['imagen']);
  2159.             $categoria_in->setVisible(true);
  2160.             $categoria_in->setOrden($categoria['orden']);
  2161.             $em->persist($categoria_in);
  2162.         }
  2163.         $em->flush();
  2164.         die();
  2165.         return $this->redirectToRoute('easyadmin');
  2166.         */
  2167.         //$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  2168.     }
  2169.     /**
  2170.      * @Route("/resetting/iridian", name="reset-iridian")
  2171.      */
  2172.     public function sendEmailAction(Request $request)
  2173.     {
  2174.         $username $request->request->get('username');
  2175.         $user $this->userManager->findUserByUsernameOrEmail($username);
  2176.         $event = new GetResponseNullableUserEvent($user$request);
  2177.         if (null !== $event->getResponse()) {
  2178.             return $event->getResponse();
  2179.         }
  2180.         if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl)) {
  2181.             $event = new GetResponseUserEvent($user$request);
  2182.             if (null !== $event->getResponse()) {
  2183.                 return $event->getResponse();
  2184.             }
  2185.             if (null === $user->getConfirmationToken()) {
  2186.                 $user->setConfirmationToken($this->tokenGenerator->generateToken());
  2187.             }
  2188.             $event = new GetResponseUserEvent($user$request);
  2189.             if (null !== $event->getResponse()) {
  2190.                 return $event->getResponse();
  2191.             }
  2192.             $this->sendResettingEmailMessage($user);
  2193.             $user->setPasswordRequestedAt(new \DateTime());
  2194.             $this->userManager->updateUser($user);
  2195.             $event = new GetResponseUserEvent($user$request);
  2196.             if (null !== $event->getResponse()) {
  2197.                 return $event->getResponse();
  2198.             }
  2199.         }
  2200.         return new RedirectResponse($this->generateUrl('fos_user_resetting_check_email', array('username' => $username)));
  2201.     }
  2202.     public function sendResettingEmailMessage(UserInterface $user)
  2203.     {
  2204.         $url $this->generateUrl('fos_user_resetting_reset', array('token' => $user->getConfirmationToken()), UrlGeneratorInterface::ABSOLUTE_URL);
  2205.         $mensajestr_replace('%link%','<a href="'.$url.'">link</a>',$this->qi->getTextoBig('mail_contrasena'));
  2206.         //$this->qi->sendMailPHP($this->qi->getTexto('asunto_mail_resetting'),$user->getEmail(),$mensaje) ;
  2207.     }
  2208.     /**
  2209.      * @Route("/fullreload", name="fullreload")
  2210.      */
  2211.     /*
  2212.     public function fullreload(Request $request)
  2213.     {
  2214.         $productos = $this->getDoctrine()->getRepository('App:Producto')
  2215.             ->createQueryBuilder('p')
  2216.             ->select('p','c as cats')
  2217.             ->leftJoin('p.categorias','c')
  2218.             ->where('c.id is not null')
  2219.             //->setMaxResults(2)
  2220.             ->getQuery()
  2221.             ->getArrayResult();
  2222.         $prods = array();
  2223.         foreach ($productos as $producto){
  2224.             $cat = $producto['categorias'][0]['id'];
  2225.             $producto['categorias'] = array($cat);
  2226.             $prods[$producto['plu']] = $producto;
  2227.         }
  2228.         $this->qi->saveMultiFire('Producto',$prods);
  2229.         dd($prods);
  2230.         return $this->render('basic/template.html.twig', [
  2231.         ]);
  2232.     }
  2233.     */
  2234.     /**
  2235.      * @Route("/load", name="load")
  2236.      */
  2237.     /*
  2238.     public function load(Request $request)
  2239.     {
  2240.         $em = $this->getDoctrine()->getManager();
  2241.         $precios = array(10000, 5000, 7900, 12000, 17000, 20500,9000, 500, 300, 1000, 14500);
  2242.         $productos = $this->getDoctrine()->getRepository('App:Producto')->findAll();
  2243.         $tiendas = $this->getDoctrine()->getRepository('App:Tienda')->findAll();
  2244.         foreach ($tiendas as $tienda){
  2245.             $cont = 0;
  2246.             foreach ($productos as $producto){
  2247.                 if($cont >= count($precios))
  2248.                     $cont = 0;
  2249.                 $inventario = new Inventario();
  2250.                 $inventario->setCantidad(1);
  2251.                 $inventario->setProducto($producto);
  2252.                 $inventario->setPrecio($precios[$cont]);
  2253.                 $inventario->setTienda($tienda);
  2254.                 $cont++;
  2255.                 $em->persist($inventario);
  2256.                 $em->flush();
  2257.                 $this->qi->saveFire($inventario);
  2258.             }
  2259.         }
  2260.         return $this->render('basic/template.html.twig', [
  2261.         ]);
  2262.     }
  2263.     */
  2264.     /**
  2265.      * @Route("/mispedidos/romance/mispedidos", name="mispedidos")
  2266.      */
  2267.     public function mispedidos(Request $request)
  2268.     {
  2269.         $user $this->getUser();
  2270.         if(!$user){
  2271.             return $this->redirectToRoute('homepage');
  2272.         }
  2273.         $aprobado $this->getDoctrine()->getRepository(EstadoPedido::class)->findBy(array('ref'=>'APPROVED'));
  2274.         $pedidos $this->getDoctrine()->getRepository(Compra::class)->findBy(array("usuario"=>$user,'estado'=>$aprobado), array("createdAt"=>"desc"));
  2275.         return $this->render('basic/pedidos.html.twig', [
  2276.             'pedidos' => $pedidos,
  2277.             'idprincipal' => $idprincipal=null
  2278.         ]);
  2279.     }
  2280.     /**
  2281.      * @Route("/mailingcompra/romance/mailingcompra", name="mailingcompra")
  2282.      */
  2283.     public function mailingcompra(Request $request)
  2284.     {
  2285.         $compra $this->getDoctrine()->getRepository('App:Compra')->findOneBy(array(), array('id'=>'desc'));
  2286.         $asunto $this->qi->getSetting('asunto_compra_cliente');
  2287.         $mail $this->renderView('mailing/pedido.html.twig',array('compra'=>$compra));
  2288.         $this->qi->sendMail($asunto'laura@iridian.co'$mail);
  2289.         return $this->render('mailing/pedido.html.twig', array(
  2290.             'compra'=>$compra,
  2291.             'idprincipal' => $idprincipal=null
  2292.         ));
  2293.     }
  2294.     /**
  2295.      * @Route("/mailingcontacto/romance/mailingcontacto", name="mailingcontacto")
  2296.      */
  2297.     public function mailingcontacto(Request $request)
  2298.     {
  2299.         //$compra = $this->getDoctrine()->getRepository('App:Contacto')->findOneBy(array(), array('id'=>'desc'));
  2300.         $asunto $this->qi->getTexto('asunto_compra_cliente');
  2301.         //$mail = $this->renderView('mailing/compra.html.twig',array('compra'=>$compra));
  2302.         //dd($this->qi->sendMail($asunto, 'mauricio@iridian.co', $mail));
  2303.         return $this->render('contact/contact_mail.html.twig', array(
  2304.             'nombre'=>'Luisa',
  2305.             'email'=>'samuel@iridian.co',
  2306.             'telefono'=>'3002111111',
  2307.             'mensaje'=>'Hola quiero saber si venden traumel en tabletas',
  2308.         ));
  2309.     }
  2310.     /**
  2311.      * @Route("/load_images/romance/load_images", name="load_images")
  2312.      */
  2313.     public function load_images(Request $request)
  2314.     {
  2315.         $em $this->getDoctrine()->getManager();
  2316.         $imgs = [[90069577,1,'jpg'], [90069577,2,'jpg'], [90069577,3,'jpg'], [90069788,1,'jpg'], [90069788,2,'jpg'], [90069788,3,'jpg'], [90069789,1,'jpg'], [90069789,2,'jpg'], [90069789,3,'jpg'], [90069790,1,'jpg'], [90069790,2,'jpg'], [90069790,3,'jpg'], [90070677,1,'jpg'], [90070677,2,'jpg'], [90070677,3,'jpg'], [90071645,1,'jpg'], [90071645,2,'jpg'], [90072962,1,'jpg'], [90072962,2,'jpg'], [90072962,3,'jpg'], [90072967,1,'png'], [90072967,2,'jpg'], [90072967,3,'jpg'], [90073014,1,'jpg'], [90073014,2,'jpg'], [90073015,1,'jpg'], [90073015,2,'jpg'], [90073016,1,'jpg'], [90073016,2,'jpg'], [90073220,1,'png'], [90073220,2,'jpg'], [90073220,3,'jpg'], [90073223,1,'png'], [90073223,2,'jpg'], [90073223,3,'jpg'], [90073225,1,'png'], [90073225,2,'jpg'], [90073225,3,'jpg'], [90073228,1,'png'], [90073228,2,'jpg'], [90073228,3,'jpg'], [90073231,1,'png'], [90073231,2,'jpg'], [90073231,3,'jpg'], [90073241,1,'png'], [90073241,2,'jpg'], [90073241,3,'jpg'], [90073244,1,'png'], [90073244,2,'jpg'], [90073244,3,'jpg'], [90073249,1,'jpg'], [90073249,2,'jpg'], [90073249,3,'jpg'], [90073252,1,'jpg'], [90073252,2,'jpg'], [90073252,3,'jpg'], [90073257,1,'jpg'], [90073257,2,'jpg'], [90073257,3,'jpg'], [90073260,1,'jpg'], [90073260,2,'jpg'], [90073260,3,'jpg'], [90074207,1,'jpg'], [90074207,2,'jpg'], [90074207,3,'jpg'], [90074209,1,'jpg'], [90074209,2,'jpg'], [90074209,3,'jpg'], [90074211,1,'jpg'], [90074211,2,'jpg'], [90074211,3,'jpg'], [90075022,1,'jpg'], [90075022,2,'jpg'], [90075294,1,'png'], [90075294,2,'jpg'], [90075294,3,'jpg'], [90075295,1,'png'], [90075295,2,'jpg'], [90075295,3,'jpg'], [90075342,1,'jpg'], [90075342,2,'jpg'], [90075342,3,'jpg'], [90075348,1,'jpg'], [90075348,2,'jpg'], [90075349,1,'jpg'], [90075349,2,'jpg'], [90075467,1,'jpg'], [90075467,2,'jpg'], [90075467,3,'jpg'], [90075467,4,'jpg'], [90075467,5,'png'], [90075468,1,'jpg'], [90075468,2,'jpg'], [90075468,3,'jpg'], [90075468,4,'jpg'], [90075468,5,'png'], [90075469,1,'jpg'], [90075469,2,'jpg'], [90075469,3,'jpg'], [90075469,4,'jpg'], [90075469,5,'png'], [90075512,1,'jpg'], [90075512,2,'jpg'], [90075512,3,'jpg'], [90075512,4,'jpg'], [90075512,5,'png'], [90075513,1,'jpg'], [90075513,2,'jpg'], [90075513,3,'jpg'], [90075513,4,'jpg'], [90075513,5,'png'], [90076166,1,'jpg'], [90076166,2,'jpg'], [90076166,3,'jpg'], [90076166,4,'jpg'], [90076166,5,'png'], [90076166,6,'jpg'], [90076167,1,'jpg'], [90076167,2,'jpg'], [90076167,3,'jpg'], [90076167,4,'jpg'], [90076167,5,'png'], [90076167,6,'jpg'], [90076168,1,'jpg'], [90076168,2,'jpg'], [90076168,3,'jpg'], [90076168,4,'jpg'], [90076168,5,'png'], [90076168,6,'jpg'], [90076168,7,'jpg'], [90076168,8,'jpg'], [90076169,1,'jpg'], [90076169,2,'jpg'], [90076169,3,'jpg'], [90076169,4,'jpg'], [90076169,5,'png'], [90076169,6,'jpg'], [90076169,7,'jpg'], [90076169,8,'jpg'], [90076195,1,'jpg'], [90076195,2,'jpg'], [90076195,3,'jpg'], [90076195,4,'jpg'], [90076195,5,'png'], [90076195,6,'jpg'], [90076195,7,'jpg'], [90076195,8,'jpg'], [90076196,1,'jpg'], [90076196,2,'jpg'], [90076196,3,'jpg'], [90076196,4,'jpg'], [90076196,5,'png'], [90076196,6,'jpg'], [90076196,7,'jpg'], [90076196,8,'jpg'], [90076485,1,'jpg'], [90076485,2,'jpg'], [90076486,1,'jpg'], [90076486,2,'jpg'], [90077226,1,'jpg'], [90077226,2,'jpg'], [90077226,3,'jpg'], [90077588,1,'jpg'], [90077588,2,'jpg'], [90077588,3,'jpg'], [90077589,1,'jpg'], [90077589,2,'jpg'], [90077589,3,'jpg'], [90077590,1,'jpg'], [90077590,2,'jpg'], [90077590,3,'jpg'], [90077591,1,'jpg'], [90077591,2,'jpg'], [90077591,3,'jpg'], [90077592,1,'jpg'], [90077592,2,'jpg'], [90077592,3,'jpg'], [90077616,1,'jpg'], [90077616,2,'jpg'], [90077616,3,'jpg'], [90077616,4,'jpg'], [90077616,5,'jpg'], [90077616,6,'jpg'], [90077616,7,'jpg'], [90077616,8,'jpg'], [90077616,9,'jpg'], [90077876,1,'jpg'], [90077876,2,'jpg'], [90077876,3,'png'], [90077877,1,'jpg'], [90077877,2,'jpg'], [90078113,1,'jpg'], [90078113,2,'jpg'], [90078113,3,'jpg'], [90078113,4,'jpg'], [90078142,1,'jpg'], [90078142,2,'jpg'], [90078142,3,'jpg'], [90078142,4,'jpg'], [90078142,5,'jpg'], [90078143,1,'jpg'], [90078143,2,'jpg'], [90078143,3,'jpg'], [90078143,4,'jpg'], [90078143,5,'png'], [90078144,1,'jpg'], [90078144,2,'jpg'], [90078144,3,'jpg'], [90078144,4,'jpg'], [90078144,5,'jpg'], [90078145,1,'jpg'], [90078145,2,'jpg'], [90078145,3,'jpg'], [90078145,4,'jpg'], [90078145,5,'png'], [90078146,1,'jpg'], [90078146,2,'jpg'], [90078146,3,'jpg'], [90078146,4,'jpg'], [90078146,5,'jpg'], [90078147,1,'jpg'], [90078147,2,'jpg'], [90078147,3,'jpg'], [90078147,4,'jpg'], [90078147,5,'png'], [90078355,1,'jpg'], [90078355,2,'jpg'], [90078355,3,'jpg'], [90078355,4,'jpg'], [90078355,5,'png'], [90078356,1,'jpg'], [90078356,2,'jpg'], [90078356,3,'jpg'], [90078356,4,'jpg'], [90078356,5,'png'], [90078357,1,'jpg'], [90078357,2,'jpg'], [90078357,3,'jpg'], [90078357,4,'jpg'], [90078357,5,'png'], [90078358,1,'jpg'], [90078358,2,'jpg'], [90078358,3,'jpg'], [90078358,4,'jpg'], [90078358,5,'png'], [90078359,1,'jpg'], [90078359,2,'jpg'], [90078359,3,'jpg'], [90078359,4,'jpg'], [90078359,5,'png'], [90078361,1,'jpg'], [90078361,2,'jpg'], [90078361,3,'jpg'], [90078361,4,'jpg'], [90078361,5,'png'], [90078362,1,'jpg'], [90078362,2,'jpg'], [90078362,3,'jpg'], [90078362,4,'jpg'], [90078362,5,'png'], [90078363,1,'jpg'], [90078363,2,'jpg'], [90078363,3,'jpg'], [90078363,4,'jpg'], [90078363,5,'png'], [90078364,1,'jpg'], [90078364,2,'jpg'], [90078364,3,'jpg'], [90078364,4,'jpg'], [90078364,5,'jpg'], [90078365,1,'jpg'], [90078365,2,'jpg'], [90078365,3,'jpg'], [90078365,4,'jpg'], [90078365,5,'jpg'], [90078366,1,'jpg'], [90078366,2,'jpg'], [90078366,3,'jpg'], [90078366,4,'jpg'], [90078366,5,'jpg'], [90078367,1,'jpg'], [90078367,2,'jpg'], [90078367,3,'jpg'], [90078367,4,'jpg'], [90078367,5,'jpg'], [90078373,1,'jpg'], [90078373,2,'jpg'], [90078373,3,'jpg'], [90078373,4,'jpg'], [90078373,5,'png'], [90078374,1,'jpg'], [90078374,2,'jpg'], [90078374,3,'jpg'], [90078374,4,'jpg'], [90078374,5,'png'], [90078375,1,'jpg'], [90078375,2,'jpg'], [90078375,3,'jpg'], [90078375,4,'jpg'], [90078375,5,'png'], [90078376,1,'jpg'], [90078376,2,'jpg'], [90078376,3,'jpg'], [90078376,4,'jpg'], [90078376,5,'png'], [90078377,1,'jpg'], [90078377,2,'jpg'], [90078377,3,'jpg'], [90078377,4,'jpg'], [90078378,1,'jpg'], [90078378,2,'jpg'], [90078378,3,'jpg'], [90078378,4,'jpg'], [90078379,1,'jpg'], [90078379,2,'jpg'], [90078379,3,'jpg'], [90078379,4,'jpg'], [90078380,1,'jpg'], [90078380,2,'jpg'], [90078380,3,'jpg'], [90078380,4,'jpg'], [90078381,1,'jpg'], [90078381,2,'jpg'], [90078381,3,'jpg'], [90078381,4,'jpg'], [90078381,5,'jpg'], [90078383,1,'jpg'], [90078383,2,'jpg'], [90078383,3,'jpg'], [90078383,4,'jpg'], [90078383,5,'jpg'], [90078384,1,'jpg'], [90078384,2,'jpg'], [90078384,3,'jpg'], [90078384,4,'jpg'], [90078384,5,'jpg'], [90078385,1,'jpg'], [90078385,2,'jpg'], [90078385,3,'jpg'], [90078385,4,'jpg'], [90078385,5,'jpg'], [90078386,1,'jpg'], [90078386,2,'jpg'], [90078386,3,'jpg'], [90078386,4,'jpg'], [90078386,5,'jpg'], [90078387,1,'jpg'], [90078387,2,'jpg'], [90078387,3,'jpg'], [90078387,4,'jpg'], [90078387,5,'jpg'], [90078388,1,'jpg'], [90078388,2,'jpg'], [90078388,3,'jpg'], [90078388,4,'jpg'], [90078388,5,'jpg'], [90078389,1,'jpg'], [90078389,2,'jpg'], [90078389,3,'jpg'], [90078389,4,'jpg'], [90078389,5,'jpg'], [90078487,1,'jpg'], [90078487,2,'jpg'], [90078487,3,'jpg'], [90078487,4,'jpg'], [90078487,5,'jpg'], [90078487,6,'jpg'], [90078487,7,'jpg'], [90078488,1,'jpg'], [90078488,2,'jpg'], [90078488,3,'jpg'], [90078488,4,'jpg'], [90078488,5,'jpg'], [90078488,6,'jpg'], [90078488,7,'jpg'], [90078489,1,'jpg'], [90078489,2,'jpg'], [90078489,3,'jpg'], [90078489,4,'jpg'], [90078489,5,'jpg'], [90078489,6,'jpg'], [90078489,7,'jpg'], [90078490,1,'jpg'], [90078490,2,'jpg'], [90078490,3,'jpg'], [90078490,4,'jpg'], [90078490,5,'jpg'], [90078490,6,'jpg'], [90078490,7,'jpg'], [90078491,1,'jpg'], [90078491,2,'jpg'], [90078491,3,'jpg'], [90078491,4,'jpg'], [90078491,5,'jpg'], [90078491,6,'jpg'], [90078491,7,'jpg'], [90078492,1,'jpg'], [90078492,2,'jpg'], [90078492,3,'jpg'], [90078492,4,'jpg'], [90078492,5,'png'], [90078492,6,'jpg'], [90078492,7,'jpg'], [90078493,1,'jpg'], [90078493,2,'jpg'], [90078493,3,'jpg'], [90078493,4,'jpg'], [90078493,5,'png'], [90078493,6,'jpg'], [90078493,7,'jpg'], [90078494,1,'jpg'], [90078494,2,'jpg'], [90078494,3,'jpg'], [90078494,4,'jpg'], [90078494,5,'png'], [90078494,6,'jpg'], [90078494,7,'jpg'], [90078495,1,'jpg'], [90078495,2,'jpg'], [90078495,3,'jpg'], [90078495,4,'jpg'], [90078495,5,'png'], [90078495,6,'jpg'], [90078495,7,'jpg'], [90078496,1,'jpg'], [90078496,2,'jpg'], [90078496,3,'jpg'], [90078496,4,'jpg'], [90078496,5,'png'], [90078496,6,'jpg'], [90078496,7,'jpg'], [90078497,1,'jpg'], [90078497,2,'jpg'], [90078497,3,'jpg'], [90078497,4,'jpg'], [90078497,5,'jpg'], [90078497,6,'jpg'], [90078497,7,'jpg'], [90078498,1,'jpg'], [90078498,2,'jpg'], [90078498,3,'jpg'], [90078498,4,'jpg'], [90078498,5,'jpg'], [90078498,6,'jpg'], [90078498,7,'jpg'], [90078499,1,'jpg'], [90078499,2,'jpg'], [90078499,3,'jpg'], [90078499,4,'jpg'], [90078499,5,'jpg'], [90078499,6,'jpg'], [90078499,7,'jpg'], [90078500,1,'jpg'], [90078500,2,'jpg'], [90078500,3,'jpg'], [90078500,4,'jpg'], [90078500,5,'jpg'], [90078500,6,'jpg'], [90078500,7,'jpg'], [90078501,1,'jpg'], [90078501,2,'jpg'], [90078501,3,'jpg'], [90078501,4,'jpg'], [90078501,5,'jpg'], [90078501,6,'jpg'], [90078501,7,'jpg'], [90078507,1,'jpg'], [90078507,2,'jpg'], [90078507,3,'jpg'], [90078507,4,'jpg'], [90078507,5,'png'], [90078507,6,'jpg'], [90078507,7,'jpg'], [90078507,8,'jpg'], [90078507,9,'jpg'], [90078508,1,'jpg'], [90078508,2,'jpg'], [90078508,3,'jpg'], [90078508,4,'jpg'], [90078508,5,'png'], [90078508,6,'jpg'], [90078508,7,'jpg'], [90078508,8,'jpg'], [90078508,9,'jpg'], [90078509,1,'jpg'], [90078509,2,'jpg'], [90078509,3,'jpg'], [90078509,4,'jpg'], [90078509,5,'png'], [90078509,6,'jpg'], [90078509,7,'jpg'], [90078509,8,'jpg'], [90078509,9,'jpg'], [90078510,1,'jpg'], [90078510,2,'jpg'], [90078510,3,'jpg'], [90078510,4,'jpg'], [90078510,5,'png'], [90078510,6,'jpg'], [90078510,7,'jpg'], [90078510,8,'jpg'], [90078510,9,'jpg'], [90078511,1,'jpg'], [90078511,2,'jpg'], [90078511,3,'jpg'], [90078511,4,'jpg'], [90078511,5,'png'], [90078511,6,'jpg'], [90078511,7,'jpg'], [90078511,8,'jpg'], [90078511,9,'jpg'], [90078512,1,'jpg'], [90078512,2,'jpg'], [90078512,3,'jpg'], [90078512,4,'jpg'], [90078512,5,'png'], [90078512,6,'jpg'], [90078512,7,'jpg'], [90078513,1,'jpg'], [90078513,2,'jpg'], [90078513,3,'jpg'], [90078513,4,'jpg'], [90078513,5,'png'], [90078513,6,'jpg'], [90078513,7,'jpg'], [90078514,1,'jpg'], [90078514,2,'jpg'], [90078514,3,'jpg'], [90078514,4,'jpg'], [90078514,5,'png'], [90078514,6,'jpg'], [90078514,7,'jpg'], [90078515,1,'jpg'], [90078515,2,'jpg'], [90078515,3,'jpg'], [90078515,4,'jpg'], [90078515,5,'png'], [90078515,6,'jpg'], [90078515,7,'jpg'], [90078516,1,'jpg'], [90078516,2,'jpg'], [90078516,3,'jpg'], [90078516,4,'jpg'], [90078516,5,'png'], [90078516,6,'jpg'], [90078516,7,'jpg'], [90078694,1,'jpg'], [90078694,2,'jpg'], [90078694,3,'jpg'], [90078694,4,'jpg'], [90078694,5,'jpg'], [90078694,6,'jpg'], [90078695,1,'jpg'], [90078695,2,'jpg'], [90078695,3,'jpg'], [90078695,4,'jpg'], [90078695,5,'jpg'], [90078695,6,'jpg'], [90078696,1,'jpg'], [90078696,2,'jpg'], [90078696,3,'jpg'], [90078696,4,'jpg'], [90078696,5,'jpg'], [90078696,6,'jpg'], [90078697,1,'jpg'], [90078697,2,'jpg'], [90078697,3,'jpg'], [90078697,4,'jpg'], [90078697,5,'jpg'], [90078697,6,'jpg'], [90078698,1,'jpg'], [90078698,2,'jpg'], [90078698,3,'jpg'], [90078698,4,'jpg'], [90078698,5,'jpg'], [90078698,6,'jpg'], [90078699,1,'jpg'], [90078699,2,'jpg'], [90078699,3,'jpg'], [90078699,4,'jpg'], [90078699,5,'jpg'], [90078699,6,'jpg'], [90078700,1,'jpg'], [90078700,2,'jpg'], [90078700,3,'jpg'], [90078700,4,'jpg'], [90078700,5,'jpg'], [90078700,6,'jpg'], [90078701,1,'jpg'], [90078701,2,'jpg'], [90078701,3,'jpg'], [90078701,4,'jpg'], [90078701,5,'jpg'], [90078701,6,'jpg'], [90078702,1,'jpg'], [90078702,2,'jpg'], [90078702,3,'jpg'], [90078702,4,'jpg'], [90078702,5,'jpg'], [90078702,6,'jpg'], [90078703,1,'jpg'], [90078703,2,'jpg'], [90078703,3,'jpg'], [90078703,4,'jpg'], [90078703,5,'jpg'], [90078703,6,'jpg'], [90078704,1,'jpg'], [90078704,2,'jpg'], [90078704,3,'jpg'], [90078705,1,'jpg'], [90078705,2,'jpg'], [90078705,3,'jpg'], [90078706,1,'jpg'], [90078706,2,'jpg'], [90078706,3,'jpg'], [90078707,1,'jpg'], [90078707,2,'jpg'], [90078707,3,'jpg'], [90078708,1,'jpg'], [90078708,2,'jpg'], [90078708,3,'jpg'], [90078709,1,'jpg'], [90078709,2,'jpg'], [90078709,3,'jpg'], [90078710,1,'jpg'], [90078710,2,'jpg'], [90078710,3,'jpg'], [90078711,1,'jpg'], [90078711,2,'jpg'], [90078711,3,'jpg'], [90078712,1,'jpg'], [90078712,2,'jpg'], [90078712,3,'jpg'], [90078713,1,'jpg'], [90078713,2,'jpg'], [90078713,3,'jpg'], [90079388,1,'png'], [90079388,2,'jpg'], [90079388,3,'jpg'], [90079389,1,'png'], [90079389,2,'jpg'], [90079389,3,'jpg'], [90079390,1,'png'], [90079390,2,'jpg'], [90079390,3,'jpg'], [90079391,1,'png'], [90079391,2,'jpg'], [90079391,3,'jpg'], [90079392,1,'png'], [90079392,2,'jpg'], [90079392,3,'jpg'], [90079393,1,'png'], [90079393,2,'jpg'], [90079393,3,'jpg'], [90079394,1,'png'], [90079394,2,'jpg'], [90079394,3,'jpg'], [90079395,1,'png'], [90079395,2,'jpg'], [90079395,3,'jpg'], [90079396,1,'png'], [90079396,2,'jpg'], [90079396,3,'jpg'], [90079397,1,'png'], [90079397,2,'jpg'], [90079397,3,'jpg'], [90079398,1,'jpg'], [90079398,2,'jpg'], [90079398,3,'jpg'], [90079401,1,'jpg'], [90079401,2,'jpg'], [90079401,3,'jpg'], [90079402,1,'jpg'], [90079402,2,'jpg'], [90079402,3,'jpg'], [90079403,1,'jpg'], [90079403,2,'jpg'], [90079403,3,'jpg'], [90079404,1,'jpg'], [90079404,2,'jpg'], [90079404,3,'jpg'], [90079409,1,'png'], [90079409,2,'jpg'], [90079409,3,'jpg'], [90079410,1,'png'], [90079410,2,'jpg'], [90079410,3,'jpg'], [90079411,1,'png'], [90079411,2,'jpg'], [90079411,3,'jpg'], [90079412,1,'png'], [90079412,2,'jpg'], [90079412,3,'jpg'], [90079413,1,'png'], [90079413,2,'jpg'], [90079413,3,'jpg'], [90079414,1,'png'], [90079414,2,'jpg'], [90079414,3,'jpg'], [90079415,1,'png'], [90079415,2,'jpg'], [90079415,3,'jpg'], [90079416,1,'png'], [90079416,2,'jpg'], [90079416,3,'jpg'], [90079417,1,'png'], [90079417,2,'jpg'], [90079417,3,'jpg'], [90079418,1,'png'], [90079418,2,'jpg'], [90079418,3,'jpg'], [90079420,1,'jpg'], [90079420,2,'jpg'], [90079420,3,'jpg'], [90079421,1,'jpg'], [90079421,2,'jpg'], [90079421,3,'jpg'], [90079422,1,'jpg'], [90079422,2,'jpg'], [90079422,3,'jpg'], [90079423,1,'jpg'], [90079423,2,'jpg'], [90079423,3,'jpg'], [90079424,1,'jpg'], [90079424,2,'jpg'], [90079424,3,'jpg'], [90077616,10,'jpg'], [90077616,11,'jpg']];
  2317.         $prods $this->getDoctrine()->getRepository('App:Producto')->findAll();
  2318.         $prods_array = [];
  2319.         foreach ($prods as $prod){
  2320.             $prods_array[$prod->getPlu()] = $prod;
  2321.         }
  2322.         $ini "https://firebasestorage.googleapis.com/v0/b/romancerelax-2021.appspot.com/o/app_images%2F";
  2323.         $fin "?alt=media&token=a72666b0-cf6f-4480-a06b-286f3f0911e6";
  2324.         foreach ($imgs as $data){
  2325.             $sku $data[0];
  2326.             $pos $data[1];
  2327.             $ext $data[2];
  2328.             $ruta $ini.$sku.'_'.$pos.'.'.$ext.$fin;
  2329.             $producto $prods_array[$sku];
  2330.             if($pos == 1){
  2331.                 $producto->setImagen($ruta);
  2332.                 $em->persist($producto);
  2333.             }else{
  2334.                 $new_img = new Image();
  2335.                 $new_img->setProducto($producto);
  2336.                 $new_img->setVisible(true);
  2337.                 $new_img->setOrden(1);
  2338.                 $new_img->setImage($ruta);
  2339.                 $em->persist($new_img);
  2340.             }
  2341.         }
  2342.         $em->flush();
  2343.         dd(1);
  2344.         return $this->render('contact/contact_mail.html.twig', array(
  2345.             'nombre'=>'Luisa',
  2346.             'email'=>'samuel@iridian.co',
  2347.             'telefono'=>'3002111111',
  2348.             'mensaje'=>'Hola quiero saber si venden traumel en tabletas',
  2349.         ));
  2350.     }
  2351.     /**
  2352.      * @Route("/mis-datos/romance/mis-datos", name="mis-datos")
  2353.      */
  2354.     public function misDatos(Request $request)
  2355.     {
  2356.         $user $this->getUser();
  2357.         if ($user) {
  2358.             $perfil = new Usuario();
  2359.             $form $this->createForm(PerfilType::class, $perfil);
  2360.             $form->handleRequest($request);
  2361.             if ($form->isSubmitted() && $form->isValid()) {
  2362.                 $perfil $form->getData();
  2363.                 $um $this->userManager;
  2364.                 $user $um->findUserBy(array('uid' => $user->getUid() ));
  2365.                 $user->setNombre($perfil->getNombre());
  2366.                 $user->setDocumento($perfil->getDocumento());
  2367.                 $user->setEmail($perfil->getEmail());
  2368.                 $user->setCelular($perfil->getCelular());
  2369.                 $user->setEmail($form->get('email')->getData());
  2370.                
  2371.                 $em $this->getDoctrine()->getManager();
  2372.                 $em->persist($user);
  2373.                 $em->flush();
  2374.                 $um->updateUser($user);
  2375.                 return $this->render('home/mis-datos.html.twig', [
  2376.                     'user' => $user,
  2377.                     'msg' => 'submitted and validated',
  2378.                     'form' => $form->createView(),
  2379.                     'perfil' => $perfil
  2380.                 ]);
  2381.             }
  2382.           
  2383.             return $this->render('home/mis-datos.html.twig', [
  2384.                 'user' => $user,
  2385.                 'msg' => 'no submit',
  2386.                 'form' => $form->createView(),
  2387.                 'perfil' => $perfil,
  2388.                 'idprincipal' => $idprincipal null
  2389.             ]);
  2390.         } else {
  2391.             return $this->redirectToRoute('homepage');
  2392.         }
  2393.     }
  2394.     /**
  2395.      * @Route("/mis-compras/romance/mis-compras", name="mis-compras")
  2396.      */
  2397.     public function misCompras(Request $request)
  2398.     {
  2399.         $user $this->getUser();
  2400.         if(!$user){
  2401.             return $this->redirectToRoute('homepage');
  2402.         }
  2403.         // $estado = $this->getDoctrine()->getRepository(EstadoPedido::class)->findOneBy(array("ref" => 'APROBADA'));
  2404.         // $compras=$this->getDoctrine()->getRepository(Compra::class)->findBy(array( 'usuario'=>$user),array('id'=>'desc'));
  2405.         $aprobado $this->getDoctrine()->getRepository(EstadoPedido::class)->findOneBy(array('ref'=>'APROBADA'));
  2406.         $compras=$this->getDoctrine()->getRepository(Compra::class)->findBy(array('usuario'=>$user),array('createdAt'=>'desc'));
  2407.         // dd($compras);
  2408.         
  2409.         return $this->render('home/mis-compras.html.twig', [
  2410.             'compras'=>$compras,
  2411.             'idprincipal' => $idprincipal null
  2412.             ]);
  2413.     }
  2414.     /**
  2415.      * @Route("/mis-compras-interna/romance/mis-compras-interna/{id}", name="mis-compras-interna")
  2416.      */
  2417.     public function misComprasInterna(Request $request,$id)
  2418.     {
  2419.         $compra=$this->getDoctrine()->getRepository(Compra::class)->find($id);
  2420.         $usuario=$compra->getUsuario();
  2421.         // $tracking = $this->fedex->TrackingPedido($compra);
  2422.         // $estados = array(
  2423.         //     'PU' => 'RECIBIDA',
  2424.         //     'AF' => 'ALISTAMIENTO',
  2425.         //     'IT' => 'EN CAMINO',
  2426.         //     'DL' => 'ENTREGADA',
  2427.         //     'CA' => 'NOVEDAD',
  2428.         //     'DE' => 'NOVEDAD',
  2429.         // );
  2430.         // if(isset($tracking['code'])) {
  2431.         //     $seguimiento = $this->getDoctrine()->getRepository('App:Seguimiento')->findOneBy(array('nombre_es'=>$estados[$tracking['code']]));
  2432.         // }else{
  2433.         //     $seguimiento = $this->getDoctrine()->getRepository('App:Seguimiento')->find(2);
  2434.         // }
  2435.         // $track=$this->getDoctrine()->getRepository('App:SeguimientoTracking')->findOneBy(array('compra'=>$compra,'seguimiento'=>$seguimiento));
  2436.         // if($seguimiento && !$track){
  2437.         //     $compra->setSeguimiento($seguimiento);
  2438.         //     $segtrack = new SeguimientoTracking();
  2439.         //     $segtrack->setCompra($compra);
  2440.         //     $segtrack->setSeguimiento($seguimiento);
  2441.         //     $em = $this->getDoctrine()->getManager();
  2442.         //     $em->persist($compra);
  2443.         //     $em->persist($segtrack);
  2444.         //     $em->flush();
  2445.         // }
  2446.         // dd($compra);
  2447.         
  2448.         
  2449.         return $this->render('home/mis-compras-interna.html.twig', [
  2450.             'compra'=>$compra,
  2451.             'usuario'=>$usuario,
  2452.             'idprincipal' => $idprincipal null
  2453.             
  2454.         ]);
  2455.         
  2456.     }
  2457.     /**
  2458.      * @Route("/mis-direcciones/romance/mis-direcciones", name="mis-direcciones")
  2459.      */
  2460.     public function misDirecciones2(Request $request)
  2461.     {
  2462.         $user $this->getUser();
  2463.         if ($user) {
  2464.             $direcciones $this->getDoctrine()->getRepository(Direccion::class)->createQueryBuilder('d')
  2465.                 ->select('d')
  2466.                 ->leftJoin('d.usuario','u')
  2467.                 ->where('u.id = '.$user->getId())
  2468.                 ->andWhere('d.visible = 1')
  2469.                 ->getQuery()
  2470.                 ->getResult();
  2471.             // ->andWhere('d.visible is null or d.visible = 1')
  2472.             return $this->render('home/mis-direcciones.html.twig', [
  2473.                 'direcciones' => $direcciones,
  2474.                 'idprincipal' => $idprincipal null
  2475.             ]);
  2476.         }
  2477.     }
  2478.     /**
  2479.      * @Route("/editar-direccion/romance/{id}", name="editar-direccion")
  2480.      */
  2481.     public function editarDirecciones(Request $request,$id)
  2482.     {
  2483.         $user=$this->getUser();
  2484.         if(!$user){
  2485.             return $this->redirectToRoute('homepage');
  2486.         }
  2487.         $direccion=$this->getDoctrine()->getRepository(Direccion::class)->find($id);
  2488.         return $this->render('home/editar_mis-direcciones-formulario.html.twig', [
  2489.             'direccion'=>$direccion,
  2490.             'idprincipal' => $idprincipal=null
  2491.         ]);
  2492.     }
  2493.         /**
  2494.      * @Route("/enviar-edicion-formulario-direccion/romance/{id}", name="enviar-edicion-formulario-direccion")
  2495.      */
  2496.     public function enviaredicionformulariodireccion(Request $request,$id)
  2497.     {
  2498.         $mensaje = array("ok" => false"mensaje" => "error");
  2499.         $user=$this->getUser();
  2500.         if(!$user){
  2501.             return $this->redirectToRoute('homepage');
  2502.         }
  2503.         $direccioneditada=$this->getDoctrine()->getRepository(Direccion::class)->find($id);
  2504.         // $nombre=$request->get("nombrecompleto");  
  2505.         // $telefono=$request->get("telefono");
  2506.         $direccion=$request->get("direccion");
  2507.         // $zip=$request->get("zip");
  2508.         $ciudad=$request->get("ciudad");
  2509.         //$departamento=$request->get("departamento");
  2510.         // $numerodoc=$request->request->get('numerodoc');
  2511.         // $tipodoc=$this->getDoctrine()->getRepository(Tipodocumento::class)->find($request->request->get('tipodoc'));
  2512.         $ciudad=$this->getDoctrine()->getRepository(Ciudad::class)->find($request->request->get('ciudad'));
  2513.         $em $this->getDoctrine()->getManager();        
  2514.         // $direccioneditada->setPersona($nombre);
  2515.         // $direccioneditada->setTelefono($telefono);
  2516.         $direccioneditada->setDireccion($direccion);
  2517.         // $direccioneditada->setCodigopostal($zip);
  2518.         // if($zip) {
  2519.         //     $data =$this->fedex->ValidarPostal($zip, $ciudad->getPais()->getCodigo());
  2520.         //     if(isset($data->error)){
  2521.         //         $this->addFlash(
  2522.         //             'warning',
  2523.         //             'Error postal'
  2524.         //         );
  2525.         //         return $this->redirectToRoute('editar-direccion',array('id'=>$id));
  2526.         //     }
  2527.         // }
  2528.         $direccioneditada->setCiudad($ciudad);
  2529.         // $direccioneditada->setTipodocumento($tipodoc);
  2530.         // $direccioneditada->setNumerodocumento($numerodoc);
  2531.         $direccioneditada->setVisible(1);
  2532.         //$direccioneditada->setDepartamento($departamento);
  2533.         
  2534.         $em $this->getDoctrine()->getManager();
  2535.         $em->persist($direccioneditada);
  2536.         $em->flush();
  2537.         $mensaje["ok"] = true;
  2538.         $mensaje["mensaje"] = "Direccion Editada";
  2539.         return new JsonResponse($mensaje);
  2540.     }
  2541.     /**
  2542.      * @Route("/eliminar-direccion/romance/{id}", name="eliminar-direccion")
  2543.      */
  2544.     public function eliminardireccion(Request $request,$id)
  2545.     {
  2546.         // $mensaje = array("ok" => false, "mensaje" => "error");
  2547.         $user=$this->getUser();
  2548.         if(!$user){
  2549.             return $this->redirectToRoute('homepage');
  2550.         }
  2551.         $direccion=$this->getDoctrine()->getRepository(Direccion::class)->find($id);
  2552.         // dd($direccion); 
  2553.         
  2554.         $em $this->getDoctrine()->getManager();
  2555.         $direccion->setVisible(false);
  2556.         // $em->persist($direccioneditada);
  2557.         // $em->flush();
  2558.         $em->persist($direccion);
  2559.         $em->flush();
  2560.        return $this->redirectToRoute('mis-direcciones',[
  2561.         'idprincipal' => $idprincipal=null
  2562.         ]);
  2563.     }
  2564.     /**
  2565.      * @Route("/mis-direcciones-formulario/romance/mis-direcciones-formulario", name="mis-direcciones-formulario")
  2566.      */
  2567.     public function misDireccionesFormulario(Request $request)
  2568.     {
  2569.         return $this->render('home/mis-direcciones-formulario.html.twig', [
  2570.             'idprincipal' => $idprincipal null
  2571.         ]);
  2572.     }
  2573.         /**
  2574.      * @Route("/mis-favoritos/romance/mis-favoritos", name="mis-favoritos")
  2575.      */
  2576.     public function misFavoritos(Request $request)
  2577.     { 
  2578.         $user=$this->getUser();
  2579.         if(!$user){
  2580.             return $this->redirectToRoute('homepage');
  2581.         }
  2582.         $favoritos_prod$this->getDoctrine()->getRepository(Producto::class)->createQueryBuilder('p')
  2583.             ->select('p')
  2584.             ->leftJoin('p.favoritos''fav')
  2585.             ->leftJoin('fav.usuario''u')
  2586.             ->leftJoin('fav.producto''pa')
  2587.             ->Where('u.id ='.$user->getId())
  2588.             ->AndWhere('p.padre is null');
  2589.         $favoritos_prod$favoritos_prod->groupBy('p.plu')->getQuery()
  2590.             ->getResult();
  2591.         $favoritos_blog$this->getDoctrine()->getRepository(FavoritoBlog::class)->createQueryBuilder('p')
  2592.         ->select('p''b.id as id','b.titulo as titulo''b.created_at as fecha''b.imagen_listado as imagen')
  2593.         // ->leftJoin('p.favorito', 'fav')
  2594.         ->leftJoin('p.usuario''u')
  2595.         ->leftJoin('p.blog''b')
  2596.         ->Where('u.id ='.$user->getId())
  2597.         ->getQuery()
  2598.         ->getResult();
  2599.         return $this->render('home/mis-favoritos.html.twig', [
  2600.             'favoritos_prod'=>$favoritos_prod,
  2601.             'favoritos_blog'=>$favoritos_blog,
  2602.             'user'=>$user,
  2603.             'idprincipal' => $idprincipal null
  2604.         ]);
  2605.     }
  2606.     /**
  2607.      *  @Method({"POST"})
  2608.      * @Route("/add-favorito-producto/romance/add-favorito-producto/{id}", name="add-favorito-producto")
  2609.      */
  2610.     public function FavoritoProducto(Request $request,$id)
  2611.     {
  2612.         $user=$this->getUser();
  2613.         $mensaje = array('ok' => false'msg' => 'Error al agregar');
  2614.         $producto=$this->getDoctrine()->getRepository(Producto::class)->find($id);
  2615.         $favorito=$this->getDoctrine()->getRepository(Favorito::class)->findOneBy(array('producto'=>$producto'usuario'=>$user));
  2616.         $em=$this->getDoctrine()->getManager();
  2617.         if($favorito){
  2618.             $em->remove($favorito);
  2619.             $em->flush();
  2620.             $mensaje = array('ok' => false'msg' => 'Eliminado');
  2621.         }else{
  2622.             $newfavorito=new Favorito();
  2623.             $newfavorito->setUsuario($user);
  2624.             $newfavorito->setProducto($producto);
  2625.             $em->persist($newfavorito);
  2626.             $em->flush();
  2627.             $mensaje = array('ok' => true'msg' => 'agregado');
  2628.         }
  2629.         $response = new Response();
  2630.         $response->setContent(json_encode($mensaje));
  2631.         $response->headers->set('Content-Type''application/json');
  2632.         return $response;
  2633.     }
  2634.      /**
  2635.      *  @Method({"POST"})
  2636.      * @Route("/add-favorito-blog/romance/add-favorito-blog/{id}", name="add-favorito-blog")
  2637.      */
  2638.     public function FavoritoBlog(Request $request,$id)
  2639.     {
  2640.         $user=$this->getUser();
  2641.         $mensaje = array('ok' => false'msg' => 'Error al agregar');
  2642.         $blog=$this->getDoctrine()->getRepository(Blog::class)->find($id);
  2643.         $favorito=$this->getDoctrine()->getRepository(FavoritoBlog::class)->findOneBy(array('blog'=>$blog'usuario'=>$user));
  2644.         $em=$this->getDoctrine()->getManager();
  2645.         if($favorito){
  2646.             $em->remove($favorito);
  2647.             $em->flush();
  2648.             $mensaje = array('ok' => false'msg' => 'Eliminado');
  2649.         }else{
  2650.             $newfavorito=new FavoritoBlog();
  2651.             $newfavorito->setUsuario($user);
  2652.             $newfavorito->setBlog($blog);
  2653.             $em->persist($newfavorito);
  2654.             $em->flush();
  2655.             $mensaje = array('ok' => true'msg' => 'agregado');
  2656.         }
  2657.         $response = new Response();
  2658.         $response->setContent(json_encode($mensaje));
  2659.         $response->headers->set('Content-Type''application/json');
  2660.         return $response;
  2661.     }
  2662.      /**
  2663.      *  @Method({"POST"})
  2664.      * @Route("/cargarfotos/romance/romance/ro", name="cargarfotos")
  2665.      */
  2666.     public function cargarfotos(Request $request)
  2667.     {
  2668.         $em $this->getDoctrine()->getManager();
  2669.         // $photos=["90071645_1.jpg"];
  2670.         $photos=["90071645_1.jpg","90071645_2.jpg","90076168_1.jpg","90076168_2.jpg","90076168_3.jpg","90076168_4.jpg","90076168_5.jpg","90076168_6.jpg","90076168_7.jpg","90076168_8.jpg","90076168_9.jpg","90076169_1.jpg","90076169_2.jpg","90076169_3.jpg","90076169_4.jpg","90076169_5.jpg","90076169_6.jpg","90076169_7.jpg","90076169_8.jpg","90076169_9.jpg","90076195_1.jpg","90076195_2.jpg","90076195_3.jpg","90076195_4.jpg","90076195_5.jpg","90076195_6.jpg","90076195_7.jpg","90076195_8.jpg","90076195_9.jpg","90076196_1.jpg","90076196_2.jpg","90076196_3.jpg","90076196_4.jpg","90076196_5.jpg","90076196_6.jpg","90076196_7.jpg","90076196_8.jpg","90076196_9.jpg","90077875_1.jpg","90077875_2.jpg","90078512_1.jpg","90078512_2.jpg","90078512_3.jpg","90078512_4.jpg","90078512_5.jpg","90078512_6.jpg","90078512_7.jpg","90078513_1.jpg","90078513_2.jpg","90078513_3.jpg","90078513_4.jpg","90078513_5.jpg","90078513_6.jpg","90078513_7.jpg","90078514_1.jpg","90078514_2.jpg","90078514_3.jpg","90078514_4.jpg","90078514_5.jpg","90078514_6.jpg","90078514_7.jpg","90078515_1.jpg","90078515_2.jpg","90078515_3.jpg","90078515_4.jpg","90078515_5.jpg","90078515_6.jpg","90078515_7.jpg","90078516_1.jpg","90078516_2.jpg","90078516_4.jpg","90078516_5.jpg","90078516_6.jpg","90078516_7.jpg","90078603_1.jpg","90078603_2.jpg","90078694_1.jpg","90078694_2.jpg","90078694_3.jpg","90078694_4.jpg","90078694_5.jpg","90078694_6.jpg","90078694_7.jpg","90078695_1.jpg","90078695_2.jpg","90078695_3.jpg","90078695_4.jpg","90078695_5.jpg","90078695_6.jpg","90078695_7.jpg","90078696_1.jpg","90078696_2.jpg","90078696_3.jpg","90078696_4.jpg","90078696_5.jpg","90078696_6.jpg","90078696_7.jpg","90078697_1.jpg","90078697_2.jpg","90078697_3.jpg","90078697_4.jpg","90078697_5.jpg","90078697_6.jpg","90078697_7.jpg","90078698_1.jpg","90078698_2.jpg","90078698_3.jpg","90078698_4.jpg","90078698_5.jpg","90078698_6.jpg","90078698_7.jpg","90078699_1.jpg","90078699_2.jpg","90078699_3.jpg","90078699_4.jpg","90078699_5.jpg","90078699_6.jpg","90078699_7.jpg","90078700_1.jpg","90078700_2.jpg","90078700_3.jpg","90078700_4.jpg","90078700_5.jpg","90078700_6.jpg","90078700_7.jpg","90078701_1.jpg","90078701_2.jpg","90078701_3.jpg","90078701_4.jpg","90078701_5.jpg","90078701_6.jpg","90078701_7.jpg","90078702_1.jpg","90078702_2.jpg","90078702_3.jpg","90078702_4.jpg","90078702_5.jpg","90078702_6.jpg","90078702_7.jpg","90078703_1.jpg","90078703_2.jpg","90078703_3.jpg","90078703_4.jpg","90078703_5.jpg","90078703_6.jpg","90078703_7.jpg","90080091_1.jpg","90080091_2.jpg","90080091_3.jpg","90080091_4.jpg","90080091_5.jpg","90080091_6.jpg","90080091_7.jpg","90080091_8.jpg","90080091_9.jpg","90080092_1.jpg","90080092_2.jpg","90080092_3.jpg","90080092_4.jpg","90080092_5.jpg","90080092_6.jpg","90080092_7.jpg","90080092_8.jpg","90080092_9.jpg","90080094_1.jpg","90080094_2.jpg","90080094_3.jpg","90080094_4.jpg","90080094_5.jpg","90080094_6.jpg","90080094_7.jpg","90080094_8.jpg","90080094_9.jpg","90080095_1.jpg","90080095_2.jpg","90080095_3.jpg","90080095_4.jpg","90080095_5.jpg","90080095_6.jpg","90080095_7.jpg","90080095_8.jpg","90080095_9.jpg","90080097_1.jpg","90080097_2.jpg","90080097_3.jpg","90080097_4.jpg","90080097_5.jpg","90080097_6.jpg","90080097_7.jpg","90080097_8.jpg","90080097_9.jpg","90080098_1.jpg","90080098_2.jpg","90080098_3.jpg","90080098_4.jpg","90080098_5.jpg","90080098_6.jpg","90080098_7.jpg","90080098_8.jpg","90080098_9.jpg","90080100_1.jpg","90080100_2.jpg","90080100_3.jpg","90080100_4.jpg","90080100_5.jpg","90080100_6.jpg","90080100_7.jpg","90080100_8.jpg","90080100_9.jpg","90080101_1.jpg","90080101_2.jpg","90080101_3.jpg","90080101_4.jpg","90080101_5.jpg","90080101_6.jpg","90080101_7.jpg","90080101_8.jpg","90080101_9.jpg","90080103_1.jpg","90080103_2.jpg","90080103_3.jpg","90080103_4.jpg","90080103_5.jpg","90080103_6.jpg","90080103_7.jpg","90080103_8.jpg","90080103_9.jpg","90080104_1.jpg","90080104_2.jpg","90080104_3.jpg","90080104_4.jpg","90080104_5.jpg","90080104_6.jpg","90080104_7.jpg","90080104_8.jpg","90080104_9.jpg","90080105_1.jpg","90080105_2.jpg","90080106_1.jpg","90080106_2.jpg","90080107_1.jpg","90080107_2.jpg","90080108_1.jpg","90080108_2.jpg","90080109_1.jpg","90080109_2.jpg","90080111_1.jpg","90080111_2.jpg","90080111_3.jpg","90080111_4.jpg","90080111_5.jpg","90080111_6.jpg","90080111_7.jpg","90080111_8.jpg","90080111_9.jpg","90080112_1.jpg","90080112_2.jpg","90080112_3.jpg","90080112_4.jpg","90080112_5.jpg","90080112_6.jpg","90080112_7.jpg","90080112_8.jpg","90080112_9.jpg","90080114_1.jpg","90080114_2.jpg","90080114_3.jpg","90080114_4.jpg","90080114_5.jpg","90080114_6.jpg","90080114_7.jpg","90080114_8.jpg","90080114_9.jpg","90080115_1.jpg","90080115_2.jpg","90080115_3.jpg","90080115_4.jpg","90080115_5.jpg","90080115_6.jpg","90080115_7.jpg","90080115_8.jpg","90080115_9.jpg","90080117_1.jpg","90080117_2.jpg","90080117_3.jpg","90080117_4.jpg","90080117_5.jpg","90080117_6.jpg","90080117_7.jpg","90080117_8.jpg","90080117_9.jpg","90080118_1.jpg","90080118_2.jpg","90080118_3.jpg","90080118_4.jpg","90080118_5.jpg","90080118_6.jpg","90080118_7.jpg","90080118_8.jpg","90080118_9.jpg","90080120_1.jpg","90080120_2.jpg","90080120_3.jpg","90080120_4.jpg","90080120_5.jpg","90080120_6.jpg","90080120_7.jpg","90080120_8.jpg","90080120_9.jpg","90080121_1.jpg","90080121_2.jpg","90080121_3.jpg","90080121_4.jpg","90080121_5.jpg","90080121_6.jpg","90080121_7.jpg","90080121_8.jpg","90080121_9.jpg","90080123_1.jpg","90080123_2.jpg","90080123_3.jpg","90080123_4.jpg","90080123_5.jpg","90080123_6.jpg","90080123_7.jpg","90080123_8.jpg","90080123_9.jpg","90080124_1.jpg","90080124_2.jpg","90080124_3.jpg","90080124_4.jpg","90080124_5.jpg","90080124_6.jpg","90080124_7.jpg","90080124_8.jpg","90080124_9.jpg","90080141_1.jpg","90080141_2.jpg","90080141_3.jpg","90080141_4.jpg","90080141_5.jpg","90080141_6.jpg","90080141_7.jpg","90080141_8.jpg","90080141_9.jpg","90080144_1.jpg","90080144_2.jpg","90080144_3.jpg","90080144_4.jpg","90080144_5.jpg","90080144_6.jpg","90080144_7.jpg","90080144_8.jpg","90080144_9.jpg","90080147_1.jpg","90080147_2.jpg","90080147_3.jpg","90080147_4.jpg","90080147_5.jpg","90080147_6.jpg","90080147_7.jpg","90080147_8.jpg","90080147_9.jpg","90080150_1.jpg","90080150_2.jpg","90080150_3.jpg","90080150_4.jpg","90080150_5.jpg","90080150_6.jpg","90080150_7.jpg","90080150_8.jpg","90080150_9.jpg","90080153_1.jpg","90080153_2.jpg","90080153_3.jpg","90080153_4.jpg","90080153_5.jpg","90080153_6.jpg","90080153_7.jpg","90080153_8.jpg","90080153_9.jpg","90080556_1.jpg","90080556_2.jpg","90080556_3.jpg","90080556_4.jpg","90080556_5.jpg","90080556_6.jpg","90080557_1.jpg","90080557_2.jpg","90080557_3.jpg","90080557_4.jpg","90080557_5.jpg","90080557_6.jpg","90080558_1.jpg","90080558_2.jpg","90080558_3.jpg","90080558_4.jpg","90080558_5.jpg","90080558_6.jpg","90080559_1.jpg","90080559_2.jpg","90080559_3.jpg","90080559_4.jpg","90080559_5.jpg","90080559_6.jpg","90080828_1.jpg","90080828_2.jpg","90080828_3.jpg","90080828_4.jpg","90080828_5.jpg","90080828_6.jpg","90080828_7.jpg","90080830_1.jpg","90080830_2.jpg","90080830_3.jpg","90080830_4.jpg","90080830_5.jpg","90080830_6.jpg","90080830_7.jpg","90080831_1.jpg","90080831_2.jpg","90080831_3.jpg","90080831_4.jpg","90080831_5.jpg","90080831_6.jpg","90080831_7.jpg","90080832_1.jpg","90080832_2.jpg","90080832_3.jpg","90080832_4.jpg","90080832_5.jpg","90080832_6.jpg","90080832_7.jpg","90080833_1.jpg","90080833_2.jpg","90080833_3.jpg","90080833_4.jpg","90080833_5.jpg","90080833_6.jpg","90080833_7.jpg","90080834_1.jpg","90080834_2.jpg","90080834_3.jpg","90080834_4.jpg","90080834_5.jpg","90080834_6.jpg","90080834_7.jpg","90080835_1.jpg","90080835_2.jpg","90080835_3.jpg","90080835_4.jpg","90080835_5.jpg","90080835_6.jpg","90080835_7.jpg","90080836_1.jpg","90080836_2.jpg","90080836_3.jpg","90080836_4.jpg","90080836_5.jpg","90080836_6.jpg","90080836_7.jpg","90080837_1.jpg","90080837_2.jpg","90080837_3.jpg","90080837_4.jpg","90080837_5.jpg","90080837_6.jpg","90080837_7.jpg","90080838_1.jpg","90080838_2.jpg","90080838_3.jpg","90080838_4.jpg","90080838_5.jpg","90080838_6.jpg","90080838_7.jpg","90080839_1.jpg","90080839_2.jpg","90080839_3.jpg","90080839_4.jpg","90080839_5.jpg","90080839_6.jpg","90080839_7.jpg","90080839_8.jpg","90080839_9.jpg","90080840_1.jpg","90080840_2.jpg","90080840_3.jpg","90080840_4.jpg","90080840_5.jpg","90080840_6.jpg","90080840_7.jpg","90080840_8.jpg","90080840_9.jpg","90080841_1.jpg","90080841_2.jpg","90080841_3.jpg","90080841_4.jpg","90080841_5.jpg","90080841_6.jpg","90080841_7.jpg","90080841_8.jpg","90080841_9.jpg","90080842_1.jpg","90080842_2.jpg","90080842_3.jpg","90080842_4.jpg","90080842_5.jpg","90080842_6.jpg","90080842_7.jpg","90080842_8.jpg","90080842_9.jpg","90080843_1.jpg","90080843_2.jpg","90080843_3.jpg","90080843_4.jpg","90080843_5.jpg","90080843_6.jpg","90080843_7.jpg","90080843_8.jpg","90080843_9.jpg","90080844_1.jpg","90080844_2.jpg","90080844_3.jpg","90080844_4.jpg","90080844_5.jpg","90080844_6.jpg","90080844_7.jpg","90080844_8.jpg","90080844_9.jpg","90080845_1.jpg","90080845_2.jpg","90080845_3.jpg","90080845_4.jpg","90080845_5.jpg","90080845_6.jpg","90080845_7.jpg","90080845_8.jpg","90080845_9.jpg","90080846_1.jpg","90080846_2.jpg","90080846_3.jpg","90080846_4.jpg","90080846_5.jpg","90080846_6.jpg","90080846_7.jpg","90080846_8.jpg","90080846_9.jpg","90080847_1.jpg","90080847_2.jpg","90080847_3.jpg","90080847_4.jpg","90080847_5.jpg","90080847_6.jpg","90080847_7.jpg","90080847_8.jpg","90080847_9.jpg","90080848_1.jpg","90080848_2.jpg","90080848_3.jpg","90080848_4.jpg","90080848_5.jpg","90080848_6.jpg","90080848_7.jpg","90080848_8.jpg","90080848_9.jpg","90080849_1.jpg","90080849_2.jpg","90080849_3.jpg","90080849_4.jpg","90080849_5.jpg","90080849_6.jpg","90080849_7.jpg","90080850_1.jpg","90080850_2.jpg","90080850_3.jpg","90080850_4.jpg","90080850_5.jpg","90080850_6.jpg","90080850_7.jpg","90080851_1.jpg","90080851_2.jpg","90080851_3.jpg","90080851_4.jpg","90080851_5.jpg","90080851_6.jpg","90080851_7.jpg","90080852_1.jpg","90080852_2.jpg","90080852_3.jpg","90080852_4.jpg","90080852_5.jpg","90080852_6.jpg","90080852_7.jpg","90080853_1.jpg","90080853_2.jpg","90080853_3.jpg","90080853_4.jpg","90080853_5.jpg","90080853_6.jpg","90080853_7.jpg","90080883_1.jpg","90080883_2.jpg","90080883_3.jpg","90080883_4.jpg","90080883_5.jpg","90080883_6.jpg","90080883_7.jpg","90080883_8.jpg","90080883_9.jpg","90080884_1.jpg","90080884_2.jpg","90080884_3.jpg","90080884_4.jpg","90080884_5.jpg","90080884_6.jpg","90080884_7.jpg","90080884_8.jpg","90080884_9.jpg","90080885_1.jpg","90080885_2.jpg","90080885_3.jpg","90080885_4.jpg","90080885_5.jpg","90080885_6.jpg","90080885_7.jpg","90080885_8.jpg","90080885_9.jpg","90080886_1.jpg","90080886_2.jpg","90080886_3.jpg","90080886_4.jpg","90080886_5.jpg","90080886_6.jpg","90080886_7.jpg","90080886_8.jpg","90080886_9.jpg","90080887_1.jpg","90080887_2.jpg","90080887_3.jpg","90080887_4.jpg","90080887_5.jpg","90080887_6.jpg","90080887_7.jpg","90080887_8.jpg","90080887_9.jpg","90080888_1.jpg","90080888_2.jpg","90080888_3.jpg","90080888_4.jpg","90080888_5.jpg","90080888_6.jpg","90080888_7.jpg","90080888_8.jpg","90080888_9.jpg","90080889_1.jpg","90080889_2.jpg","90080889_3.jpg","90080889_4.jpg","90080889_5.jpg","90080889_6.jpg","90080889_7.jpg","90080889_8.jpg","90080889_9.jpg","90080890_1.jpg","90080890_2.jpg","90080890_3.jpg","90080890_4.jpg","90080890_5.jpg","90080890_6.jpg","90080890_7.jpg","90080890_8.jpg","90080890_9.jpg","90080891_1.jpg","90080891_2.jpg","90080891_3.jpg","90080891_4.jpg","90080891_5.jpg","90080891_6.jpg","90080891_7.jpg","90080891_8.jpg","90080891_9.jpg","90080892_1.jpg","90080892_2.jpg","90080892_3.jpg","90080892_4.jpg","90080892_5.jpg","90080892_6.jpg","90080892_7.jpg","90080892_8.jpg","90080892_9.jpg","90080893_1.jpg","90080893_2.jpg","90080893_3.jpg","90080893_4.jpg","90080893_5.jpg","90080893_6.jpg","90080893_7.jpg","90080893_8.jpg","90080893_9.jpg","90080894_1.jpg","90080894_2.jpg","90080894_3.jpg","90080894_4.jpg","90080894_5.jpg","90080894_6.jpg","90080894_7.jpg","90080894_8.jpg","90080894_9.jpg","90080895_1.jpg","90080895_2.jpg","90080895_3.jpg","90080895_4.jpg","90080895_5.jpg","90080895_6.jpg","90080895_7.jpg","90080895_8.jpg","90080895_9.jpg","90080896_1.jpg","90080896_2.jpg","90080896_3.jpg","90080896_4.jpg","90080896_5.jpg","90080896_6.jpg","90080896_7.jpg","90080896_8.jpg","90080896_9.jpg","90080897_1.jpg","90080897_2.jpg","90080897_3.jpg","90080897_4.jpg","90080897_5.jpg","90080897_6.jpg","90080897_7.jpg","90080897_8.jpg","90080897_9.jpg","90080898_1.jpg","90080898_2.jpg","90080898_3.jpg","90080898_4.jpg","90080898_5.jpg","90080898_6.jpg","90080898_7.jpg","90080898_8.jpg","90080898_9.jpg","90080899_1.jpg","90080899_2.jpg","90080899_3.jpg","90080899_4.jpg","90080899_5.jpg","90080899_6.jpg","90080899_7.jpg","90080899_8.jpg","90080899_9.jpg","90080900_1.jpg","90080900_2.jpg","90080900_3.jpg","90080900_4.jpg","90080900_5.jpg","90080900_6.jpg","90080900_7.jpg","90080900_8.jpg","90080900_9.jpg","90080901_01.jpg","90080901_2.jpg","90080901_3.jpg","90080901_4.jpg","90080901_5.jpg","90080901_6.jpg","90080901_7.jpg","90080901_8.jpg","90080901_9.jpg","90080902_1.jpg","90080902_2.jpg","90080902_3.jpg","90080902_4.jpg","90080902_5.jpg","90080902_6.jpg","90080902_7.jpg","90080902_8.jpg","90080902_9.jpg","90080904_01.jpg","90080904_2.jpg","90080904_3.jpg","90080904_4.jpg","90080904_5.jpg","90080904_6.jpg","90080904_7.jpg","90080904_8.jpg","90080904_9.jpg","90080905_1.jpg","90080905_2.jpg","90080905_3.jpg","90080905_4.jpg","90080905_5.jpg","90080905_6.jpg","90080905_7.jpg","90080905_8.jpg","90080905_9.jpg","90080906_01.jpg","90080906_2.jpg","90080906_3.jpg","90080906_4.jpg","90080906_5.jpg","90080906_6.jpg","90080906_7.jpg","90080906_8.jpg","90080906_9.jpg","90080907_1.jpg","90080907_2.jpg","90080907_3.jpg","90080907_4.jpg","90080907_5.jpg","90080907_6.jpg","90080907_7.jpg","90080907_8.jpg","90080907_9.jpg","90080908_01.jpg","90080908_2.jpg","90080908_3.jpg","90080908_4.jpg","90080908_5.jpg","90080908_6.jpg","90080908_7.jpg","90080908_8.jpg","90080908_9.jpg","90080909_1.jpg","90080909_2.jpg","90080909_3.jpg","90080909_4.jpg","90080909_5.jpg","90080909_6.jpg","90080909_7.jpg","90080909_8.jpg","90080909_9.jpg","90080910_1.jpg","90080910_2.jpg","90080910_3.jpg","90080910_4.jpg","90080910_5.jpg","90080910_6.jpg","90080910_7.jpg","90080910_8.jpg","90080910_9.jpg","90080911_1.jpg","90080911_2.jpg","90080911_3.jpg","90080911_4.jpg","90080911_5.jpg","90080911_6.jpg","90080911_7.jpg","90080911_8.jpg","90080911_9.jpg","90080912_1.jpg","90080912_2.jpg","90080912_3.jpg","90080912_4.jpg","90080912_5.jpg","90080912_6.jpg","90080912_7.jpg","90080912_8.jpg","90080912_9.jpg","90080913_1.jpg","90080913_2.jpg","90080913_3.jpg","90080913_4.jpg","90080913_5.jpg","90080913_6.jpg","90080913_7.jpg","90080913_8.jpg","90080913_9.jpg","90080914_1.jpg","90080914_2.jpg","90080914_3.jpg","90080914_4.jpg","90080914_5.jpg","90080914_6.jpg","90080914_7.jpg","90080914_8.jpg","90080914_9.jpg","90080915_1.jpg","90080915_2.jpg","90080915_3.jpg","90080915_4.jpg","90080915_5.jpg","90080915_6.jpg","90080915_7.jpg","90080915_8.jpg","90080915_9.jpg","90080916_1.jpg","90080916_2.jpg","90080916_3.jpg","90080916_4.jpg","90080916_5.jpg","90080916_6.jpg","90080916_7.jpg","90080916_8.jpg","90080916_9.jpg","90080917_1.jpg","90080917_2.jpg","90080917_3.jpg","90080917_4.jpg","90080917_5.jpg","90080917_6.jpg","90080917_7.jpg","90080917_8.jpg","90080917_9.jpg","90080918_1.jpg","90080918_2.jpg","90080918_3.jpg","90080918_4.jpg","90080918_5.jpg","90080918_6.jpg","90080918_7.jpg","90080918_8.jpg","90080918_9.jpg","90080919_1.jpg","90080919_2.jpg","90080919_3.jpg","90080919_4.jpg","90080919_5.jpg","90080919_6.jpg","90080919_7.jpg","90080919_8.jpg","90080919_9.jpg","90080920_1.jpg","90080920_2.jpg","90080920_3.jpg","90080920_4.jpg","90080920_5.jpg","90080920_6.jpg","90080920_7.jpg","90080920_8.jpg","90080920_9.jpg","90080921_1.jpg","90080921_2.jpg","90080921_3.jpg","90080921_4.jpg","90080921_5.jpg","90080921_6.jpg","90080921_7.jpg","90080921_8.jpg","90080921_9.jpg","90080922_1.jpg","90080922_2.jpg","90080922_3.jpg","90080922_4.jpg","90080922_5.jpg","90080922_6.jpg","90080922_7.jpg","90080922_8.jpg","90080922_9.jpg","90080923_1.jpg","90080923_2.jpg","90080923_3.jpg","90080923_4.jpg","90080923_5.jpg","90080923_6.jpg","90080923_7.jpg","90080923_8.jpg","90080923_9.jpg","90080924_1.jpg","90080924_2.jpg","90080924_3.jpg","90080924_4.jpg","90080924_5.jpg","90080924_6.jpg","90080924_7.jpg","90080924_8.jpg","90080924_9.jpg","90080925_1.jpg","90080925_2.jpg","90080925_3.jpg","90080925_4.jpg","90080925_5.jpg","90080925_6.jpg","90080925_7.jpg","90080925_8.jpg","90080925_9.jpg","90080926_1.jpg","90080926_2.jpg","90080926_3.jpg","90080926_4.jpg","90080926_5.jpg","90080926_6.jpg","90080926_7.jpg","90080926_8.jpg","90080926_9.jpg","90080927_1.jpg","90080927_2.jpg","90080927_3.jpg","90080927_4.jpg","90080927_5.jpg","90080927_6.jpg","90080927_7.jpg","90080927_8.jpg","90080927_9.jpg","90080928_1.jpg","90080928_2.jpg","90080928_3.jpg","90080928_4.jpg","90080928_5.jpg","90080928_6.jpg","90080928_7.jpg","90080928_8.jpg","90080928_9.jpg","90080929_1.jpg","90080929_2.jpg","90080929_3.jpg","90080929_4.jpg","90080929_5.jpg","90080929_6.jpg","90080929_7.jpg","90080929_8.jpg","90080929_9.jpg","90080930_1.jpg","90080930_2.jpg","90080930_3.jpg","90080930_4.jpg","90080930_5.jpg","90080930_6.jpg","90080930_7.jpg","90080930_8.jpg","90080930_9.jpg","90080931_1.jpg","90080931_2.jpg","90080931_3.jpg","90080931_4.jpg","90080931_5.jpg","90080931_6.jpg","90080931_7.jpg","90080931_8.jpg","90080931_9.jpg","90080932_1.jpg","90080932_2.jpg","90080932_3.jpg","90080932_4.jpg","90080932_5.jpg","90080932_6.jpg","90080932_7.jpg","90080932_8.jpg","90080932_9.jpg","90080933_1.jpg","90080933_2.jpg","90080933_3.jpg","90080933_4.jpg","90080933_5.jpg","90080933_6.jpg","90080933_7.jpg","90080933_8.jpg","90080933_9.jpg","90080934_1.jpg","90080934_2.jpg","90080934_3.jpg","90080934_4.jpg","90080934_5.jpg","90080934_6.jpg","90080934_7.jpg","90080934_8.jpg","90080934_9.jpg","90080935_1.jpg","90080935_2.jpg","90080935_3.jpg","90080935_4.jpg","90080935_5.jpg","90080935_6.jpg","90080935_7.jpg","90080935_8.jpg","90080935_9.jpg","90080936_1.jpg","90080936_2.jpg","90080936_3.jpg","90080936_4.jpg","90080936_5.jpg","90080936_6.jpg","90080936_7.jpg","90080936_8.jpg","90080936_9.jpg","90080937_1.jpg","90080937_2.jpg","90080937_3.jpg","90080937_4.jpg","90080937_5.jpg","90080937_6.jpg","90080937_7.jpg","90080937_8.jpg","90080937_9.jpg","90080938_1.jpg","90080938_2.jpg","90080938_3.jpg","90080938_4.jpg","90080938_5.jpg","90080938_6.jpg","90080938_7.jpg","90080938_8.jpg","90080938_9.jpg","90080939_1.jpg","90080939_2.jpg","90080939_3.jpg","90080939_4.jpg","90080939_5.jpg","90080939_6.jpg","90080939_7.jpg","90080939_8.jpg","90080939_9.jpg","90080940_1.jpg","90080940_2.jpg","90080940_3.jpg","90080940_4.jpg","90080940_5.jpg","90080940_6.jpg","90080940_7.jpg","90080940_8.jpg","90080940_9.jpg","90080941_1.jpg","90080941_2.jpg","90080941_3.jpg","90080941_4.jpg","90080941_5.jpg","90080941_6.jpg","90080941_7.jpg","90080941_8.jpg","90080941_9.jpg","90080942_1.jpg","90080942_2.jpg","90080942_3.jpg","90080942_4.jpg","90080942_5.jpg","90080942_6.jpg","90080942_7.jpg","90080942_8.jpg","90080942_9.jpg","90080943_1.jpg","90080943_2.jpg","90080943_3.jpg","90080943_4.jpg","90080943_5.jpg","90080943_6.jpg","90080943_7.jpg","90080943_8.jpg","90080943_9.jpg","90080944_1.jpg","90080944_2.jpg","90080944_3.jpg","90080944_4.jpg","90080944_5.jpg","90080944_6.jpg","90080944_7.jpg","90080944_8.jpg","90080944_9.jpg","90080945_1.jpg","90080945_2.jpg","90080945_3.jpg","90080945_4.jpg","90080945_5.jpg","90080945_6.jpg","90080945_7.jpg","90080945_8.jpg","90080945_9.jpg","90080946_1.jpg","90080946_2.jpg","90080946_3.jpg","90080946_4.jpg","90080946_5.jpg","90080946_6.jpg","90080946_7.jpg","90080946_8.jpg","90080946_9.jpg","90080947_1.jpg","90080947_2.jpg","90080947_3.jpg","90080947_4.jpg","90080947_5.jpg","90080947_6.jpg","90080947_7.jpg","90080947_8.jpg","90080947_9.jpg","90080948_1.jpg","90080948_2.jpg","90080948_3.jpg","90080948_4.jpg","90080948_5.jpg","90080948_6.jpg","90080948_7.jpg","90080948_8.jpg","90080948_9.jpg","90080949_1.jpg","90080949_2.jpg","90080949_3.jpg","90080949_4.jpg","90080949_5.jpg","90080949_6.jpg","90080949_7.jpg","90080949_8.jpg","90080949_9.jpg","90080950_1.jpg","90080950_2.jpg","90080950_3.jpg","90080950_4.jpg","90080950_5.jpg","90080950_6.jpg","90080950_7.jpg","90080950_8.jpg","90080950_9.jpg","90080951_1.jpg","90080951_2.jpg","90080951_3.jpg","90080951_4.jpg","90080951_5.jpg","90080951_6.jpg","90080951_7.jpg","90080951_8.jpg","90080951_9.jpg","90080952_1.jpg","90080952_2.jpg","90080952_3.jpg","90080952_4.jpg","90080952_5.jpg","90080952_6.jpg","90080952_7.jpg","90080952_8.jpg","90080952_9.jpg","90080953_1.jpg","90080953_2.jpg","90080953_3.jpg","90080953_4.jpg","90080953_5.jpg","90080953_6.jpg","90080953_7.jpg","90080953_8.jpg","90080953_9.jpg","90080954_1.jpg","90080954_2.jpg","90080954_3.jpg","90080954_4.jpg","90080954_5.jpg","90080954_6.jpg","90080954_7.jpg","90080954_8.jpg","90080954_9.jpg","90080955_1.jpg","90080955_2.jpg","90080955_3.jpg","90080955_4.jpg","90080955_5.jpg","90080955_6.jpg","90080955_7.jpg","90080955_8.jpg","90080955_9.jpg","90080956_1.jpg","90080956_2.jpg","90080956_3.jpg","90080956_4.jpg","90080956_5.jpg","90080956_6.jpg","90080956_7.jpg","90080956_8.jpg","90080956_9.jpg","90080957_1.jpg","90080957_2.jpg","90080957_3.jpg","90080957_4.jpg","90080957_5.jpg","90080957_6.jpg","90080957_7.jpg","90080957_8.jpg","90080957_9.jpg","90080958_1.jpg","90080958_2.jpg","90080958_3.jpg","90080958_4.jpg","90080958_5.jpg","90080958_6.jpg","90080958_7.jpg","90080958_8.jpg","90080958_9.jpg","90080959_1.jpg","90080959_2.jpg","90080959_3.jpg","90080959_4.jpg","90080959_5.jpg","90080959_6.jpg","90080959_7.jpg","90080959_8.jpg","90080959_9.jpg","90080960_1.jpg","90080960_2.jpg","90080960_3.jpg","90080960_4.jpg","90080960_5.jpg","90080960_6.jpg","90080960_7.jpg","90080960_8.jpg","90080960_9.jpg","90080961_1.jpg","90080961_2.jpg","90080961_3.jpg","90080961_4.jpg","90080961_5.jpg","90080961_6.jpg","90080961_7.jpg","90080961_8.jpg","90080961_9.jpg","90080962_1.jpg","90080962_2.jpg","90080962_3.jpg","90080962_4.jpg","90080962_5.jpg","90080962_6.jpg","90080962_7.jpg","90080962_8.jpg","90080962_9.jpg","90080963_1.jpg","90080963_2.jpg","90080963_3.jpg","90080963_4.jpg","90080963_5.jpg","90080963_6.jpg","90080963_7.jpg","90080963_8.jpg","90080963_9.jpg","90080964_1.jpg","90080964_2.jpg","90080964_3.jpg","90080964_4.jpg","90080964_5.jpg","90080964_6.jpg","90080964_7.jpg","90080964_8.jpg","90080964_9.jpg","90080965_1.jpg","90080965_2.jpg","90080965_3.jpg","90080965_4.jpg","90080965_5.jpg","90080965_6.jpg","90080965_7.jpg","90080965_8.jpg","90080965_9.jpg","90080966_1.jpg","90080966_2.jpg","90080966_3.jpg","90080966_4.jpg","90080966_5.jpg","90080966_6.jpg","90080966_7.jpg","90080966_8.jpg","90080966_9.jpg","90080970_1.jpg","90080970_2.jpg","90080970_3.jpg","90080970_4.jpg","90080970_5.jpg","90080970_6.jpg","90080970_7.jpg","90080970_8.jpg","90080970_9.jpg","90080971_1.jpg","90080971_2.jpg","90080971_3.jpg","90080971_4.jpg","90080971_5.jpg","90080971_6.jpg","90080971_7.jpg","90080971_8.jpg","90080971_9.jpg"];
  2671.         $productos=$this->getDoctrine()->getRepository(Producto::class)->findall();
  2672.         $prods=[];
  2673.         foreach( $productos as $prod){
  2674.             $prods[$prod->getPlu()]=$prod;
  2675.         }
  2676.         foreach($photos as $ph){
  2677.             $id_index=explode("_",$ph);  
  2678.             // dd('entró a un foreach',$id_index[1]);
  2679.             $sku=$id_index[0];
  2680.             /* @var $producto Producto */
  2681.             $producto=$prods[$sku];
  2682.             $image_path="https://firebasestorage.googleapis.com/v0/b/romancerelax-2021.appspot.com/o/app_images%2F".$ph."?alt=media";
  2683.             if($id_index[1]=="1.jpg"){
  2684.                 // dd('entró a este if');
  2685.                 // $imagencargada=$producto->setImagen();
  2686.                 // if(!$imagencargada){
  2687.                     $producto->setImagen($image_path);
  2688.                     $em->persist($producto);
  2689.                 // }
  2690.             }else{
  2691.                 $image = new Image();
  2692.                 /* @Var $image Image */
  2693.                 $image->setImage($image_path);
  2694.                 $image->setProducto($producto);
  2695.                 $em->persist($image);             
  2696.             }
  2697.             $em->flush();
  2698.         }
  2699.     }
  2700.     /**
  2701.      * @Route("/ajaxdesplegable/{categoria}/romance/romancerelax", name="ajaxdesplegable")
  2702.      */
  2703.     public function ajaxdesplegable(Request $request$categoria)
  2704.     {
  2705.         // dd($categoria);
  2706.         $categoria=$this->getDoctrine()->getRepository(Categoria::class)->find($categoria);
  2707.         // dd($categoria);
  2708.         return $this->render('basic/busqueda2.html.twig', [
  2709.             'cat'=>$categoria
  2710.         ]);
  2711.         
  2712.     }
  2713.     /**
  2714.      * @Route("/api/ciudades/ro/ro")
  2715.      * @Method({"POST"})
  2716.      */
  2717.     public function getCiudades(Request $request)
  2718.     {
  2719.         $content $request->getContent();
  2720.         $request_get json_decode($contenttrue);
  2721.  
  2722.         $departamento_id $request_get["departamento"];
  2723.         $ciudades $this->getDoctrine()->getRepository(Ciudad::class)->createQueryBuilder('c')
  2724.             ->select('c.id''c.nombre')
  2725.             ->leftJoin('c.departamento''d')
  2726.             ->where('d.id = :departamentoid')
  2727.             ->setParameter('departamentoid'$departamento_id)
  2728.             ->orderBy('c.nombre''asc')
  2729.             ->getQuery()
  2730.             ->getArrayResult();
  2731.         return new Response(json_encode($ciudades));
  2732.     }
  2733.     /**
  2734.      * @Route("/validaremailregister/romance/romancevalida")
  2735.      */
  2736.     public function validaremailregister(Request $request)
  2737.     {
  2738.         $body json_decode($request->getContent(), true);
  2739.         /* @var $user Usuario */
  2740.         $user $body['email'];
  2741.         $usuario=$this->getDoctrine()->getRepository(Usuario::class)->findOneBy(array('email'=>$user));
  2742.         
  2743.         if($usuario){
  2744.             $msg = array('ok'=>false,'mensaje'=>"La dirección de correo electrónico ya está en uso por otra cuenta");
  2745.         }else{
  2746.             $msg = array('ok'=>true);
  2747.         }
  2748.         return new Response(json_encode($msg));
  2749.     }
  2750.     /**
  2751.      * @Route("/enviosuscripcion/ro/rom", name="enviosuscripcion")
  2752.      */
  2753.     public function enviosuscripcion(Request $request)
  2754.     {
  2755.         $mensaje = array("ok" => false"mensaje" => "error");
  2756.         $email=$request->get("email");
  2757.         $mensaje["ok"] = true;
  2758.         $mensaje["mensaje"] = "Suscripcion realizada.";
  2759.         $asunto "Suscripcion al Blog - Romance Relax.";
  2760.         $html $this->renderView('contact/suscrip_mail.html.twig', array(
  2761.             'email'=>$email,
  2762.         ));
  2763.         $this->qi->sendMail($asunto,$email,$html);
  2764.         $to $this->qi->getSetting('mail_recepcion_pedidos');
  2765.         $this->qi->sendMail($asunto,$to,$html);
  2766.         return new JsonResponse($mensaje);
  2767.     }
  2768. }