app/Plugin/JoolenCategoryBannerText42/Event.php line 62

Open in your IDE?
  1. <?php
  2. /*
  3.  * Plugin Name: JoolenCategoryBannerText42
  4.  *
  5.  * Copyright(c) joolen inc. All Rights Reserved.
  6.  *
  7.  * https://www.joolen.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 Plugin\JoolenCategoryBannerText42;
  13. use Eccube\Common\EccubeConfig;
  14. use Plugin\JoolenCategoryBannerText42\Repository\CategoryBannerRepository;
  15. use Plugin\JoolenCategoryBannerText42\Repository\CategoryBannerTextRepository;
  16. class Event implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
  17. {
  18.     private $pluginName 'JoolenCategoryBannerText42';
  19.     protected $eccubeConfig;
  20.     protected $categoryBannerRepository;
  21.     private $categoryBannerTextRepository;
  22.     /**
  23.      * Event constructor.
  24.      */
  25.     public function __construct(
  26.         EccubeConfig $eccubeConfig,
  27.         CategoryBannerRepository $categoryBannerRepository,
  28.         CategoryBannerTextRepository $categoryBannerTextRepository
  29.     ) {
  30.         $this->eccubeConfig                 $eccubeConfig;
  31.         $this->categoryBannerRepository     $categoryBannerRepository;
  32.         $this->categoryBannerTextRepository $categoryBannerTextRepository;
  33.     }
  34.     /**
  35.      * フックポイント一覧
  36.      *
  37.      * @return array
  38.      */
  39.     public static function getSubscribedEvents()
  40.     {
  41.         return [
  42.             // フロント画面
  43.             // ・banner_text.twigへ画像と文章のデータを差し込む
  44.             'JoolenCategoryBannerText42/Resource/template/default/banner_text.twig' => 'addImageAtProductList',
  45.         ];
  46.     }
  47.     // ・商品一覧画面に画像と文章を差し込む
  48.     public function addImageAtProductList(\Eccube\Event\TemplateEvent $event)
  49.     {
  50.         log_info('JoolenCategoryBannerText42 trigger addImageAtProductList start');
  51.         $parameters $event->getParameters();
  52.         $CategoryBanners    = [];    // [初期化] バナー
  53.         $CategoryBannerText null;  // [初期化] テキストなど
  54.         $Category = isset($parameters['Category']) ? $parameters['Category'] : null;
  55.         if ($Category) {
  56.             // バナー
  57.             $CategoryBanners $this->categoryBannerRepository->findBy(['category_id' => $Category->getId()], ['sort_no' => 'ASC']);
  58.             // テキストなど
  59.             $CategoryBannerText $this->categoryBannerTextRepository->findOneBy(['category_id' => $Category->getId()]);
  60.         }
  61.         // ・レコードがない場合でも差し込む(レコードが無い場合もプラグインテンプレートで変更したtwigを表示したいため)
  62.         // パラメータをセット(snippetは手動で追記する方式)
  63.         // snippet: {{ include('JoolenCategoryBannerText42/Resource/template/default/banner_text.twig', ignore_missing = true) }}
  64.         // snippet追記先: 商品一覧ページ(app/template/default/Product/list.twig)
  65.         $parameters['CategoryBanners']    = $CategoryBanners;
  66.         $parameters['CategoryBannerText'] = $CategoryBannerText;
  67.         $event->setParameters($parameters);
  68.         log_info('JoolenCategoryBannerText42 trigger addImageAtProductList finish');
  69.     }
  70. }