app/Customize/Controller/ProductController.php line 75

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Controller\CartController as CustomizeCartController;
  4. use Eccube\Entity\Master\ProductStatus;
  5. use Eccube\Event\EccubeEvents;
  6. use Eccube\Event\EventArgs;
  7. use Eccube\Entity\Product;
  8. use Eccube\Form\Type\AddCartType;
  9. use Eccube\Repository\BaseInfoRepository;
  10. use Eccube\Repository\CustomerFavoriteProductRepository;
  11. use Eccube\Repository\Master\ProductListMaxRepository;
  12. use Eccube\Repository\ProductRepository;
  13. use Eccube\Service\CartService;
  14. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  21. use Customize\Repository\ProductRepository as CustomizeProductRepository;
  22. class ProductController extends \Eccube\Controller\ProductController
  23. {
  24.     /**
  25.      * 商品詳細画面.
  26.      *
  27.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  28.      * @Template("Product/detail.twig")
  29.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  30.      *
  31.      * @param Request $request
  32.      * @param Product $Product
  33.      *
  34.      * @return array
  35.      */
  36.     private $title '';
  37.     private CustomizeProductRepository $customizeProdRepo;
  38.     private CustomizeCartController $customizeCartController;
  39.     public function __construct(PurchaseFlow $cartPurchaseFlowCustomerFavoriteProductRepository $customerFavoriteProductRepositoryCartService $cartServiceProductRepository $productRepositoryBaseInfoRepository $baseInfoRepositoryAuthenticationUtils $helperProductListMaxRepository $productListMaxRepositoryCustomizeProductRepository $customizeProdRepoCustomizeCartController $customizeCartController)
  40.     {
  41.         parent::__construct($cartPurchaseFlow$customerFavoriteProductRepository$cartService$productRepository$baseInfoRepository$helper$productListMaxRepository);
  42.         $this->customizeProdRepo       $customizeProdRepo;
  43.         $this->customizeCartController $customizeCartController;
  44.     }
  45.     /**
  46.      * 商品詳細画面.
  47.      *
  48.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  49.      * @Template("Product/detail.twig")
  50.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  51.      *
  52.      * @param Request $request
  53.      * @param Product $Product
  54.      *
  55.      * @return array | \Symfony\Component\HttpFoundation\RedirectResponse
  56.      */
  57.     public function detail(Request $requestProduct $Product)
  58.     {
  59.         if (!$this->checkVisibility($Product)) {
  60.             throw new NotFoundHttpException();
  61.         }
  62.         $builder $this->formFactory->createNamedBuilder(
  63.             '',
  64.             AddCartType::class,
  65.             null,
  66.             [
  67.                 'product'           => $Product,
  68.                 'id_add_product_id' => false,
  69.             ]
  70.         );
  71.         $event = new EventArgs(
  72.             [
  73.                 'builder' => $builder,
  74.                 'Product' => $Product,
  75.             ],
  76.             $request
  77.         );
  78.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
  79.         $is_favorite false;
  80.         if ($this->isGranted('ROLE_USER')) {
  81.             $Customer    $this->getUser();
  82.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  83.         }
  84.         $isDirectCart $request->get('direct_cart') == $this->customizeProdRepo->getValIsDirectCart();
  85.         $available    $Product->getStockFind() && $Product->getStatus()->getId() == ProductStatus::DISPLAY_SHOW;
  86.         if ($isDirectCart && $available) {
  87.             $flag $this->customizeProdRepo->isDirectCart($Product$this->cartService$this->customizeCartController);
  88.             if ($flag) {
  89.                 return $this->redirectToRoute('cart');
  90.             }
  91.         }
  92.         return [
  93.             'title'       => $this->title,
  94.             'subtitle'    => $Product->getName(),
  95.             'form'        => $builder->getForm()->createView(),
  96.             'Product'     => $Product,
  97.             'is_favorite' => $is_favorite,
  98.         ];
  99.     }
  100. }