app/Plugin/SameCategoryProduct/SameaCategoryProductEvent.php line 60

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2020 YAMATO.CO.LTD
  4.  */
  5. namespace Plugin\SameCategoryProduct;
  6. use Eccube\Common\EccubeConfig;
  7. use Eccube\Entity\Product;
  8. use Eccube\Event\TemplateEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. /**
  12.  * 同カテゴリ商品イベント
  13.  *
  14.  * @author Masaki Okada
  15.  */
  16. class SameaCategoryProductEvent implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * セッションID
  20.      */
  21.     const SEDDION_ID 'plugin.same_category_product.product_id';
  22.     /** @var EccubeConfig $eccubeConfig */
  23.     private $eccubeConfig;
  24.     /** @var EccubeConfig $session */
  25.     private $session;
  26.     /**
  27.      * コンストラクタ
  28.      *
  29.      * @param SessionInterface $session
  30.      * @param EccubeConfig $eccubeConfig
  31.      */
  32.     public function __construct(SessionInterface $sessionEccubeConfig $eccubeConfig)
  33.     {
  34.         $this->session $session;
  35.         $this->eccubeConfig $eccubeConfig;
  36.     }
  37.     /**
  38.      *
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             'Product/detail.twig' => 'productDetail'
  45.         ];
  46.     }
  47.     /**
  48.      * コントローラを呼び出す前に、セッションにパラメタをセットする。
  49.      *
  50.      * @param TemplateEvent $event
  51.      */
  52.     public function productDetail(TemplateEvent $event)
  53.     {
  54.         /** @var Product $Product */
  55.         $Product $event->getParameter('Product');
  56.         // 商品IDをセット
  57.         $this->session->set(self::SEDDION_ID$Product->getId());
  58.     }
  59. }