src/Controller/CatalogController.php line 543

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.         $prods $ModelProd->getProds($cat_id$spec$request->get('q'''));
  231.         if ($filters) {
  232.             $is_filter 1;
  233.             $sale 0;
  234.             preg_match_all("/char(\d+)\-([\d_]+)/"$filters$m);
  235.             $chars = [];
  236.             if (preg_match("/sale-(\w+)/"$filters$m2)) {
  237.                 $sale $m2[1];
  238.             }
  239.             foreach ($m[1] as $k => $v) {
  240.                 if (preg_match("/_/"$m[2][$k])) {
  241.                     preg_match_all("/(\d+)/"$m[2][$k], $mm);
  242.                     $chars[$v] = $mm[0];
  243.                 } else {
  244.                     $chars[$v][] = $m[2][$k];
  245.                 }
  246.             }
  247.             $catpage $this->Catpages->findOneBy(['intname' => str_replace("/".$request->getLocale()."/""/"$request->getPathInfo())]);
  248.             if ($catpage) {
  249.                 $is_catpage 1;
  250.                 $page->setName($catpage->getName());
  251.                 $page->setTitle($catpage->getTitle());
  252.                 $page->setH1($catpage->getH1());
  253.                 $page->setKw($catpage->getKw());
  254.                 $page->setDescr($catpage->getDescr());
  255.                 $page->setCont($catpage->getCont());
  256.                 $page->setCont2($catpage->getCont2());
  257.                 $page->setLocale($request->getLocale());                
  258.                 $cont $catpage->getCont();
  259.                 if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  260.                     $bc["/" $catpage->getIntname()] = $catpage->getName();
  261.                 } else {
  262.                     $bc["/" $request->getLocale() . "/" $catpage->getIntname()] = $catpage->getName();
  263.                 }                
  264.             }
  265.             $chars['sale'] = $sale;
  266.             $prods $this->Prods->filter($prods$chars);
  267.         }
  268.         if ($request->get('order') == 'prior') {
  269.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriorDesc');
  270.         } elseif ($request->get('order') == 'changed' || (empty($request->get('order')) && $spec == 'new')) {
  271.             uasort($prods'\App\Repository\ProdRepository::sortArrayByChangedAsc');
  272.         } elseif ($request->get('order') == 'prior' && $request->get('desc_asc') == 'asc') {
  273.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriceAsc');
  274.         } elseif ($request->get('order') == 'prior' && $request->get('desc_asc') == 'desc') {
  275.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriceDesc');
  276.         }  elseif ($request->get('order') == 'skidka') {
  277.             uasort($prods'\App\Repository\ProdRepository::sortArrayBySkidkaDesc');
  278.         } else {
  279.             uasort($prods'\App\Repository\ProdRepository::sortArrayByPriorDesc');
  280.         }
  281.         $cnt count($prods);
  282.         $show_prods = [];
  283.         $k 1;
  284.         $i 1;
  285.         $prodstable = ['cat' => ($cat_id $page->getH1() : ''), 'cnt' => count($prods), 'minprice' => (count($prods) ? 999999999 0), 'maxprice' => 0'avgprice' => 0];
  286.         foreach ($prods as &$prod) {
  287.             if ($start != && $i++ <= $start) continue;
  288.             if ($k <= $results) {
  289.                 $show_prods[] = $prod;
  290.             }
  291.             $k++;
  292.             (($prod['price'] > 0) && ($prodstable['minprice'] > $prod['price'])) ? $prodstable['minprice'] = round($prod['price']) : false;
  293.             (($prod['price'] > 0) && ($prodstable['maxprice'] < $prod['price'])) ? $prodstable['maxprice'] = round($prod['price']) : false;
  294.             $prodstable['avgprice'] += $prod['price'];
  295.         }
  296.         if ($prodstable['cnt']) {
  297.             $prodstable['avgprice'] = round($prodstable['avgprice'] / $prodstable['cnt'], 2);
  298.         } else {
  299.             $prodstable['avgprice'] = 0;
  300.         }
  301.         if ($start) {
  302.             $page = new Page();
  303.             if (isset($row) && $row) {
  304.                 $page->setTitle(Func::mess_from_tmp($this->app->templates->get('cat_page_title'), array("page" => round($start $results) + 1"name" => $row->getName())));
  305.                 $page->setDescr(Func::mess_from_tmp($this->app->templates->get('cat_page_descr'), array("page" => round($start $results) + 1"name" => $row->getName())));
  306.             } else {
  307.                 $page->setTitle(Func::mess_from_tmp($this->app->templates->get('cat_page_title'), array("page" => round($start $results) + 1"name" => "")));
  308.                 $page->setDescr(Func::mess_from_tmp($this->app->templates->get('cat_page_descr'), array("page" => round($start $results) + 1"name" => "")));
  309.             }
  310.             
  311.             $page->setCont('');
  312.             $page->setCont2('');
  313.             $showcont 0;
  314.         }
  315.         /* For SEO. Indexing */        
  316.         $route $request->get('_route');
  317.         $canonical '';
  318.         if ($request->get('start')) {
  319.             $canonical "https://".$request->getHost().$request->getPathInfo()."?start=".$request->get('start');
  320.         } else {
  321.             $canonical "https://".$request->getHost().$request->getPathInfo();
  322.         }
  323.         
  324.         if ($request->get('start', -1) == || $request->get('start') == || $request->get('start') == 'x') {            
  325.             if ($spec && isset($row)) {
  326.                 return $this->redirectToRoute($request->get('_route'), ['cat_id' => $row->getId(), "cat_intname" => $row->getIntname(), "spec" => $spec], 301);
  327.             } elseif (isset($row)) {
  328.                 return $this->redirectToRoute($request->get('_route'), ['cat_id' => $row->getId(), "cat_intname" => $row->getIntname()], 301);
  329.             }
  330.         }
  331.         if ($start && count($show_prods) == 0) {
  332.             $this->createNotFoundException();
  333.         }
  334.         if (!empty($spec)) {
  335.             $noindex 1;
  336.         }
  337.         if ($is_filter || strpos($request->getUri(), 'filter') !== false) {
  338.             if ($catpage) {
  339.                 $noindex 0;
  340.             } else {
  341.                 $noindex 1;
  342.             }
  343.         }
  344.         if (count($request->query->all()) > 1) {
  345.             $noindex 1;
  346.         }
  347.         if (!empty($request->query->all()) && $start 30 != 0) {
  348.             $noindex 1;
  349.         }
  350.         if (!empty($request->get('results'))) {
  351.             $noindex 1;
  352.         }
  353.         if (!empty($request->get('view'))) {
  354.             $noindex 1;
  355.         }
  356.         /* End For SEO */
  357.         // Render Subcats
  358.         $subcat_list_rendered '';
  359.         if (empty($spec)) {
  360.             $cats $this->Cats->findBy(['visible' => 1'cat' => $cat_id], ["prior" => "desc""name" => "asc"]);
  361.             if (count($cats)) {
  362.                 $subcat_list_rendered $this->render('catalog/subcat-list.html.twig', [
  363.                     'cats' => $cats,
  364.                 ]);
  365.             }
  366.         }
  367.         // Ids in Cart
  368.         $cartids = [];
  369.         foreach ($this->Cart->getCart() as $k => $v) {
  370.             $cartids[] = $v['id'];
  371.         }
  372.         $cat $this->Cats->find($cat_id);
  373.         if ($request->get('test')) {
  374.             foreach ($show_prods as $k => $v) {
  375.                 echo $v['id']."-".$v['price']."<br>";
  376.             }
  377.         }
  378.         
  379.         if ($start) {
  380.             // if ($cat) {
  381.             //     $cat->setCont('');
  382.             // }
  383.             
  384.             $showcont 0;
  385.         }
  386.         
  387.         if (!empty($show_prods)) {
  388.             $show_prods $this->Prods->prodArrayToEntity($show_prods);        
  389.             
  390.             if ($request->get('order') == 'prior') {
  391.                 uasort($show_prods'\App\Repository\ProdRepository::sortByPriorDesc');
  392.             } elseif ($request->get('order') == 'changed' || (empty($request->get('order')) && $spec == 'new')) {
  393.                 uasort($show_prods'\App\Repository\ProdRepository::sortByChangedAsc');
  394.             } elseif ($request->get('order') == 'price' && $request->get('desc_asc') == 'asc') {
  395.                 uasort($show_prods'\App\Repository\ProdRepository::sortByPriceAsc');
  396.             } elseif ($request->get('order') == 'price' && $request->get('desc_asc') == 'desc') {                        
  397.                 uasort($show_prods'\App\Repository\ProdRepository::sortByPriceDesc');            
  398.             } else {
  399.                 uasort($show_prods'\App\Repository\ProdRepository::sortByPriorDesc');
  400.             }
  401.             foreach ($show_prods as $k => $v) {
  402.                 $show_prods[$k]->setPrices($this->ModelProd->getPrices($v));
  403.                 //TODO. Import Photos. Photos из базы
  404.                 $show_prods[$k]->photos $this->Photos->findBy(['type' => 'prod''par' => $v]);
  405.             }
  406.         }
  407.         
  408.         if ($request->get('q''')) {
  409.             $ga_events_search 1;
  410.             $ga_events_prodlist 0;
  411.         } else {
  412.             $ga_events_search 0;
  413.             $ga_events_prodlist 1;
  414.         }
  415.         // CatMenu
  416.         $cats $Cats->getSpecCatMenu($cat_id$spec$request->get('q'''));
  417.         $catpages = [];
  418.         //TODO. Сделать выборку catpages
  419.         // foreach ($cats as $k => $v) {            
  420.         //     foreach ($v as $kk => $subcat) {
  421.         //         $catpages[$subcat['id']] = $this->Catpages->findBy(["visible" => 1, "cat" => $subcat['id']], ["prior" => "DESC"]);
  422.         //         if (empty($catpages[$subcat['id']])) {
  423.         //             unset($catpages[$subcat['id']]);
  424.         //         }
  425.         //     }
  426.         // }
  427.         // Filter
  428.         $chars $Chars->getChars($cat_id);
  429.         $charvals $Chars->getCharVals($cat_id);
  430.         $filter_prods $ModelProd->getProds($cat_id);
  431.         $chars_selected = [];
  432.         $charvals_selected = [];
  433.         
  434.         if ($filters) {
  435.             preg_match_all("/char(\d+)\-([\d_]+)/"$filters$m);
  436.             if (preg_match("/sale-(\w+)/"$filters$m2)) {
  437.                 $chars_selected['sale'] = $m2[1];
  438.             }
  439.             if (isset($m[1]) && count($m[1])) {
  440.                 foreach ($m[1] as $k => $v) {
  441.                     if (preg_match("/_/"$m[2][$k])) {
  442.                         preg_match_all("/(\d+)/"$m[2][$k], $mm);
  443.                         $chars_selected[$v] = $mm[0];
  444.                     } else {
  445.                         $chars_selected[$v][] = $m[2][$k];
  446.                     }
  447.                 }
  448.             }         
  449.         }
  450.         return $this->render('catalog/list.html.twig', [
  451.             'subcat_list_rendered' => $subcat_list_rendered,
  452.             'spec' => $spec,
  453.             'cat_id' => $cat_id,
  454.             'cat_intname' => $cat_intname,
  455.             'filters' => $filters,
  456.             'chars' => $chars,
  457.             'charvals' => $charvals,
  458.             'chars_selected' => $chars_selected,
  459.             'charvals_selected' => $charvals_selected,
  460.             'filter_prods' => $filter_prods,
  461.             'speccatmenu_menu' => $cats,
  462.             'speccatmenu_spec' => $spec,
  463.             'speccatmenu_catpages' => $catpages,
  464.             'speccatmenu_parent_id' => ($cat) ? $cat->getCat() : 0,
  465.             'speccatmenu_cat_id' => $cat_id,
  466.             'speccatmenu_search' => $request->get('q'''),
  467.             'prods' => $show_prods,
  468.             'noindex' => $noindex,
  469.             'cat' => $cat,
  470.             'results' => $results,
  471.             'view_mode' => $view_mode,
  472.             'page' => $page,
  473.             'cont' => $cont,
  474.             'cartids' => $cartids,
  475.             'paginator' => new ServicePaginator($request->attributes->get('_route'), $cnt$results$start),
  476.             'prod_count' => $cnt,
  477.             'bc' => $bc,
  478.             'bcc' => $bcc,
  479.             'canonical' => $canonical,
  480.             'showcont' => $showcont,
  481.             'prodstable' => $prodstable,
  482.             'cart_items' => $this->ModelCart->getCart(),
  483.             'ga_events_search' => $ga_events_search,
  484.             'ga_events_prodlist' => $ga_events_prodlist,
  485.             'q' => $request->get('q'''),
  486.         ]);
  487.     }
  488.     #[Route('/catalog/prod-{prod_id}'name'prod_cont_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  489.     #[Route('/{_locale}/catalog/prod-{prod_id}'name'prod_cont'requirements: ['_locale' => '%app.langs%'])]
  490.     public function prodCont(Request $requestModelCat $ModelCatint $prod_id 0): Response
  491.     {
  492.         if ($request->getLocale() == $this->getParameter('app.default_lang')) {
  493.             $bc = ["/" => $this->app->labels->get('home')];
  494.         } else {
  495.             $bc = ["/" $request->getLocale() . "/" => $this->app->labels->get('home')];
  496.         }
  497.         
  498.         $bcc = [];
  499.         $prod $this->Prods->find($prod_id);
  500.         if (!$prod) {
  501.             throw $this->createNotFoundException('Page not found');
  502.         }
  503.         if ($prod) {
  504.             $prod->setPrices($this->ModelProd->getPrices($prod));
  505.         }
  506.         //Статистика показов
  507.         $this->prodView->addProd($prod->getId());
  508.         
  509.         //TODO. Import Photos. Photos из базы
  510.         $photos $this->Photos->findBy(['type' => 'prod''par' => $prod->getId()]);
  511.         $cat_id $prod->getCat();
  512.         $tree array_reverse($ModelCat->get_cat_tree_up($cat_id));
  513.         $locale $request->getLocale() == $this->getParameter('app.default_lang') ? '' '/'.$request->getLocale();
  514.         
  515.         foreach ($tree as $k => $v) {
  516.             $cat_row $this->Cats->find($v['id']);
  517.             $searchq '';
  518.             if ($request->query->get('q')) {
  519.                 $searchq '?q=' $request->query->get('q');
  520.             }
  521.             $relatives $this->Cats->findBy(['cat' => $cat_row->getCat(), 'visible' => 1], ['prior' => 'desc']);
  522.             $bc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = $cat_row->getName();
  523.             
  524.             foreach ($relatives as $k => $v) {
  525.                 if (!isset($bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()])) {
  526.                     $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()] = [];
  527.                 }
  528.                 
  529.                 $bcc[$locale "/catalog/cat-" $cat_row->getId() . "-" $cat_row->getIntname()][$locale "/catalog/cat-" $v->getId() . "-" $v->getIntname()] = $v->getName();
  530.             }
  531.         }
  532.         
  533.         $prod_chars $this->Prods->getprodchars($prod_id);
  534.         $prod_childs $this->Prods->getprodchilds($prod_id);
  535.         //TODO. Alex. SEO
  536.         $page = new Page();
  537.         $page->setTitle(Func::mess_from_tmp($this->app->templates->get('prod_title'), array("name" => $prod->getName())));
  538.         $page->setDescr(Func::mess_from_tmp($this->app->templates->get('prod_descr'), array("name" => $prod->getName())));
  539.         $page->setCont('');
  540.         $page->setCont2('');
  541.         
  542.         return $this->render('catalog/cont.html.twig', [
  543.             'page' => $page,
  544.             'prod' => $prod,
  545.             'photos' => $photos,
  546.             'bc' => $bc,
  547.             'bcc' => $bcc,
  548.             'chars' => $prod_chars,
  549.             'childs' => $prod_childs,
  550.             'cart_items' => $this->ModelCart->getCart(),
  551.             'ga_events_prodcont' => 1,
  552.         ]);
  553.     }
  554.     #[Route('/catalog/prod/ajax/{prod_id}'name'prod_ajax_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  555.     #[Route('/{_locale}/catalog/prod/ajax/{prod_id}'name'prod_ajax'requirements: ['_locale' => '%app.langs%'])]
  556.     public function prodAjaxCont(Request $requestint $prod_id 0): Response
  557.     {
  558.         $prod $this->Prods->find($prod_id);
  559.         if ($prod) {
  560.             $prod->setPrices($this->ModelProd->getPrices($prod));
  561.         }
  562.         //TODO. Import Photos. Photos из базы
  563.         $photos $this->Photos->findBy(['type' => 'prod''par' => $prod->getId()]);
  564.         $photosarray = [];
  565.         foreach ($photos as $photo) {
  566.             $obj = new stdClass();
  567.             $obj->id $photo->getId();
  568.             $photosarray[] = $obj;
  569.         }
  570.         $newprod = [
  571.             'name' => $prod->getName(),
  572.             'labels' => $this->render('catalog/block/prod-labels.html.twig', [
  573.                 'prodone' => $prod,
  574.             ])->getContent(),
  575.             'price' => $this->render('catalog/block/prod-price.html.twig', [
  576.                 'prodone' => $prod,
  577.             ])->getContent(),
  578.             'inpack' => $this->render('catalog/block/prod-inpack.html.twig', [
  579.                 'prodone' => $prod,
  580.             ])->getContent(),
  581.             'weight' => $this->render('catalog/block/prod-weight.html.twig', [
  582.                 'prodone' => $prod,
  583.             ])->getContent(),
  584.             'form' => $this->render('catalog/block/prod-form.html.twig', [
  585.                 'prodone' => $prod,
  586.             ])->getContent(),
  587.             'wishlist' => $this->render('catalog/block/prod-wishlist.html.twig', [
  588.                 'prodone' => $prod,
  589.             ])->getContent(),
  590.             'photos' => $photosarray,
  591.         ];
  592.         return $this->render('catalog/ajax.html.twig', [
  593.             'prod' => json_encode($newprod),
  594.         ]);
  595.     }
  596.     #[Route(path'/catalog/getnum/{cat_id}'name'getnum_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  597.     #[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'])]
  598.     #[Route(path'/{_locale}/catalog/getnum/{cat_id}'name'getnum'requirements: ['_locale' => '%app.langs%'])]
  599.     #[Route(path'/{_locale}/catalog/{spec}/getnum/{cat_id}'name'getnum_spec'requirements: ['_locale' => '%app.langs%''spec' => 'new|action|pop|onsale|mix|search|selection1|selection2'])]
  600.     public function getNum(Request $requestProds $ModelProdChars $ModelCharint $cat_id 0string $spec ''): Response
  601.     {
  602.         $result = [];
  603.         $prods $ModelProd->getProds($cat_id$spec);
  604.         $chars $ModelChar->getChars($cat_id);
  605.         $charvals $ModelChar->getCharVals($cat_id);
  606.         $get_chars $ModelProd->getchars($request->query->all());
  607.         //$result = array("num" => count($ModelProd->filter($request->query->all(), $prods)));
  608.         $prods_filtered $this->Prods->filter($prods$get_chars);
  609.         $result = array("num" => count($prods_filtered));
  610.         foreach ($chars as $k => $char) {
  611.             foreach ($charvals[$char->getId()] as $k => $cv) {
  612.                 $result['prodcount'][$cv->getId()] = $ModelProd->prodcount($prods$get_chars$char->getId(), $cv->getId());
  613.             }
  614.             $result['prodcount']['action'] = $ModelProd->prodcount($prods$get_chars'action'1);
  615.             $result['prodcount']['new'] = $ModelProd->prodcount($prods$get_chars'new'1);
  616.             $result['prodcount']['pop'] = $ModelProd->prodcount($prods$get_chars'pop'1);
  617.             $result['prodcount']['mix'] = $ModelProd->prodcount($prods$get_chars'mix'1);
  618.             $result['prodcount']['selection1'] = $ModelProd->prodcount($prods$get_chars'selection1'1);
  619.             $result['prodcount']['selection2'] = $ModelProd->prodcount($prods$get_chars'selection2'1);
  620.         }
  621.         if (is_array($get_chars)) {
  622.             $result['chars'] = array_keys($get_chars);
  623.             $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($get_chars));
  624.             foreach ($it as $v) {
  625.                 $result['charvals'][] = $v;
  626.             }
  627.         } else {
  628.             $result['charvals'] = array();
  629.             $result['chars'] = array();
  630.         }
  631.         return $this->json($result);
  632.     }
  633.     private function _makeFilterUrl(Request $requeststring $spec): string
  634.     {
  635.         $url_redir $request->getPathInfo() . Filter::generate_url($request->query->all());
  636.         return $url_redir;
  637.     }
  638. }