app/Plugin/ExpressLink42/Event/AdminOrderEvent.php line 46

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\Common\EccubeConfig;
  13. use Eccube\Event\TemplateEvent;
  14. use Plugin\ExpressLink42\Service\ConfigService;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class AdminOrderEvent implements EventSubscriberInterface
  17. {
  18.     private $eccubeConfig;
  19.     protected $configService;
  20.     public function __construct(
  21.             EccubeConfig $eccubeConfig,
  22.             ConfigService $configService
  23.             )
  24.     {
  25.         $this->eccubeConfig $eccubeConfig;
  26.         $this->configService $configService;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             '@admin/Order/index.twig' => 'onTemplateAdminOrder',
  35.             '@admin/Order/edit.twig' => 'onTemplateAdminOrderEdit',
  36.             '@admin/Order/shipping.twig' => 'onTemplateAdminShippingEdit',
  37.         ];
  38.     }
  39.     public function onTemplateAdminOrder(TemplateEvent $event)
  40.     {
  41.         $sagawa_all $this->configService->getConfig('sagawa_delivtype_all');
  42.         $sagawa_flg = empty($sagawa_all) ? false true;
  43.         $b2_all $this->configService->getConfig('b2_delivtype_all');
  44.         $sagawa_mail $this->configService->getConfig('sagawa_delivtype_mail');
  45.         $yuprir_all $this->configService->getConfig('yuprir_delivtype_all');
  46.         $km2 $this->configService->getConfig('km2_delivtype_normal');
  47.         $Config['b2'] = empty($b2_all) ? false true;
  48.         $Config['ehiden2'] = ($this->configService->getConfig('ehiden2_use') == && $sagawa_flg) ? true false;
  49.         $Config['ehiden3'] = ($this->configService->getConfig('ehiden3_use') == && $sagawa_flg) ? true false;
  50.         $Config['ehidenmail'] = empty($sagawa_mail) ? false true;
  51.         $Config['ehidenpro'] = ($this->configService->getConfig('ehidenpro_use') == && $sagawa_flg) ? true false;
  52.         $Config['depo'] = ($this->configService->getConfig('depo_use') == && $sagawa_flg) ? true false;
  53.         $Config['yuprir'] = empty($yuprir_all) ? false true;
  54.         $Config['km2'] = empty($km2) ? false true;
  55.         $parameters $event->getParameters();
  56.         $parameters['Config'] = $Config;
  57.         $event->setParameters($parameters);
  58.         $twig '@ExpressLink42/admin/Order/csv_menu.twig';
  59.         $event->addSnippet($twig);
  60.         $js '@ExpressLink42/admin/Order/csv_menu.js';
  61.         $event->addAsset($js);
  62.         $twig '@ExpressLink42/admin/Order/order_search.twig';
  63.         $event->addSnippet($twig);
  64.         $js '@ExpressLink42/admin/Order/order_search.js';
  65.         $event->addAsset($js);
  66.     }
  67.     public function onTemplateAdminOrderEdit(TemplateEvent $event)
  68.     {
  69.         $parameters $event->getParameters();
  70.         $Order $parameters['Order'];
  71.         if(count($Order->getShippings()) == 1){
  72.             $twig '@ExpressLink42/admin/Order/order_schedule_date.twig';
  73.             $event->addSnippet($twig);
  74.         }
  75.     }
  76.     public function onTemplateAdminShippingEdit(TemplateEvent $event)
  77.     {
  78.         $source $event->getSource();
  79.         if(preg_match("/\{\{\sform\_errors\(shippingForm\.DeliveryTime\)\s\}\}[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>/",$source$result)){
  80.             $search $result[0];
  81.             $replace file_get_contents($this->eccubeConfig->get('plugin_realdir'). '/ExpressLink42/Resource/template/admin/Order/shipping_schedule_date.twig');
  82.             $source str_replace($search$search $replace$source);
  83.         }
  84.         $event->setSource($source);
  85.     }
  86. }