app/Customize/Controller/HistoryProductController.php line 26

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 Customize\Controller;
  13. use Customize\Form\Type\SearchHistoryProductType;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\AddCartType;
  17. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  18. use Knp\Component\Pager\PaginatorInterface;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class HistoryProductController extends \Eccube\Controller\ProductController
  23. {
  24.     /**
  25.      * 商品一覧画面.
  26.      *
  27.      * @Route("/history/products/list", name="history_product_list", methods={"GET"})
  28.      * @Template("@user_data/history_product_list.twig")
  29.      */
  30.     public function index(Request $requestPaginatorInterface $paginator)
  31.     {
  32.         if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) {
  33.             return $this->redirectToRoute('mypage_login');
  34.         }
  35.         // Doctrine SQLFilter
  36.         if ($this->BaseInfo->isOptionNostockHidden()) {
  37.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  38.         }
  39.         // handleRequestは空のqueryの場合は無視するため
  40.         if ($request->getMethod() === 'GET') {
  41.             $request->query->set('pageno'$request->query->get('pageno'''));
  42.         }
  43.         // searchForm
  44.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  45.         $builder $this->formFactory->createNamedBuilder(''SearchHistoryProductType::class);
  46.         if ($request->getMethod() === 'GET') {
  47.             $builder->setMethod('GET');
  48.         }
  49.         $event = new EventArgs(
  50.             [
  51.                 'builder' => $builder,
  52.             ],
  53.             $request
  54.         );
  55.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  56.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  57.         $searchForm $builder->getForm();
  58.         $searchForm->handleRequest($request);
  59.         // paginator
  60.         $searchData $searchForm->getData();
  61.         $Customer $this->getUser();
  62.         $qb $this->productRepository->getHistoryProductQueryBuilderBySearchData($searchData$Customer);
  63.         $event = new EventArgs(
  64.             [
  65.                 'searchData' => $searchData,
  66.                 'qb' => $qb,
  67.             ],
  68.             $request
  69.         );
  70.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  71.         $searchData $event->getArgument('searchData');
  72.         $query $qb->getQuery()
  73.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  74.         /** @var SlidingPagination $pagination */
  75.         $pagination $paginator->paginate(
  76.             $query,
  77.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  78.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  79.         );
  80.         $ids = [];
  81.         foreach ($pagination as $Product) {
  82.             $ids[] = $Product->getId();
  83.         }
  84.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  85.         // addCart form
  86.         $forms = [];
  87.         foreach ($pagination as $Product) {
  88.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  89.             $builder $this->formFactory->createNamedBuilder(
  90.                 '',
  91.                 AddCartType::class,
  92.                 null,
  93.                 [
  94.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  95.                     'allow_extra_fields' => true,
  96.                 ]
  97.             );
  98.             $addCartForm $builder->getForm();
  99.             $forms[$Product->getId()] = $addCartForm->createView();
  100.         }
  101.         $Category $searchForm->get('category_id')->getData();
  102.         $OrderBy = [
  103.             // by quantity
  104.             '購入回数が多い順' => 1,
  105.             // by nearly order date
  106.             '最新の購入順' => 2
  107.         ];
  108.         return [
  109.             'subtitle' => $this->getPageTitle($searchData),
  110.             'pagination' => $pagination,
  111.             'search_form' => $searchForm->createView(),
  112.             'forms' => $forms,
  113.             'Category' => $Category,
  114.             'OrderBy' => $OrderBy
  115.         ];
  116.     }
  117. }