app/Plugin/ExpressLink4/ExpressLinkEvent.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : ExpressLink4
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\ExpressLink4;
  12. use Eccube\Event\RenderEvent;
  13. use Eccube\Event\TemplateEvent;
  14. use Eccube\Event\EventArgs;
  15. use Plugin\ExpressLink4\Service\ConfigService;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class ExpressLinkEvent implements EventSubscriberInterface
  18. {
  19.     protected $configService;
  20.     public function __construct(
  21.             ConfigService $configService
  22.             )
  23.     {
  24.         $this->configService = $configService;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             '@admin/Order/index.twig' => 'onTemplateAdminOrder',
  33.             'Mypage/history.twig' => 'onTemplateFrontMypageHistory',
  34.         ];
  35.     }
  36.     public function onTemplateAdminOrder(TemplateEvent $event)
  37.     {
  38.         $sagawa_all = $this->configService->getConfig('sagawa_delivtype_all');
  39.         $sagawa_flg = empty($sagawa_all) ? false : true;
  40.         $b2_all = $this->configService->getConfig('b2_delivtype_all');
  41.         $sagawa_mail = $this->configService->getConfig('sagawa_delivtype_mail');
  42.         $yuprir_all = $this->configService->getConfig('yuprir_delivtype_all');
  43.         $km2 = $this->configService->getConfig('km2_delivtype_normal');
  44.         $Config['b2'] = empty($b2_all) ? false : true;
  45.         $Config['ehiden2'] = ($this->configService->getConfig('ehiden2_use') == 1 && $sagawa_flg) ? true : false;
  46.         $Config['ehidenmail'] = empty($sagawa_mail) ? false : true;
  47.         $Config['ehidenpro'] = ($this->configService->getConfig('ehidenpro_use') == 1 && $sagawa_flg) ? true : false;
  48.         $Config['depo'] = ($this->configService->getConfig('depo_use') == 1 && $sagawa_flg) ? true : false;
  49.         $Config['yuprir'] = empty($yuprir_all) ? false : true;
  50.         $Config['km2'] = empty($km2) ? false : true;
  51.         $parameters = $event->getParameters();
  52.         $parameters['Config'] = $Config;
  53.         $event->setParameters($parameters);
  54.         $twig = '@ExpressLink4/admin/Order/csv_menu.twig';
  55.         $event->addSnippet($twig);
  56.     }
  57.     public function onTemplateFrontMypageHistory(TemplateEvent $event)
  58.     {
  59.         $source = $event->getSource();
  60.         if(preg_match("/\{\{\sShipping\.shipping\_delivery\_name\s\}\}\<\/dd\>[\n|\r\n|\r]\s*\<\/div\>/",$source, $result)){
  61.             $search = $result[0];
  62.             $replace = $search . "{{ include('@ExpressLink4/default/Mypage/tracking_info.twig') }}";
  63.             $source = str_replace($search, $replace, $source);
  64.         }
  65.         $event->setSource($source);
  66.     }
  67. }