app/Plugin/ProductReview42/Controller/ProductController.php line 102

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\ProductReview42\Controller;
  13. use Eccube\Entity\Product;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\AddCartType;
  17. use Eccube\Repository\BaseInfoRepository;
  18. use Eccube\Repository\CustomerFavoriteProductRepository;
  19. use Eccube\Repository\Master\ProductListMaxRepository;
  20. use Eccube\Repository\ProductRepository;
  21. use Eccube\Service\CartService;
  22. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  23. use Knp\Component\Pager\PaginatorInterface;
  24. use Plugin\ProductReview42\Form\Type\SearchProductType;
  25. use Plugin\ProductReview42\Repository\ProductReviewRepository;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  29. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  30. class ProductController extends \Eccube\Controller\ProductController
  31. {    
  32.         /**
  33.         * @var PurchaseFlow
  34.         */
  35.     protected $purchaseFlow;
  36.     /**
  37.         * @var CustomerFavoriteProductRepository
  38.         */
  39.     protected $customerFavoriteProductRepository;
  40.     /**
  41.         * @var CartService
  42.         */
  43.     protected $cartService;
  44.     /**
  45.         * @var ProductRepository
  46.         */
  47.     protected $productRepository;
  48.     /**
  49.         * @var BaseInfo
  50.         */
  51.     protected $BaseInfo;
  52.     /**
  53.         * @var AuthenticationUtils
  54.         */
  55.     protected $helper;
  56.     /**
  57.         * @var ProductListMaxRepository
  58.         */
  59.     protected $productListMaxRepository;
  60.     protected ProductReviewRepository $productReviewRepository;
  61.     private $title '';
  62.     
  63.     public function __construct(
  64.         PurchaseFlow $cartPurchaseFlow,
  65.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  66.         CartService $cartService,
  67.         ProductRepository $productRepository,
  68.         BaseInfoRepository $baseInfoRepository,
  69.         AuthenticationUtils $helper,
  70.         ProductListMaxRepository $productListMaxRepository,
  71.         ProductReviewRepository $productReviewRepository
  72.     ) {
  73.         $this->purchaseFlow $cartPurchaseFlow;
  74.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  75.         $this->cartService $cartService;
  76.         $this->productRepository $productRepository;
  77.         $this->BaseInfo $baseInfoRepository->get();
  78.         $this->helper $helper;
  79.         $this->productListMaxRepository $productListMaxRepository;
  80.         $this->productReviewRepository $productReviewRepository;
  81.     }
  82.     /**
  83.      * 商品一覧画面.
  84.      *
  85.      * @Route("/products/review", name="product_review", methods={"GET"})
  86.      * @Template("@ProductReview42/Product/review.twig")
  87.      */
  88.     public function review(Request $requestPaginatorInterface $paginator)
  89.     {
  90.         // Doctrine SQLFilter
  91.         if ($this->BaseInfo->isOptionNostockHidden()) {
  92.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  93.         }
  94.         // handleRequestは空のqueryの場合は無視するため
  95.         if ($request->getMethod() === 'GET') {
  96.             $request->query->set('pageno'$request->query->get('pageno'''));
  97.         }
  98.         // searchForm
  99.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  100.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  101.         if ($request->getMethod() === 'GET') {
  102.             $builder->setMethod('GET');
  103.         }
  104.         $event = new EventArgs(
  105.             [
  106.                 'builder' => $builder,
  107.             ],
  108.             $request
  109.         );
  110.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  111.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  112.         $searchForm $builder->getForm();
  113.         $searchForm->handleRequest($request);
  114.         // paginator
  115.         $searchData $searchForm->getData();
  116.         $qb $this->productReviewRepository->getQueryBuilderBySearchData($searchData);
  117.         $event = new EventArgs(
  118.             [
  119.                 'searchData' => $searchData,
  120.                 'qb' => $qb,
  121.             ],
  122.             $request
  123.         );
  124.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  125.         $searchData $event->getArgument('searchData');
  126.         $query $qb->getQuery()
  127.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  128.         /** @var SlidingPagination $pagination */
  129.         $pagination $paginator->paginate(
  130.             $query,
  131.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  132.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  133.         );
  134.         $ids = [];
  135.         foreach ($pagination as $Product) {
  136.             $ids[] = $Product->getId();
  137.         }
  138.         $Category $searchForm->get('category_id')->getData();
  139.         return [
  140.             'subtitle' => $this->getPageTitle($searchData),
  141.             'pagination' => $pagination,
  142.             'search_form' => $searchForm->createView(),
  143.             'Category' => $Category,
  144.         ];
  145.     }
  146. }