app/Customize/Controller/PageController.php line 450

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use Eccube\Form\Type\AddCartType;
  5. use Eccube\Repository\CategoryRepository;
  6. use Eccube\Repository\NewsRepository;
  7. use Eccube\Repository\ProductRepository;
  8. use Knp\Component\Pager\Paginator;
  9. use Plugin\CategoryRecommend4\Repository\CategoryRecommendProductRepository;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  13. use Symfony\Component\HttpFoundation\Request;
  14. class PageController extends AbstractController
  15. {
  16.     // 設定
  17.     protected $brandMaxCategoryId 3;
  18.     protected $shopDialogueId 100;
  19.     protected $shopEnsembleId 101;
  20.     protected $shopEnsembledeuxId 1217;
  21.     protected $shopFlairId 102;
  22.     protected $shopGatheringId 413;
  23.     protected $pickupCategoryId 1095;
  24.     /**
  25.      * @var ProductRepository
  26.      */
  27.     protected $productRepository;
  28.     /**
  29.      * @var NewsRepository
  30.      */
  31.     protected $newsRepository;
  32.     /**
  33.      * @var CategoryRepository
  34.      */
  35.     protected $categoryRepository;
  36.     /**
  37.      * @var CategoryRecommendProductRepository
  38.      */
  39.     protected $categoryRecommendProductRepository;
  40.     protected $brandCategories;
  41.     public function __construct(
  42.         ProductRepository $productRepository,
  43.         CategoryRepository $categoryRepository,
  44.         NewsRepository $newsRepository,
  45.         CategoryRecommendProductRepository $categoryRecommendProductRepository
  46.     ) {
  47.         $this->productRepository $productRepository;
  48.         $this->categoryRepository $categoryRepository;
  49.         $this->newsRepository $newsRepository;
  50.         $brandMaxCategory $this->categoryRepository->find($this->brandMaxCategoryId);
  51.         $this->brandCategories $this->categoryRepository->getList($brandMaxCategory);
  52.         $this->categoryRecommendProductRepository $categoryRecommendProductRepository;
  53.     }
  54.     /**
  55.      * @Method("GET")
  56.      * @Route("/faq", name="faq")
  57.      * @Template("Other/faq.twig")
  58.      */
  59.     public function faq()
  60.     {
  61.         return [];
  62.     }
  63.     /**
  64.      * @Method("GET")
  65.      * @Route("/about", name="about")
  66.      * @Template("Other/about.twig")
  67.      */
  68.     public function about()
  69.     {
  70.         return [];
  71.     }
  72.     /**
  73.      * @Method("GET")
  74.      * @Route("/dialogue", name="shop_dialogue_top")
  75.      * @Template("Shop/dialogue_top.twig")
  76.      */
  77.     public function shop_dialogue()
  78.     {
  79.         $info $this->getShopInfo($this->shopDialogueId'dialogue'5);
  80.         return $info;
  81.     }
  82.     /**
  83.      * @Method("GET")
  84.      * @Route("/blogs", name="blog_list")
  85.      * @Template("Blog/list.twig")
  86.      */
  87.     public function blog_list(Request $request)
  88.     {
  89.         $shop $request->query->get('shop');
  90.         $pageno $request->query->get('pageno'1);
  91.         $cat_id '';
  92.         if ($shop == 'dialogue') {
  93.             $cat_id 5;
  94.         } elseif ($shop == 'ensemble') {
  95.             $cat_id 2;
  96.         } elseif ($shop == 'ensembledeux') {
  97.             $cat_id 1521;
  98.         } elseif ($shop == 'flair') {
  99.             $cat_id 55;
  100.         } elseif ($shop == 'gathering') {
  101.             $cat_id 397;
  102.         }
  103.         if ($pageno == '1') {
  104.             $count 17;
  105.             $offset 0;
  106.         } else {
  107.             $count 18;
  108.             $offset 18 * ($pageno 1) - 1;
  109.         }
  110.         $args = [
  111.             'posts_per_page' => $count,
  112.             'offset' => $offset,
  113.             'orderby' => 'date',
  114.             'order' => 'DESC',
  115.         ];
  116.         if ($cat_id) {
  117.             $args['cat'] = $cat_id;
  118.         }
  119.         $the_query = new \WP_Query($args);
  120.         $blogs = [];
  121.         while ($the_query->have_posts()): $the_query->the_post();
  122.             $categories get_the_category();
  123.             $cat_name "";
  124.             if ($categories) {
  125.                 foreach ($categories as $category) {
  126.                     if ($category->term_id === || $category->term_id === || $category->term_id === 55 || $category->term_id === 397 || $category->term_id === 1521) {
  127.                         if ($cat_id) {
  128.                             if ($shop == 'dialogue' && $category->term_id === 5) {
  129.                                 $cat_name $category->name;
  130.                                 break;
  131.                             } elseif ($shop == 'ensemble' && $category->term_id === 2) {
  132.                             $cat_name $category->name;
  133.                             break;
  134.                         } elseif ($shop == 'ensembledeux' && $category->term_id === 1521) {
  135.                             $cat_name $category->name;
  136.                             break;
  137.                         } elseif ($shop == 'flair' && $category->term_id === 55) {
  138.                             $cat_name $category->name;
  139.                             break;
  140.                         } elseif ($shop == 'gathering' && $category->term_id === 397) {
  141.                             $cat_name $category->name;
  142.                             break;
  143.                         }
  144.                     } else {
  145.                         // 設定なし
  146.                         $cat_name $category->name;
  147.                         break;
  148.                     }
  149.                 }
  150.             }
  151.         }
  152.         $blogs[] = [
  153.             'id' => get_the_ID(),
  154.             'title' => get_the_title(),
  155.             'cat_name' => $cat_name,
  156.             'date' => get_the_date('Y.m.d'),
  157.             'thumbnail' => get_the_post_thumbnail_url(),
  158.         ];
  159.         endwhile;
  160.         wp_reset_postdata();
  161.         $max_posts_num $the_query->found_posts;
  162.         if ($max_posts_num <= 17) {
  163.             $max_page_num 1;
  164.         } else {
  165.             $max_page_num ceil(($max_posts_num 17) / 18);
  166.         }
  167.         return [
  168.             'shop' => $shop,
  169.             'Blogs' => $blogs,
  170.             'currentPage' => $pageno,
  171.             'max_page_num' => $max_page_num,
  172.         ];
  173.     }
  174.     /**
  175.      * @Method("GET")
  176.      * @Route("/blogs/detail/{id}", name="blog_detail")
  177.      * @Template("Blog/detail.twig")
  178.      */
  179.     public function blog_detail(Request $request$id)
  180.     {
  181.         $args = [
  182.             'p' => $id,
  183.             'category__in' => [52553971521],
  184.         ];
  185.         $the_query = new \WP_Query($args);
  186.         $acf = new \ACF();
  187.         $blog = [];
  188.         while ($the_query->have_posts()): $the_query->the_post();
  189.             $prev_post get_next_post(true);
  190.             $next_post get_previous_post(true);
  191.             $blog = [
  192.                 'id' => get_the_ID(),
  193.                 'title' => get_the_title(),
  194.                 'date' => get_the_date('Y.m.d'),
  195.                 'content' => do_shortcode(get_the_content()),
  196.                 'thumbnail' => get_the_post_thumbnail_url(),
  197.                 'next_link' => $prev_post "/blogs/detail/" $prev_post->ID null,
  198.                 'prev_link' => $next_post "/blogs/detail/" $next_post->ID null,
  199.                 'recommend' => get_field('recommend'),
  200.             ];
  201.             $cate_slugs = [];
  202.             foreach (get_the_category() as $c) {
  203.                 $cate_slugs[$c->cat_ID] = $c->slug;
  204.             }
  205.             if (in_array('dialogue'$cate_slugs)) {
  206.                 $shop 'dialogue';
  207.                 // $pickup_category_id = 1102;
  208.                 $pickup_category_id $this->shopDialogueId;
  209.             } elseif (in_array('ensemble'$cate_slugs)) {
  210.             $shop 'ensemble';
  211.             // $pickup_category_id = 1103;
  212.             $pickup_category_id $this->shopEnsembleId;
  213.         } elseif (in_array('ensembledeux'$cate_slugs)) {
  214.             $shop 'ensembledeux';
  215.             // $pickup_category_id = 1104;
  216.             $pickup_category_id $this->shopEnsembledeuxId;
  217.         } elseif (in_array('flair'$cate_slugs)) {
  218.             $shop 'flair';
  219.             // $pickup_category_id = 1105;
  220.             $pickup_category_id $this->shopFlairId;
  221.         } elseif (in_array('gathering'$cate_slugs)) {
  222.             $shop 'gathering';
  223.             // $pickup_category_id = 1106;
  224.             $pickup_category_id $this->shopGatheringId;
  225.         }
  226.         endwhile;
  227.         if ($blog['recommend']) {
  228.             log_info("getlog" $blog['recommend']);
  229.             $recomend explode(','$blog['recommend']);
  230.             $category_recommend_products $this->getProductsInRecommend($recomend3);
  231.         } else {
  232.             $category_recommend_products $this->getProductsInCategory($pickup_category_id3);
  233.         }
  234.         // $pickupCategory = $this->categoryRepository->find($pickup_category_id);
  235.         // $category_recommend_products = $this->categoryRecommendProductRepository->getCategoryRecommendProduct($pickupCategory);
  236.         // addCart form
  237.         $forms = [];
  238.         $ids = [];
  239.         foreach ($category_recommend_products as $item) {
  240.             $ids[] = $item->getId();
  241.         }
  242.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  243.         foreach ($category_recommend_products as $item) {
  244.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  245.             $builder $this->formFactory->createNamedBuilder(
  246.                 '',
  247.                 AddCartType::class,
  248.                 null,
  249.                 [
  250.                     'product' => $ProductsAndClassCategories[$item->getId()],
  251.                     'allow_extra_fields' => true,
  252.                 ]
  253.             );
  254.             $addCartForm $builder->getForm();
  255.             $forms[$item->getId()] = $addCartForm->createView();
  256.         }
  257.         return [
  258.             'shop' => $shop,
  259.             'Blog' => $blog,
  260.             'Pickup' => $category_recommend_products,
  261.             'forms' => $forms,
  262.         ];
  263.     }
  264.     /**
  265.      * @Method("GET")
  266.      * @Route("/dialogue/concept", name="shop_dialogue_concept")
  267.      * @Template("Shop/dialogue_concept.twig")
  268.      */
  269.     public function shop_dialogue_concept()
  270.     {
  271.         return [];
  272.     }
  273.     /**
  274.      * @Method("GET")
  275.      * @Route("/ensemble", name="shop_ensemble_top")
  276.      * @Template("Shop/ensemble_top.twig")
  277.      */
  278.     public function shop_ensemble()
  279.     {
  280.         $info $this->getShopInfo($this->shopEnsembleId'ensemble'2);
  281.         return $info;
  282.     }
  283.     /**
  284.      * @Method("GET")
  285.      * @Route("/ensemble/concept", name="shop_ensemble_concept")
  286.      * @Template("Shop/ensemble_concept.twig")
  287.      */
  288.     public function shop_ensemble_concept()
  289.     {
  290.         return [];
  291.     }
  292.     /**
  293.      * @Method("GET")
  294.      * @Route("/ensembledeux", name="shop_ensembledeux_top")
  295.      * @Template("Shop/ensembledeux_top.twig")
  296.      */
  297.     public function shop_ensembledeux()
  298.     {
  299.         $info $this->getShopInfo($this->shopEnsembledeuxId'ensembledeux'1521);
  300.         return $info;
  301.     }
  302.     /**
  303.      * @Method("GET")
  304.      * @Route("/ensembledeux/concept", name="shop_ensembledeux_concept")
  305.      * @Template("Shop/ensembledeux_concept.twig")
  306.      */
  307.     public function shop_ensembledeux_concept()
  308.     {
  309.         return [];
  310.     }
  311.     /**
  312.      * @Method("GET")
  313.      * @Route("/flair", name="shop_flair_top")
  314.      * @Template("Shop/flair_top.twig")
  315.      */
  316.     public function shop_flair()
  317.     {
  318.         $info $this->getShopInfo($this->shopFlairId'flair'55);
  319.         return $info;
  320.     }
  321.     /**
  322.      * @Method("GET")
  323.      * @Route("/flair/concept", name="shop_flair_concept")
  324.      * @Template("Shop/flair_concept.twig")
  325.      */
  326.     public function shop_flair_concept()
  327.     {
  328.         return [];
  329.     }
  330.     /**
  331.      * @Method("GET")
  332.      * @Route("/gathering", name="shop_gathering_top")
  333.      * @Template("Shop/gathering_top.twig")
  334.      */
  335.     public function shop_gathering()
  336.     {
  337.         $info $this->getShopInfo($this->shopGatheringId'gathering'397);
  338.         return $info;
  339.     }
  340.     /**
  341.      * @Method("GET")
  342.      * @Route("/gathering/concept", name="shop_gathering_concept")
  343.      * @Template("Shop/gathering_concept.twig")
  344.      */
  345.     public function shop_gathering_concept()
  346.     {
  347.         return [];
  348.     }
  349.     /**
  350.      * @Method("GET")
  351.      * @Route("/brand/list", name="brand_list")
  352.      * @Template("Brand/list.twig")
  353.      */
  354.     public function brand_list(Request $request)
  355.     {
  356.         $brandParantCategory $this->categoryRepository->find('3');
  357.         $qb $this->categoryRepository->createQueryBuilder('ca');
  358.         $qb->andWhere('ca.Parent = :parent')
  359.             ->setParameter('parent'$brandParantCategory)
  360.             ->orderBy("ca.sort_no""DESC");
  361.         $shop $request->query->get('shop');
  362.         if ($shop) {
  363.             if ($shop == 'dialogue') {
  364.                 /*$or = $qb->expr()->orx();
  365.                 $or->add($qb->expr()->eq('ca.shop_dialogue', 1));
  366.                 $or->add($qb->expr()->eq('ca.shop_ensemble', 1));
  367.                 $qb->andWhere($or);*/
  368.                 $qb->andWhere('ca.shop_dialogue = :flg')
  369.                     ->setParameter('flg''1');
  370.             } else if ($shop == 'ensemble') {
  371.                 $qb->andWhere('ca.shop_ensemble = :flg')
  372.                     ->setParameter('flg''1');
  373.             } else if ($shop == 'ensembledeux') {
  374.                 $qb->andWhere('ca.shop_ensembledeux = :flg')
  375.                     ->setParameter('flg''1');
  376.             } else if ($shop == 'flair') {
  377.                 $qb->andWhere('ca.shop_flair = :flg')
  378.                     ->setParameter('flg''1');
  379.             } else if ($shop == 'gathering') {
  380.                 $qb->andWhere('ca.shop_gathering = :flg')
  381.                     ->setParameter('flg''1');
  382.             }
  383.         }
  384.         $cat $request->query->get('cat');
  385.         if ($cat) {
  386.             if ($cat == 'mens') {
  387.                 $qb->andWhere('ca.men = :flg')
  388.                     ->setParameter('flg''1');
  389.             } else if ($cat == 'womens') {
  390.                 $qb->andWhere('ca.women = :flg')
  391.                     ->setParameter('flg''1');
  392.             }
  393.         }
  394.         $brandCategories $qb->getQuery()
  395.             ->getResult();
  396.         return [
  397.             'shop' => $shop,
  398.             'BrandCategories' => $brandCategories,
  399.         ];
  400.     }
  401.     /**
  402.      * @Method("GET")
  403.      * @Route("/brand", name="all_brand_list")
  404.      * @Template("Other/brand.twig")
  405.      */
  406.     public function all_brand_list(Request $request)
  407.     {
  408.         $brandParantCategory $this->categoryRepository->find('3');
  409.         $qb $this->categoryRepository->createQueryBuilder('ca');
  410.         $qb->andWhere('ca.Parent = :parent')
  411.             ->andWhere('ca.shop_dialogue = :shopEnable OR ca.shop_ensemble = :shopEnable OR ca.shop_ensembledeux = :shopEnable OR ca.shop_flair = :shopEnable OR ca.shop_gathering = :shopEnable')
  412.             ->setParameter('parent'$brandParantCategory)
  413.             ->setParameter('shopEnable'1)
  414.             ->orderBy("ca.sort_no""DESC");
  415.         $cat $request->query->get('cat');
  416.         if ($cat) {
  417.             if ($cat == 'mens') {
  418.                 $qb->andWhere('ca.men = :flg')
  419.                     ->setParameter('flg''1');
  420.             } else if ($cat == 'womens') {
  421.                 $qb->andWhere('ca.women = :flg')
  422.                     ->setParameter('flg''1');
  423.             }
  424.         }
  425.         // $qb->andWhere('ca.name != ?1')
  426.         //     ->setParameter(1, 'Aeta');
  427.         $brandCategories $qb->getQuery()
  428.             ->getResult();
  429.         return [
  430.             'BrandCategories' => $brandCategories,
  431.         ];
  432.     }
  433.     /**
  434.      * @Method("GET")
  435.      * @Route("/item/list", name="item_list")
  436.      * @Template("Item/list.twig")
  437.      */
  438.     public function item_list(Request $request)
  439.     {
  440.         $brandParantCategory $this->categoryRepository->find('4');
  441.         $qb $this->categoryRepository->createQueryBuilder('ca');
  442.         $qb->andWhere('ca.Parent = :parent')
  443.             ->setParameter('parent'$brandParantCategory)
  444.             ->orderBy("ca.sort_no""DESC");
  445.         $shop $request->query->get('shop');
  446.         $brandCategories $qb->getQuery()
  447.             ->getResult();
  448.         return [
  449.             'shop' => $shop,
  450.             'BrandCategories' => $brandCategories,
  451.         ];
  452.     }
  453.     /**
  454.      * @Method("GET")
  455.      * @Route("/item", name="all_item_list")
  456.      * @Template("Other/item.twig")
  457.      */
  458.     public function all_item_list(Request $request)
  459.     {
  460.         $brandParantCategory $this->categoryRepository->find('4');
  461.         $qb $this->categoryRepository->createQueryBuilder('ca');
  462.         $qb->andWhere('ca.Parent = :parent')
  463.             ->setParameter('parent'$brandParantCategory)
  464.             ->orderBy("ca.sort_no""DESC");
  465.         $brandCategories $qb->getQuery()
  466.             ->getResult();
  467.         return [
  468.             'BrandCategories' => $brandCategories,
  469.         ];
  470.     }
  471.     /**
  472.      * @Method("GET")
  473.      * @Route("/brand/{id}", name="brand_detail", requirements={"id" = "\d+"})
  474.      * @Template("Brand/detail.twig")
  475.      */
  476.     public function brand_detail(Request $request$idPaginator $paginator)
  477.     {
  478.         $brand $this->categoryRepository->find($id);
  479.         $pagination $paginator->paginate(
  480.             $this->getProductsInCategoryQuery($id),
  481.             $request->query->getInt('pageno'1),
  482.             12
  483.         );
  484.         // 店舗設定
  485.         if ($brand->getShopDialogue() ===true) {
  486.             $shop 'dialogue';
  487.         } else if ($brand->getShopEnsemble() ===true) {
  488.             $shop 'ensemble';
  489.         } else if ($brand->getShopEnsembledeux() ===true) {
  490.             $shop 'ensembledeux';
  491.         } else if ($brand->getShopFlair() ===true) {
  492.             $shop 'flair';
  493.         } else if ($brand->getShopGathering() ===true) {
  494.             $shop 'gathering';
  495.         }else{
  496.             $shop 'dialogue';
  497.         }
  498.         log_info("brand_detail_log shop:" $shop);
  499.         return [
  500.             'shop' => $shop,
  501.             'Brand' => $brand,
  502.             'pagination' => $pagination,
  503.         ];
  504.     }
  505.     /**
  506.      * @Method("GET")
  507.      * @Route("/item/{id}", name="item_detail", requirements={"id" = "\d+"})
  508.      * @Template("Item/detail.twig")
  509.      */
  510.     public function item_detail(Request $request$idPaginator $paginator)
  511.     {
  512.         $brand $this->categoryRepository->find($id);
  513.         $pagination $paginator->paginate(
  514.             $this->getProductsInCategoryQuery($id),
  515.             $request->query->getInt('pageno'1),
  516.             12
  517.         );
  518.         return [
  519.             'Brand' => $brand,
  520.             'pagination' => $pagination,
  521.         ];
  522.     }
  523.     private function getProductsInCategoryQuery($categry_id)
  524.     {
  525.         $category $this->categoryRepository->find($categry_id);
  526.         $qb $this->productRepository->createQueryBuilder('p')
  527.             ->addSelect("(CASE WHEN (CASE WHEN MAX(pc.stock) IS NULL THEN 0 ELSE MAX(pc.stock) END) + (CASE WHEN MAX(pc.stock_unlimited) IS NULL THEN 0 ELSE  MAX(pc.stock_unlimited) END) = 0 THEN '0000-00-00 00:00:00_0000-00-00 00:00:00' ELSE CONCAT(CASE WHEN p.published_at IS NULL THEN '0000-00-00 00:00:00' ELSE p.published_at END, '_', p.create_date) END) AS HIDDEN sort_field")
  528.             ->andWhere('p.Status = 1')
  529.             ->andWhere('p.published_at is NULL OR p.published_at <= :now')
  530.             ->setParameter('now', new \DateTime())
  531.             ->andWhere('pc.visible = :visible')
  532.             ->setParameter('visible'true);
  533.         $qb->innerJoin('p.ProductClasses''pc')
  534.             ->innerJoin('p.ProductCategories''pct')
  535.             ->innerJoin('pct.Category''c')
  536.             ->andWhere($qb->expr()->in('pct.Category'':Categories'))
  537.             ->setParameter('Categories', [$category])
  538.             ->groupBy('p.id')
  539.             ->addOrderBy('sort_field''DESC')
  540.             ->addOrderBy('p.id''DESC');
  541.         return $qb;
  542.     }
  543.     private function getProductsInCategory($categry_id$count)
  544.     {
  545.         $category $this->categoryRepository->find($categry_id);
  546.         $categories = [$category];
  547.         $qb $this->productRepository->createQueryBuilder('p')
  548.             ->addSelect("(CASE WHEN (CASE WHEN MAX(pc.stock) IS NULL THEN 0 ELSE MAX(pc.stock) END) + (CASE WHEN MAX(pc.stock_unlimited) IS NULL THEN 0 ELSE  MAX(pc.stock_unlimited) END) = 0 THEN '0000-00-00 00:00:00_0000-00-00 00:00:00' ELSE CONCAT(CASE WHEN p.published_at IS NULL THEN '0000-00-00 00:00:00' ELSE p.published_at END, '_', p.create_date) END) AS HIDDEN sort_field")
  549.             ->andWhere('p.Status = 1')
  550.             ->andWhere('p.published_at is NULL OR p.published_at <= :now')
  551.             ->setParameter('now', new \DateTime())
  552.             ->andWhere('pc.visible = :visible')
  553.             ->setParameter('visible'true);
  554.         $qb->innerJoin('p.ProductClasses''pc')
  555.             ->innerJoin('p.ProductCategories''pct')
  556.             ->innerJoin('pct.Category''c')
  557.             ->andWhere($qb->expr()->in('pct.Category'':Categories'))
  558.             ->setParameter('Categories'$categories)
  559.             ->groupBy('p.id')
  560.             ->addOrderBy('sort_field''DESC')
  561.             ->addOrderBy('p.id''DESC');
  562.         $products $qb
  563.             ->setMaxResults($count)
  564.             ->getQuery()
  565.             ->getResult();
  566.         // print("<pre>".print_r($products,true)."</pre>");die;
  567.         return $products;
  568.     }
  569.     private function getProductsInRecommend($recommend$count)
  570.     {
  571.         log_info("getlog" print_r($recommendtrue));
  572.         $qb $this->productRepository->createQueryBuilder('p')
  573.             ->andWhere('p.Status = 1')
  574.             ->andWhere('p.published_at is NULL OR p.published_at <= :now')
  575.             ->setParameter('now', new \DateTime())
  576.         ;
  577.         $qb->andWhere($qb->expr()->in('p.id'$recommend));
  578.         $qb->innerJoin('p.ProductCategories''pct')
  579.             ->innerJoin('pct.Category''c')
  580.             ->addOrderBy('p.id''DESC')
  581.             ->groupBy('p.id');
  582.         $products $qb
  583.             ->setMaxResults($count)
  584.             ->getQuery()
  585.             ->getResult();
  586.         return $products;
  587.     }
  588.     private function getProductsInCategories($shopCategory$brandCategory)
  589.     {
  590.         $qb $this->productRepository->createQueryBuilder('p')
  591.             ->andWhere('p.Status = 1')
  592.             ->andWhere('p.published_at is NULL OR p.published_at <= :now')
  593.             ->setParameter('now', new \DateTime());
  594.         $qb->innerJoin('p.ProductCategories''pct')
  595.             ->innerJoin('pct.Category''c')
  596.             ->andWhere($qb->expr()->in('pct.Category'':Categories1'))
  597.             ->setParameter('Categories1', [$shopCategory])
  598.             ->innerJoin('p.ProductCategories''pct2')
  599.             ->innerJoin('pct.Category''c2')
  600.             ->andWhere($qb->expr()->in('pct2.Category'':Categories2'))
  601.             ->setParameter('Categories2', [$brandCategory]);
  602.         $products $qb->getQuery()
  603.             ->getResult();
  604.         if (count($products)) {
  605.             return $brandCategory;
  606.         }
  607.         return false;
  608.     }
  609.     private function getShopInfo($p_cat_id$s_name$b_cat_id)
  610.     {
  611.         $brands = [];
  612.         $products $this->getProductsInCategory($p_cat_id20);
  613.         $shopCategory $this->categoryRepository->find($p_cat_id);
  614.         foreach ($this->brandCategories as $brandCategory) {
  615.             $result $this->getProductsInCategories($shopCategory$brandCategory);
  616.             if ($result) {
  617.                 $brands[] = $result;
  618.             }
  619.         }
  620.         $newsList $this->newsRepository->getListForShop(strtoupper($s_name));
  621.         $blogs = [];
  622.         $args = array(
  623.             'cat' => $b_cat_id,
  624.             'posts_per_page' => 5,
  625.             'orderby' => 'date',
  626.             'order' => 'DESC',
  627.         );
  628.         $the_query = new \WP_Query($args);
  629.         while ($the_query->have_posts()): $the_query->the_post();
  630.             $blogs[] = [
  631.                 'id' => get_the_ID(),
  632.                 'title' => get_the_title(),
  633.                 'content' => get_the_content(),
  634.                 'date' => get_the_date('Y.m.d'),
  635.                 'thumbnail' => get_the_post_thumbnail_url(),
  636.             ];
  637.         endwhile;
  638.         return [
  639.             'shop' => strtolower($s_name),
  640.             'Products' => $products,
  641.             'Brands' => $brands,
  642.             'NewsList' => $newsList,
  643.             'Blogs' => $blogs,
  644.         ];
  645.     }
  646. }