app/Plugin/ExpressLink42/Event/ExpressLinkEvent.php line 70

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : ExpressLink42
  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\ExpressLink42\Event;
  12. use Eccube\Event\EventArgs;
  13. use Eccube\Event\TemplateEvent;
  14. use Plugin\ExpressLink42\Service\ConfigService;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class ExpressLinkEvent implements EventSubscriberInterface
  17. {
  18.     protected $configService;
  19.     public function __construct(
  20.             ConfigService $configService
  21.             )
  22.     {
  23.         $this->configService $configService;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             '@admin/Order/index.twig' => 'onTemplateAdminOrder',
  32.             'Mypage/history.twig' => 'onTemplateFrontMypageHistory',
  33.             'csvimportproductext.admin.product.csv.import.product.process' => 'hookAdminProductCsvImportProductProcess',
  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') == && $sagawa_flg) ? true false;
  46.         $Config['ehiden3'] = ($this->configService->getConfig('ehiden3_use') == && $sagawa_flg) ? true false;
  47.         $Config['ehidenmail'] = empty($sagawa_mail) ? false true;
  48.         $Config['ehidenpro'] = ($this->configService->getConfig('ehidenpro_use') == && $sagawa_flg) ? true false;
  49.         $Config['depo'] = ($this->configService->getConfig('depo_use') == && $sagawa_flg) ? true false;
  50.         $Config['yuprir'] = empty($yuprir_all) ? false true;
  51.         $Config['km2'] = empty($km2) ? false true;
  52.         $parameters $event->getParameters();
  53.         $parameters['Config'] = $Config;
  54.         $event->setParameters($parameters);
  55.         $twig '@ExpressLink42/admin/Order/csv_menu.twig';
  56.         $event->addSnippet($twig);
  57.         $js '@ExpressLink42/admin/Order/csv_menu.js';
  58.         $event->addAsset($js);
  59.     }
  60.     public function onTemplateFrontMypageHistory(TemplateEvent $event)
  61.     {
  62.         $source $event->getSource();
  63.         if(preg_match("/\{\{\sShipping\.shipping\_delivery\_name\s\}\}\<\/dd\>[\n|\r\n|\r]\s*\<\/div\>/",$source$result)){
  64.             $search $result[0];
  65.             $replace $search "{{ include('@ExpressLink42/default/Mypage/tracking_info.twig') }}";
  66.             $source str_replace($search$replace$source);
  67.         }
  68.         $event->setSource($source);
  69.     }
  70.     public function hookAdminProductCsvImportProductProcess(EventArgs $event)
  71.     {
  72.         $row $event->getArgument('row');
  73.         $ProductClass $event->getArgument('ProductClass');
  74.         $Product $ProductClass->getProduct();
  75.         if(isset($row[trans('expresslink.admin.form.product.label.shipping_name')])){
  76.             $Product->setShippingName($row[trans('expresslink.admin.form.product.label.shipping_name')]);
  77.         }
  78.     }
  79. }