app/Customize/EventSubscriber/ProductDetailEventSubscriber.php line 63

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\EventSubscriber;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Eccube\Common\EccubeConfig;
  15. use Eccube\Event\EccubeEvents;
  16. use Eccube\Event\EventArgs;
  17. use Twig\Environment;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\HttpFoundation\RedirectResponse;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. class ProductDetailEventSubscriber implements EventSubscriberInterface
  22. {
  23.     protected $eccubeConfig;
  24.     private $twig;
  25.     /**
  26.      * @var EntityManagerInterface
  27.      */
  28.     protected $entityManager;
  29.     protected $urlGenerator;
  30.     /**
  31.      * ProductDetailEventSubscriber constructor.
  32.      */
  33.     public function __construct(
  34.         EccubeConfig $eccubeConfig,
  35.         Environment $twig,
  36.         EntityManagerInterface $entityManager,
  37.         UrlGeneratorInterface $urlGenerator
  38.     ) {
  39.         $this->eccubeConfig $eccubeConfig;
  40.         $this->twig $twig;
  41.         $this->entityManager $entityManager;
  42.         $this->urlGenerator $urlGenerator;
  43.     }
  44.     /**
  45.      * @return array
  46.      */
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [
  50.             EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE => 'custProductDetail',
  51.         ];
  52.     }
  53.     public function custProductDetail(EventArgs $event)
  54.     {
  55.         $Product $event->getArgument('Product');
  56.         $isGroup false;
  57.         foreach ($Product->getProductClasses() as $ProductClass) {
  58.             $SaleType $ProductClass->getSaleType();
  59.             if ($SaleType->getId() == $this->eccubeConfig['group_product_sale_type_id']) {
  60.                 $isGroup true;
  61.             }
  62.         }
  63.         
  64.         if ($Product->getCodeMin() == "group" || $Product->getCodeMax() == "group" || $isGroup) {
  65.             $url $this->urlGenerator->generate('product_list', ['group_id' => $Product->getId()]); 
  66.             header("Location: " $url);
  67.             exit;
  68.         }
  69.     }
  70. }