app/Customize/Controller/ManualPageController.php line 110

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Eccube\Entity\BaseInfo;
  4. use Eccube\Entity\Master\ProductStatus;
  5. use Eccube\Entity\Product;
  6. use Eccube\Event\EccubeEvents;
  7. use Eccube\Event\EventArgs;
  8. use Eccube\Form\Type\AddCartType;
  9. use Eccube\Form\Type\SearchProductType;
  10. use Eccube\Repository\BaseInfoRepository;
  11. use Eccube\Repository\CustomerFavoriteProductRepository;
  12. use Eccube\Repository\Master\ProductListMaxRepository;
  13. use Eccube\Repository\ProductRepository;
  14. use Eccube\Service\CartService;
  15. use Eccube\Service\PurchaseFlow\PurchaseContext;
  16. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  17. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  18. use Knp\Component\Pager\PaginatorInterface;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Eccube\Controller\AbstractController;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  24. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  25. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  26. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  27. class ManualPageController extends AbstractController
  28. {
  29.     /**
  30.      * @var PurchaseFlow
  31.      */
  32.     protected $purchaseFlow;
  33.     /**
  34.      * @var CustomerFavoriteProductRepository
  35.      */
  36.     protected $customerFavoriteProductRepository;
  37.     /**
  38.      * @var CartService
  39.      */
  40.     protected $cartService;
  41.     /**
  42.      * @var ProductRepository
  43.      */
  44.     protected $productRepository;
  45.     /**
  46.      * @var BaseInfo
  47.      */
  48.     protected $BaseInfo;
  49.     /**
  50.      * @var AuthenticationUtils
  51.      */
  52.     protected $helper;
  53.     /**
  54.      * @var ProductListMaxRepository
  55.      */
  56.     protected $productListMaxRepository;
  57.     private $title '';
  58.     /**
  59.      * ProductController constructor.
  60.      *
  61.      * @param PurchaseFlow $cartPurchaseFlow
  62.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  63.      * @param CartService $cartService
  64.      * @param ProductRepository $productRepository
  65.      * @param BaseInfoRepository $baseInfoRepository
  66.      * @param AuthenticationUtils $helper
  67.      * @param ProductListMaxRepository $productListMaxRepository
  68.      */
  69.     public function __construct(
  70.         PurchaseFlow $cartPurchaseFlow,
  71.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  72.         CartService $cartService,
  73.         ProductRepository $productRepository,
  74.         BaseInfoRepository $baseInfoRepository,
  75.         AuthenticationUtils $helper,
  76.         ProductListMaxRepository $productListMaxRepository
  77.     ) {
  78.         $this->purchaseFlow $cartPurchaseFlow;
  79.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  80.         $this->cartService $cartService;
  81.         $this->productRepository $productRepository;
  82.         $this->BaseInfo $baseInfoRepository->get();
  83.         $this->helper $helper;
  84.         $this->productListMaxRepository $productListMaxRepository;
  85.     }
  86.     /**
  87.      * @Route("/manual", name="manual")
  88.      * @Template("@user_data/manual.twig")
  89.      */
  90.     public function index(Request $requestPaginatorInterface $paginator)
  91.     {
  92.         // Doctrine SQLFilter
  93.         if ($this->BaseInfo->isOptionNostockHidden()) {
  94.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  95.         }
  96.         // handleRequestは空のqueryの場合は無視するため
  97.         if ($request->getMethod() === 'GET') {
  98.             $request->query->set('pageno'$request->query->get('pageno'''));
  99.         }
  100.         // searchForm
  101.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  102.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  103.         if ($request->getMethod() === 'GET') {
  104.             $builder->setMethod('GET');
  105.         }
  106.         $event = new EventArgs(
  107.             [
  108.                 'builder' => $builder,
  109.             ],
  110.             $request
  111.         );
  112.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  113.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  114.         $searchForm $builder->getForm();
  115.         $searchForm->handleRequest($request);
  116.         // paginator
  117.         $searchData $searchForm->getData();
  118.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  119.         $event = new EventArgs(
  120.             [
  121.                 'searchData' => $searchData,
  122.                 'qb' => $qb,
  123.             ],
  124.             $request
  125.         );
  126.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  127.         $searchData $event->getArgument('searchData');
  128.         $query $qb->getQuery()
  129.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  130.         /** @var SlidingPagination $pagination */
  131.         $pagination $paginator->paginate(
  132.             $query,
  133.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  134.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  135.         );
  136.         $ids = [];
  137.         foreach ($pagination as $Product) {
  138.             $ids[] = $Product->getId();
  139.         }
  140.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  141.         // addCart form
  142.         $forms = [];
  143.         foreach ($pagination as $Product) {
  144.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  145.             $builder $this->formFactory->createNamedBuilder(
  146.                 '',
  147.                 AddCartType::class,
  148.                 null,
  149.                 [
  150.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  151.                     'allow_extra_fields' => true,
  152.                 ]
  153.             );
  154.             $addCartForm $builder->getForm();
  155.             $forms[$Product->getId()] = $addCartForm->createView();
  156.         }
  157.         $Category $searchForm->get('category_id')->getData();
  158.         dump($Category);
  159.         return [
  160.             'pagination' => $pagination,
  161.             'search_form' => $searchForm->createView(),
  162.             'forms' => $forms,
  163.             'Category' => $Category,
  164.         ];
  165.     }
  166. }