app/Plugin/CheckProduct4/CheckProductEvent.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2019 SYSTEM FRIEND INC.
  4.  */
  5. namespace Plugin\CheckProduct4;
  6. use Eccube\Common\EccubeConfig;
  7. use Eccube\Event\TemplateEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. class CheckProductEvent implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var $eccubeConfig
  14.      */
  15.     private $eccubeConfig;
  16.     /**
  17.      * @var $session
  18.      */
  19.     private $session;
  20.     /**
  21.      * ProductReview constructor.
  22.      *
  23.      * @param SessionInterface $session
  24.      * @param EccubeConfig $eccubeConfig
  25.      *
  26.      */
  27.     public function __construct(SessionInterface $sessionEccubeConfig $eccubeConfig) {
  28.         $this->session $session;
  29.         $this->eccubeConfig $eccubeConfig;
  30.     }
  31.     /**
  32.      * @return array
  33.      */
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             'Product/detail.twig' => 'productDetail',
  38.         ];
  39.     }
  40.     /**
  41.      * @param TemplateEvent $event
  42.      */
  43.     public function productDetail(TemplateEvent $event)
  44.     {
  45.         /** @var Product $Product */
  46.         $Product $event->getParameter('Product');
  47.         $id $Product->getId();
  48.         $arr $this->session->get('plugin.check_product.product');
  49.         $arr[] = $id;
  50.         $arr array_unique($arr);
  51.         $max $this->eccubeConfig['PLG_CHECK_PRODUCT_MAX'];
  52.         $arr array_slice($arr, (- $max), $max);
  53.         $this->session->set('plugin.check_product.product'$arr);
  54.     }
  55. }