src/Controller/CatalogController.php line 95

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Func;
  4. use stdClass;
  5. use App\DTO\AppDTO;
  6. use App\Entity\Cat;
  7. use App\Entity\Page;
  8. use App\Entity\Prod;
  9. use App\Entity\Photo;
  10. use App\Entity\Catpage;
  11. use App\Entity\ProdViews;
  12. use App\Service\Utils\Bc;
  13. use App\Service\Cart\Cart;
  14. use RecursiveArrayIterator;
  15. use App\Service\Filter\Chars;
  16. use App\Service\Filter\Prods;
  17. use App\Model\Cat as ModelCat;
  18. use App\Service\Filter\Filter;
  19. use RecursiveIteratorIterator;
  20. use App\Model\Cart as ModelCart;
  21. use App\Model\Prod as ModelProd;
  22. use App\Repository\CatRepository;
  23. use App\Repository\PageRepository;
  24. use App\Repository\ProdRepository;
  25. use App\Repository\PhotoRepository;
  26. use App\Repository\CatpageRepository;
  27. use App\Repository\ProdViewsRepository;
  28. use Doctrine\ORM\EntityManagerInterface;
  29. use Symfony\Contracts\Cache\CacheInterface;
  30. use Doctrine\ORM\Tools\Pagination\Paginator;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use App\Service\Paginator as ServicePaginator;
  33. use App\Service\Statistics\ProdView;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Component\HttpFoundation\RequestStack;
  37. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. /** @package App\Controller */
  40. class CatalogController extends AbstractASController
  41. {
  42.     private CacheInterface $Cache;
  43.     private EntityManagerInterface $em;
  44.     protected AppDTO $app;
  45.     protected ModelProd $ModelProd;
  46.     protected Cart $Cart;
  47.     protected ModelCart $ModelCart;
  48.     // Repositories
  49.     protected CatRepository $Cats;
  50.     protected ProdRepository $Prods;
  51.     protected PageRepository $Pages;
  52.     protected CatpageRepository $Catpages;
  53.     protected PhotoRepository $Photos;
  54.     
  55.     protected ProdView $prodView;
  56.     public function __construct(CacheInterface $CacheEntityManagerInterface $emAppDTO $appModelProd $ModelProdCart $CartModelCart $ModelCartRequestStack $requestStackProdView $prodView)
  57.     {
  58.         $this->requestStack $requestStack;
  59.         $this->Cache $Cache;
  60.         $this->em $em;
  61.         $this->app $app;
  62.         $this->ModelProd $ModelProd;
  63.         $this->ModelCart $ModelCart;
  64.         $this->Cart $Cart;
  65.         $this->prodView $prodView;
  66.         $this->Cats $this->em->getRepository(Cat::class);
  67.         $this->Prods $this->em->getRepository(Prod::class);
  68.         $this->Pages $this->em->getRepository(Page::class);
  69.         $this->Catpages $this->em->getRepository(Catpage::class);
  70.         $this->Photos $this->em->getRepository(Photo::class);
  71.     }
  72.     #[Route('/catalog'name'app_catalog')]
  73.     public function index(): Response
  74.     {
  75.         return $this->redirectToRoute('home');
  76.     }
  77.     #[Route(path'/catalog/cat-{cat_id}-{cat_intname}'name'prod_list_cat_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  78.     #[Route(path'/catalog/cat-{cat_id}-{cat_intname}/filter-{filters}'name'prod_list_cat_filte_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  79.     #[Route(path'/catalog/{spec}/cat-{cat_id}-{cat_intname}/filter-{filters}'name'prod_list_cat_spec_filter_no_locale'defaults: ['_locale' => '%app.default_lang%'], requirements: ['spec' => 'new|action|pop|onsale|mix|search'])]
  80.     #[Route(path'/catalog/{spec}/cat-{cat_id}-{cat_intname}'name'prod_list_cat_spec_no_locale'defaults: ['_locale' => '%app.default_lang%'], requirements: ['spec' => 'new|action|pop|onsale|mix|search'])]
  81.     #[Route(path'/catalog/{spec}'name'prod_list_spec_no_locale'defaults: ['_locale' => '%app.default_lang%'], requirements: ['spec' => 'new|action|pop|onsale|mix|search'])]
  82.     #[Route(path'/{_locale}/catalog/cat-{cat_id}-{cat_intname}'name'prod_list_cat'requirements: ['_locale' => '%app.langs%'])]
  83.     #[Route(path'/{_locale}/catalog/cat-{cat_id}-{cat_intname}/filter-{filters}'name'prod_list_cat_filter'requirements: ['_locale' => '%app.langs%'])]
  84.     #[Route(path'/{_locale}/catalog/{spec}/cat-{cat_id}-{cat_intname}/filter-{filters}'name'prod_list_cat_spec_filter'requirements: ['_locale' => '%app.langs%''spec' => 'new|action|pop|onsale|mix|search'])]
  85.     #[Route(path'/{_locale}/catalog/{spec}/cat-{cat_id}-{cat_intname}'name'prod_list_cat_spec'requirements: ['_locale' => '%app.langs%''spec' => 'new|action|pop|onsale|mix|search'])]
  86.     #[Route(path'/{_locale}/catalog/{spec}'name'prod_list_spec'requirements: ['_locale' => '%app.langs%''spec' => 'new|action|pop|onsale|mix|search'])]
  87.     public function prodList(Request $requestSessionInterface $sessionModelCat $ModelCatProds $ModelProdint $cat_id 0string $cat_intname ''string $spec ''string $filters ''): Response
  88.     {
  89.         if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  90.             $bc = ["/" => $this->app->labels->get('home')];
  91.         } else {
  92.             $bc = ["/" $request->getLocale() . "/" => $this->app->labels->get('home')];
  93.         }
  94.         switch ($spec) {
  95.             case 'new':
  96.                 $bctype '/new';
  97.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  98.                     $bc["/catalog/new"] = $this->app->labels->get('main-mobile-buttons-1');
  99.                 } else {
  100.                     $bc["/" $request->getLocale() . "/catalog/new"] = $this->app->labels->get('main-mobile-buttons-1');
  101.                 }
  102.                 break;
  103.             case 'action':
  104.                 $bctype '/action';
  105.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  106.                     $bc["/catalog/action"] = $this->app->labels->get('main-mobile-buttons-2');
  107.                 } else {
  108.                     $bc["/" $request->getLocale() . "/catalog/action"] = $this->app->labels->get('main-mobile-buttons-2');
  109.                 }
  110.                 break;
  111.             case 'pop':
  112.                 $bctype '/pop';
  113.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  114.                     $bc["/catalog/pop"] = $this->app->labels->get('main-mobile-buttons-4');
  115.                 } else {
  116.                     $bc["/" $request->getLocale() . "/catalog/pop"] = $this->app->labels->get('main-mobile-buttons-4');
  117.                 }
  118.                 
  119.                 break;
  120.             case 'mix':
  121.                 $bctype '/mix';
  122.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  123.                     $bc["/catalog/mix"] = $this->app->labels->get('main-mobile-buttons-3');
  124.                 } else {
  125.                     $bc["/" $request->getLocale() . "/catalog/mix"] = $this->app->labels->get('main-mobile-buttons-3');
  126.                 }
  127.                 break;
  128.             case 'onsale':
  129.                 $bctype '/onsale';
  130.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  131.                     $bc["/catalog/onsale"] = $this->app->labels->get('catalog-bc-sale');
  132.                 } else {
  133.                     $bc["/" $request->getLocale() . "/catalog/onsale"] = $this->app->labels->get('catalog-bc-sale');
  134.                 }                
  135.                 break;
  136.             case 'search':
  137.                 $bctype '/search';
  138.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  139.                     $bc["/catalog/search?q=" $request->get('q')] = $this->app->labels->get('catalog-bc-1') . ": \"" $request->get('q') . "\"";
  140.                 } else {
  141.                     $bc["/" $request->getLocale() . "/catalog/search?q=" $request->get('q')] = $this->app->labels->get('catalog-bc-1') . ": \"" $request->get('q') . "\"";
  142.                 }                
  143.                 break;
  144.             case '':
  145.                 $bctype '';
  146.                 break;
  147.         }
  148.         $bcc = [];
  149.         $is_filter 0;
  150.         $noindex 0;
  151.         $catpage null;
  152.         $showcont 1;
  153.         if ($request->get('filter')) {
  154.             return $this->redirect($this->_makeFilterUrl($request$spec));
  155.         }
  156.         if ($request->get('results') && $request->get('results') != $session->get('results')) {
  157.             $session->set('results'$request->get('results'));
  158.         }
  159.         if ($request->get('view') === 'list' || $request->get('view') === 'grid') {
  160.             setcookie("view_mode"$_GET['view'], time() + 86400 365'/');
  161.         }
  162.         $results $session->get('results') ?? 30;
  163.         $start = (int) $request->query->get('start');
  164.         $view_mode $request->get('view') ?? $request->cookies->get('view_mode') ?? 'list';
  165.         if ($spec) {
  166.             $page $this->Pages->findOneBy(['intname' => 'catalog/' $spec]);
  167.         } else {
  168.             $page $this->Pages->findOneBy(['intname' => 'catalog']);
  169.         }
  170.         if (!$page) {
  171.             $page = new Page();
  172.         }
  173.         $cont '';
  174.         if ($cat_id) {
  175.             $cat_row $row $this->Cats->find($cat_id);
  176.             if ($row === null ||!$row->isVisible() || $row->getIntname() != $cat_intname) {
  177.                 throw $this->createNotFoundException('Page not found');
  178.             }
  179.             $page->setName($row->getName());
  180.             $page->setCont($row->getCont());
  181.             $page->setCont2($row->getCont2());
  182.             $page->setTitle(!empty($row->getTitle()) ? $row->getTitle() : Func::mess_from_tmp($this->app->templates->get('cat_title'), array("name" => $row->getName())));
  183.             $page->setName($row->getName());
  184.             $page->setH1($row->getH1() ? $row->getH1() : $row->getName());
  185.             $page->setKw($row->getKw());
  186.             $page->setDescr(!empty($row->getDescr()) ? $row->getDescr() : Func::mess_from_tmp($this->app->templates->get('cat_desc'), array("name" => $row->getName())));
  187.             $cont $row->getCont();
  188.             $tree array_reverse($ModelCat->get_cat_tree_up($cat_id));
  189.             $bctype $spec '/' $spec '';
  190.             $locale $request->getLocale() == $this->getParameter('app.default_lang') ? '' '/'.$request->getLocale();
  191.             foreach ($tree as $k => $v) {
  192.                 $cat_row $this->Cats->find($v['id']);
  193.                 $searchq '';
  194.                 if ($request->query->get('q')) {
  195.                     $searchq '?q=' $request->query->get('q');
  196.                 }
  197.                 $relatives $this->Cats->findBy(['cat' => $cat_row->getCat(), 'visible' => 1]);
  198.                 $bc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = $cat_row->getName();
  199.                 
  200.                 foreach ($relatives as $k => $v) {
  201.                     if (!isset($bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()])) {
  202.                         $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = [];
  203.                     }
  204.                     
  205.                     $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()][$locale "/catalog/cat-" $v->getId() . "-" $v->getIntname()] = $v->getName();
  206.                 }
  207.             }
  208.         }
  209.         $prods $ModelProd->getProds($cat_id$spec$request->get('q'''));
  210.         if ($filters) {
  211.             $is_filter 1;
  212.             $sale 0;
  213.             preg_match_all("/char(\d+)\-([\d_]+)/"$filters$m);
  214.             $chars = [];
  215.             if (preg_match("/sale-(\w+)/"$filters$m2)) {
  216.                 $sale $m2[1];
  217.             }
  218.             foreach ($m[1] as $k => $v) {
  219.                 if (preg_match("/_/"$m[2][$k])) {
  220.                     preg_match_all("/(\d+)/"$m[2][$k], $mm);
  221.                     $chars[$v] = $mm[0];
  222.                 } else {
  223.                     $chars[$v][] = $m[2][$k];
  224.                 }
  225.             }
  226.             $catpage $this->Catpages->findOneBy(['intname' => str_replace("/".$request->getLocale()."/""/"$request->getPathInfo())]);
  227.             if ($catpage) {
  228.                 $is_catpage 1;
  229.                 $page->setName($catpage->getName());
  230.                 $page->setTitle($catpage->getTitle());
  231.                 $page->setH1($catpage->getH1());
  232.                 $page->setKw($catpage->getKw());
  233.                 $page->setDescr($catpage->getDescr());
  234.                 $page->setCont($catpage->getCont());
  235.                 $page->setCont2($catpage->getCont2());
  236.                 $page->setLocale($request->getLocale());                
  237.                 $cont $catpage->getCont();
  238.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  239.                     $bc["/" $catpage->getIntname()] = $catpage->getName();
  240.                 } else {
  241.                     $bc["/" $request->getLocale() . "/" $catpage->getIntname()] = $catpage->getName();
  242.                 }                
  243.             }
  244.             $chars['sale'] = $sale;
  245.             $prods $this->Prods->filter($prods$chars);
  246.         }
  247.         if ($request->get('order') == 'prior') {
  248.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriorDesc');
  249.         } elseif ($request->get('order') == 'changed' || (empty($request->get('order')) && $spec == 'new')) {
  250.             uasort($prods'\App\Repository\ProdRepository::sortArrayByChangedAsc');
  251.         } elseif ($request->get('order') == 'prior' && $request->get('desc_asc') == 'asc') {
  252.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriceAsc');
  253.         } elseif ($request->get('order') == 'prior' && $request->get('desc_asc') == 'desc') {
  254.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriceDesc');
  255.         }  elseif ($request->get('order') == 'skidka') {
  256.             uasort($prods'\App\Repository\ProdRepository::sortArrayBySkidkaDesc');
  257.         } else {
  258.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriorDesc');
  259.         }
  260.         $cnt count($prods);
  261.         $show_prods = [];
  262.         $k 1;
  263.         $i 1;
  264.         $prodstable = ['cat' => ($cat_id $page->getH1() : ''), 'cnt' => count($prods), 'minprice' => (count($prods) ? 999999999 0), 'maxprice' => 0'avgprice' => 0];
  265.         foreach ($prods as &$prod) {
  266.             if ($start != && $i++ <= $start) continue;
  267.             if ($k <= $results) {
  268.                 $show_prods[] = $prod;
  269.             }
  270.             $k++;
  271.             (($prod['price'] > 0) && ($prodstable['minprice'] > $prod['price'])) ? $prodstable['minprice'] = round($prod['price']) : false;
  272.             (($prod['price'] > 0) && ($prodstable['maxprice'] < $prod['price'])) ? $prodstable['maxprice'] = round($prod['price']) : false;
  273.             $prodstable['avgprice'] += $prod['price'];
  274.         }
  275.         if ($prodstable['cnt']) {
  276.             $prodstable['avgprice'] = round($prodstable['avgprice'] / $prodstable['cnt'], 2);
  277.         } else {
  278.             $prodstable['avgprice'] = 0;
  279.         }
  280.         if ($start) {
  281.             $page = new Page();
  282.             if (isset($row) && $row) {
  283.                 $page->setTitle(Func::mess_from_tmp($this->app->templates->get('cat_page_title'), array("page" => round($start $results) + 1"name" => $row->getName())));
  284.                 $page->setDescr(Func::mess_from_tmp($this->app->templates->get('cat_page_descr'), array("page" => round($start $results) + 1"name" => $row->getName())));
  285.             } else {
  286.                 $page->setTitle(Func::mess_from_tmp($this->app->templates->get('cat_page_title'), array("page" => round($start $results) + 1"name" => "")));
  287.                 $page->setDescr(Func::mess_from_tmp($this->app->templates->get('cat_page_descr'), array("page" => round($start $results) + 1"name" => "")));
  288.             }
  289.             
  290.             $page->setCont('');
  291.             $page->setCont2('');
  292.             $showcont 0;
  293.         }
  294.         /* For SEO. Indexing */        
  295.         $route $request->get('_route');
  296.         $canonical '';
  297.         if ($request->get('start')) {
  298.             $canonical "https://".$request->getHost().$request->getPathInfo()."?start=".$request->get('start');
  299.         } else {
  300.             $canonical "https://".$request->getHost().$request->getPathInfo();
  301.         }
  302.         
  303.         if ($request->get('start', -1) == || $request->get('start') == || $request->get('start') == 'x') {            
  304.             if ($spec && isset($row)) {
  305.                 return $this->redirectToRoute($request->get('_route'), ['cat_id' => $row->getId(), "cat_intname" => $row->getIntname(), "spec" => $spec], 301);
  306.             } elseif (isset($row)) {
  307.                 return $this->redirectToRoute($request->get('_route'), ['cat_id' => $row->getId(), "cat_intname" => $row->getIntname()], 301);
  308.             }
  309.         }
  310.         if ($start && count($show_prods) == 0) {
  311.             $this->createNotFoundException();
  312.         }
  313.         if (!empty($spec)) {
  314.             $noindex 1;
  315.         }
  316.         if ($is_filter || strpos($request->getUri(), 'filter') !== false) {
  317.             if ($catpage) {
  318.                 $noindex 0;
  319.             } else {
  320.                 $noindex 1;
  321.             }
  322.         }
  323.         if (count($request->query->all()) > 1) {
  324.             $noindex 1;
  325.         }
  326.         if (!empty($request->query->all()) && $start 30 != 0) {
  327.             $noindex 1;
  328.         }
  329.         if (!empty($request->get('results'))) {
  330.             $noindex 1;
  331.         }
  332.         if (!empty($request->get('view'))) {
  333.             $noindex 1;
  334.         }
  335.         /* End For SEO */
  336.         // Render Subcats
  337.         $subcat_list_rendered '';
  338.         if (empty($spec)) {
  339.             $cats $this->Cats->findBy(['visible' => 1'cat' => $cat_id], ["prior" => "desc""name" => "asc"]);
  340.             if (count($cats)) {
  341.                 $subcat_list_rendered $this->render('catalog/subcat-list.html.twig', [
  342.                     'cats' => $cats,
  343.                 ]);
  344.             }
  345.         }
  346.         // Ids in Cart
  347.         $cartids = [];
  348.         foreach ($this->Cart->getCart() as $k => $v) {
  349.             $cartids[] = $v['id'];
  350.         }
  351.         $cat $this->Cats->find($cat_id);
  352.         if ($request->get('test')) {
  353.             foreach ($show_prods as $k => $v) {
  354.                 echo $v['id']."-".$v['price']."<br>";
  355.             }
  356.         }
  357.         
  358.         if ($start) {
  359.             if ($cat) {
  360.                 $cat->setCont('');
  361.             }
  362.             
  363.             $showcont 0;
  364.         }
  365.         
  366.         $show_prods $this->Prods->prodArrayToEntity($show_prods);        
  367.         
  368.         if ($request->get('order') == 'prior') {
  369.             uasort($show_prods'\App\Repository\ProdRepository::sortByPriorDesc');
  370.         } elseif ($request->get('order') == 'changed' || (empty($request->get('order')) && $spec == 'new')) {
  371.             uasort($show_prods'\App\Repository\ProdRepository::sortByChangedAsc');
  372.         } elseif ($request->get('order') == 'price' && $request->get('desc_asc') == 'asc') {
  373.             uasort($show_prods'\App\Repository\ProdRepository::sortByPriceAsc');
  374.         } elseif ($request->get('order') == 'price' && $request->get('desc_asc') == 'desc') {                        
  375.             uasort($show_prods'\App\Repository\ProdRepository::sortByPriceDesc');            
  376.         } else {
  377.             uasort($show_prods'\App\Repository\ProdRepository::sortByPriorDesc');
  378.         }
  379.         foreach ($show_prods as $k => $v) {
  380.             $show_prods[$k]->setPrices($this->ModelProd->getPrices($v));
  381.             //TODO. Import Photos. Photos из базы
  382.             $show_prods[$k]->photos $this->Photos->findBy(['type' => 'prod''par' => $v]);
  383.         }
  384.         return $this->render('catalog/list.html.twig', [
  385.             'subcat_list_rendered' => $subcat_list_rendered,
  386.             'spec' => $spec,
  387.             'cat_id' => $cat_id,
  388.             'cat_intname' => $cat_intname,
  389.             'filters' => $filters,
  390.             'prods' => $show_prods,
  391.             'noindex' => $noindex,
  392.             'cat' => $cat,
  393.             'results' => $results,
  394.             'view_mode' => $view_mode,
  395.             'page' => $page,
  396.             'cont' => $cont,
  397.             'cartids' => $cartids,
  398.             'paginator' => new ServicePaginator($request->attributes->get('_route'), $cnt$results$start),
  399.             'bc' => $bc,
  400.             'bcc' => $bcc,
  401.             'canonical' => $canonical,
  402.             'showcont' => $showcont,
  403.             'prodstable' => $prodstable,
  404.             'cart_items' => $this->ModelCart->getCart(),
  405.         ]);
  406.     }
  407.     #[Route('/catalog/prod-{prod_id}'name'prod_cont_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  408.     #[Route('/{_locale}/catalog/prod-{prod_id}'name'prod_cont'requirements: ['_locale' => '%app.langs%'])]
  409.     public function prodCont(Request $requestModelCat $ModelCatint $prod_id 0): Response
  410.     {
  411.         if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  412.             $bc = ["/" => $this->app->labels->get('home')];
  413.         } else {
  414.             $bc = ["/" $request->getLocale() . "/" => $this->app->labels->get('home')];
  415.         }
  416.         
  417.         $bcc = [];
  418.         $prod $this->Prods->find($prod_id);
  419.         if (!$prod) {
  420.             throw $this->createNotFoundException('Page not found');
  421.         }
  422.         if ($prod) {
  423.             $prod->setPrices($this->ModelProd->getPrices($prod));
  424.         }
  425.         //Статистика показов
  426.         $this->prodView->addProd($prod->getId());
  427.         
  428.         //TODO. Import Photos. Photos из базы
  429.         $photos $this->Photos->findBy(['type' => 'prod''par' => $prod->getId()]);
  430.         $cat_id $prod->getCat();
  431.         $tree array_reverse($ModelCat->get_cat_tree_up($cat_id));
  432.         $locale $request->getLocale() == $this->getParameter('app.default_lang') ? '' '/'.$request->getLocale();
  433.         
  434.         foreach ($tree as $k => $v) {
  435.             $cat_row $this->Cats->find($v['id']);
  436.             $searchq '';
  437.             if ($request->query->get('q')) {
  438.                 $searchq '?q=' $request->query->get('q');
  439.             }
  440.             $relatives $this->Cats->findBy(['cat' => $cat_row->getCat(), 'visible' => 1]);
  441.             $bc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = $cat_row->getName();
  442.             
  443.             foreach ($relatives as $k => $v) {
  444.                 if (!isset($bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()])) {
  445.                     $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = [];
  446.                 }
  447.                 
  448.                 $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()][$locale "/catalog/cat-" $v->getId() . "-" $v->getIntname()] = $v->getName();
  449.             }
  450.         }
  451.         
  452.         $prod_chars $this->Prods->getprodchars($prod_id);
  453.         $prod_childs $this->Prods->getprodchilds($prod_id);
  454.         //TODO. Alex. SEO
  455.         $page = new Page();
  456.         $page->setTitle(Func::mess_from_tmp($this->app->templates->get('prod_title'), array("name" => $prod->getName())));
  457.         $page->setDescr(Func::mess_from_tmp($this->app->templates->get('prod_descr'), array("name" => $prod->getName())));
  458.         $page->setCont('');
  459.         $page->setCont2('');
  460.         
  461.         return $this->render('catalog/cont.html.twig', [
  462.             'page' => $page,
  463.             'prod' => $prod,
  464.             'photos' => $photos,
  465.             'bc' => $bc,
  466.             'bcc' => $bcc,
  467.             'chars' => $prod_chars,
  468.             'childs' => $prod_childs,
  469.             'cart_items' => $this->ModelCart->getCart(),
  470.         ]);
  471.     }
  472.     #[Route('/catalog/prod/ajax/{prod_id}'name'prod_ajax_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  473.     #[Route('/{_locale}/catalog/prod/ajax/{prod_id}'name'prod_ajax'requirements: ['_locale' => '%app.langs%'])]
  474.     public function prodAjaxCont(Request $requestint $prod_id 0): Response
  475.     {
  476.         $prod $this->Prods->find($prod_id);
  477.         if ($prod) {
  478.             $prod->setPrices($this->ModelProd->getPrices($prod));
  479.         }
  480.         //TODO. Import Photos. Photos из базы
  481.         $photos $this->Photos->findBy(['type' => 'prod''par' => $prod->getId()]);
  482.         $photosarray = [];
  483.         foreach ($photos as $photo) {
  484.             $obj = new stdClass();
  485.             $obj->id $photo->getId();
  486.             $photosarray[] = $obj;
  487.         }
  488.         $newprod = [
  489.             'name' => $prod->getName(),
  490.             'labels' => $this->render('catalog/block/prod-labels.html.twig', [
  491.                 'prodone' => $prod,
  492.             ])->getContent(),
  493.             'price' => $this->render('catalog/block/prod-price.html.twig', [
  494.                 'prodone' => $prod,
  495.             ])->getContent(),
  496.             'inpack' => $this->render('catalog/block/prod-inpack.html.twig', [
  497.                 'prodone' => $prod,
  498.             ])->getContent(),
  499.             'weight' => $this->render('catalog/block/prod-weight.html.twig', [
  500.                 'prodone' => $prod,
  501.             ])->getContent(),
  502.             'form' => $this->render('catalog/block/prod-form.html.twig', [
  503.                 'prodone' => $prod,
  504.             ])->getContent(),
  505.             'wishlist' => $this->render('catalog/block/prod-wishlist.html.twig', [
  506.                 'prodone' => $prod,
  507.             ])->getContent(),
  508.             'photos' => $photosarray,
  509.         ];
  510.         return $this->render('catalog/ajax.html.twig', [
  511.             'prod' => json_encode($newprod),
  512.         ]);
  513.     }
  514.     #[Route(path'/catalog/getnum/{cat_id}'name'getnum_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  515.     #[Route(path'/catalog/{spec}/getnum/{cat_id}'name'getnum_spec_no_locale'defaults: ['_locale' => '%app.default_lang%'], requirements: ['spec' => 'new|action|pop|onsale|mix|search'])]
  516.     #[Route(path'/{_locale}/catalog/getnum/{cat_id}'name'getnum'requirements: ['_locale' => '%app.langs%'])]
  517.     #[Route(path'/{_locale}/catalog/{spec}/getnum/{cat_id}'name'getnum_spec'requirements: ['_locale' => '%app.langs%''spec' => 'new|action|pop|onsale|mix|search'])]
  518.     public function getNum(Request $requestProds $ModelProdChars $ModelCharint $cat_id 0string $spec ''): Response
  519.     {
  520.         $result = [];
  521.         $prods $ModelProd->getProds($cat_id$spec);
  522.         $chars $ModelChar->getChars($cat_id);
  523.         $charvals $ModelChar->getCharVals($cat_id);
  524.         $get_chars $ModelProd->getchars($request->query->all());
  525.         //$result = array("num" => count($ModelProd->filter($request->query->all(), $prods)));
  526.         $prods_filtered $this->Prods->filter($prods$get_chars);
  527.         $result = array("num" => count($prods_filtered));
  528.         foreach ($chars as $k => $char) {
  529.             foreach ($charvals[$char->getId()] as $k => $cv) {
  530.                 $result['prodcount'][$cv->getId()] = $ModelProd->prodcount($prods$get_chars$char->getId(), $cv->getId());
  531.             }
  532.             $result['prodcount']['action'] = $ModelProd->prodcount($prods$get_chars'action'1);
  533.             $result['prodcount']['new'] = $ModelProd->prodcount($prods$get_chars'new'1);
  534.             $result['prodcount']['pop'] = $ModelProd->prodcount($prods$get_chars'pop'1);
  535.             $result['prodcount']['mix'] = $ModelProd->prodcount($prods$get_chars'mix'1);
  536.         }
  537.         if (is_array($get_chars)) {
  538.             $result['chars'] = array_keys($get_chars);
  539.             $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($get_chars));
  540.             foreach ($it as $v) {
  541.                 $result['charvals'][] = $v;
  542.             }
  543.         } else {
  544.             $result['charvals'] = array();
  545.             $result['chars'] = array();
  546.         }
  547.         return $this->json($result);
  548.     }
  549.     private function _makeFilterUrl(Request $requeststring $spec): string
  550.     {
  551.         $url_redir $request->getPathInfo() . Filter::generate_url($request->query->all());
  552.         return $url_redir;
  553.     }
  554. }