src/Controller/CatalogController.php line 403

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