app/Customize/Controller/CustomProductController.php line 127

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 Eccube\Controller\ProductController as BaseProductController;
  14. use Eccube\Controller\AbstractController;
  15. use Eccube\Entity\BaseInfo;
  16. use Eccube\Entity\Master\ProductStatus;
  17. use Eccube\Entity\Product;
  18. use Eccube\Event\EccubeEvents;
  19. use Eccube\Event\EventArgs;
  20. use Eccube\Form\Type\AddCartType;
  21. use Eccube\Form\Type\Master\ProductListMaxType;
  22. use Eccube\Form\Type\Master\ProductListOrderByType;
  23. use Eccube\Form\Type\SearchProductType;
  24. use Eccube\Repository\BaseInfoRepository;
  25. use Eccube\Repository\CustomerFavoriteProductRepository;
  26. use Eccube\Repository\Master\ProductListMaxRepository;
  27. use Eccube\Repository\ProductRepository;
  28. use Eccube\Service\CartService;
  29. use Customize\Service\ProductService;
  30. use Eccube\Service\PurchaseFlow\PurchaseContext;
  31. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  32. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  33. use Knp\Component\Pager\PaginatorInterface;
  34. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  35. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  38. use Symfony\Component\Routing\Annotation\Route;
  39. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  40. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  41. class CustomProductController extends BaseProductController
  42. {
  43.     /**
  44.      * @var PurchaseFlow
  45.      */
  46.     protected $purchaseFlow;
  47.     /**
  48.      * @var CustomerFavoriteProductRepository
  49.      */
  50.     protected $customerFavoriteProductRepository;
  51.     /**
  52.      * @var CartService
  53.      */
  54.     protected $cartService;
  55.     /**
  56.      * @var ProductService
  57.      */
  58.     protected $productService;
  59.     /**
  60.      * @var ProductRepository
  61.      */
  62.     protected $productRepository;
  63.     /**
  64.      * @var BaseInfo
  65.      */
  66.     protected $BaseInfo;
  67.     /**
  68.      * @var AuthenticationUtils
  69.      */
  70.     protected $helper;
  71.     /**
  72.      * @var ProductListMaxRepository
  73.      */
  74.     protected $productListMaxRepository;
  75.     private $title '';
  76.     /**
  77.      * ProductController constructor.
  78.      *
  79.      * @param PurchaseFlow $cartPurchaseFlow
  80.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  81.      * @param CartService $cartService
  82.      * @param ProductService $productService
  83.      * @param ProductRepository $productRepository
  84.      * @param BaseInfoRepository $baseInfoRepository
  85.      * @param AuthenticationUtils $helper
  86.      * @param ProductListMaxRepository $productListMaxRepository
  87.      */
  88.     public function __construct(
  89.         PurchaseFlow $cartPurchaseFlow,
  90.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  91.         CartService $cartService,
  92.         ProductService $productService,
  93.         ProductRepository $productRepository,
  94.         BaseInfoRepository $baseInfoRepository,
  95.         AuthenticationUtils $helper,
  96.         ProductListMaxRepository $productListMaxRepository
  97.     ) {
  98.         $this->purchaseFlow $cartPurchaseFlow;
  99.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  100.         $this->cartService $cartService;
  101.         $this->productService $productService;
  102.         $this->productRepository $productRepository;
  103.         $this->BaseInfo $baseInfoRepository->get();
  104.         $this->helper $helper;
  105.         $this->productListMaxRepository $productListMaxRepository;
  106.     }
  107.     /**
  108.      * 商品一覧画面.
  109.      *
  110.      * @Route("/products/list", name="product_list", methods={"GET"})
  111.      * @Template("Product/list.twig")
  112.      */
  113.     public function index(Request $requestPaginatorInterface $paginator)
  114.     {
  115.         // Doctrine SQLFilter
  116.         if ($this->BaseInfo->isOptionNostockHidden()) {
  117.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  118.         }
  119.         // handleRequestは空のqueryの場合は無視するため
  120.         if ($request->getMethod() === 'GET') {
  121.             $request->query->set('pageno'$request->query->get('pageno'''));
  122.         }
  123.         // searchForm
  124.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  125.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  126.         if ($request->getMethod() === 'GET') {
  127.             $builder->setMethod('GET');
  128.         }
  129.         $event = new EventArgs(
  130.             [
  131.                 'builder' => $builder,
  132.             ],
  133.             $request
  134.         );
  135.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  136.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  137.         $searchForm $builder->getForm();
  138.         $searchForm->handleRequest($request);
  139.         // paginator
  140.         $searchData $searchForm->getData();
  141.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  142.         $event = new EventArgs(
  143.             [
  144.                 'searchData' => $searchData,
  145.                 'qb' => $qb,
  146.             ],
  147.             $request
  148.         );
  149.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  150.         $searchData $event->getArgument('searchData');
  151.         $query $qb->getQuery()
  152.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  153.         /** @var SlidingPagination $pagination */
  154.         $pagination $paginator->paginate(
  155.             $query,
  156.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  157.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  158.         );
  159.         $ids = [];
  160.         foreach ($pagination as $Product) {
  161.             $ids[] = $Product->getId();
  162.         }
  163.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  164.         // addCart form
  165.         $forms = [];
  166.         foreach ($pagination as $Product) {
  167.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  168.             $builder $this->formFactory->createNamedBuilder(
  169.                 '',
  170.                 AddCartType::class,
  171.                 null,
  172.                 [
  173.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  174.                     'allow_extra_fields' => true,
  175.                 ]
  176.             );
  177.             $addCartForm $builder->getForm();
  178.             $forms[$Product->getId()] = $addCartForm->createView();
  179.         }
  180.         // 表示件数
  181.         $builder $this->formFactory->createNamedBuilder(
  182.             'disp_number',
  183.             ProductListMaxType::class,
  184.             null,
  185.             [
  186.                 'required' => false,
  187.                 'allow_extra_fields' => true,
  188.             ]
  189.         );
  190.         if ($request->getMethod() === 'GET') {
  191.             $builder->setMethod('GET');
  192.         }
  193.         $dispNumberForm $builder->getForm();
  194.         $dispNumberForm->handleRequest($request);
  195.         // ソート順
  196.         $builder $this->formFactory->createNamedBuilder(
  197.             'orderby',
  198.             ProductListOrderByType::class,
  199.             null,
  200.             [
  201.                 'required' => false,
  202.                 'allow_extra_fields' => true,
  203.             ]
  204.         );
  205.         if ($request->getMethod() === 'GET') {
  206.             $builder->setMethod('GET');
  207.         }
  208.         $orderByForm $builder->getForm();
  209.         $orderByForm->handleRequest($request);
  210.         $Category $searchForm->get('category_id')->getData();
  211.         // ▼タグ検索
  212.         $Tag $searchForm->get('product_tag_id')->getData();
  213.         return [
  214.             'subtitle' => $this->getPageTitle($searchData),
  215.             'pagination' => $pagination,
  216.             'search_form' => $searchForm->createView(),
  217.             'disp_number_form' => $dispNumberForm->createView(),
  218.             'order_by_form' => $orderByForm->createView(),
  219.             'forms' => $forms,
  220.             'Category' => $Category,
  221.             'Tag' => $Tag,
  222.         ];
  223.     }
  224.     /**
  225.      * 商品詳細画面.(紹介)
  226.      *
  227.      * @Route("/products/detail/{id}/{guid}", name="product_detailintro", methods={"GET"}, requirements={"id" = "\d+"})
  228.      * @Template("Product/detail.twig")
  229.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  230.      *
  231.      * @param Request $request
  232.      * @param Product $Product
  233.      *
  234.      * @return array
  235.      */
  236.     public function detailIntro(Request $requestProduct $Product$guid)
  237.     {
  238.         $CustomerID $this->productService->getDecodeByShareID($guid);
  239.         
  240.         if($CustomerID != ""){
  241.             $this->productService->addIntroProducts($Product->getId(), $CustomerID);
  242.             //print_r($this->productService->getIntroProducts());
  243.         }
  244.         $rs $this->detail($request$Product);
  245.         $rs['guid'] = $guid;
  246.         return $rs;
  247.     }
  248. }