<?php
/*
* Plugin Name : ExpressLink42
*
* Copyright (C) BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\ExpressLink42\Event;
use Eccube\Common\EccubeConfig;
use Eccube\Event\TemplateEvent;
use Plugin\ExpressLink42\Service\ConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminOrderEvent implements EventSubscriberInterface
{
private $eccubeConfig;
protected $configService;
public function __construct(
EccubeConfig $eccubeConfig,
ConfigService $configService
)
{
$this->eccubeConfig = $eccubeConfig;
$this->configService = $configService;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'@admin/Order/index.twig' => 'onTemplateAdminOrder',
'@admin/Order/edit.twig' => 'onTemplateAdminOrderEdit',
'@admin/Order/shipping.twig' => 'onTemplateAdminShippingEdit',
];
}
public function onTemplateAdminOrder(TemplateEvent $event)
{
$sagawa_all = $this->configService->getConfig('sagawa_delivtype_all');
$sagawa_flg = empty($sagawa_all) ? false : true;
$b2_all = $this->configService->getConfig('b2_delivtype_all');
$sagawa_mail = $this->configService->getConfig('sagawa_delivtype_mail');
$yuprir_all = $this->configService->getConfig('yuprir_delivtype_all');
$km2 = $this->configService->getConfig('km2_delivtype_normal');
$Config['b2'] = empty($b2_all) ? false : true;
$Config['ehiden2'] = ($this->configService->getConfig('ehiden2_use') == 1 && $sagawa_flg) ? true : false;
$Config['ehiden3'] = ($this->configService->getConfig('ehiden3_use') == 1 && $sagawa_flg) ? true : false;
$Config['ehidenmail'] = empty($sagawa_mail) ? false : true;
$Config['ehidenpro'] = ($this->configService->getConfig('ehidenpro_use') == 1 && $sagawa_flg) ? true : false;
$Config['depo'] = ($this->configService->getConfig('depo_use') == 1 && $sagawa_flg) ? true : false;
$Config['yuprir'] = empty($yuprir_all) ? false : true;
$Config['km2'] = empty($km2) ? false : true;
$parameters = $event->getParameters();
$parameters['Config'] = $Config;
$event->setParameters($parameters);
$twig = '@ExpressLink42/admin/Order/csv_menu.twig';
$event->addSnippet($twig);
$js = '@ExpressLink42/admin/Order/csv_menu.js';
$event->addAsset($js);
$twig = '@ExpressLink42/admin/Order/order_search.twig';
$event->addSnippet($twig);
$js = '@ExpressLink42/admin/Order/order_search.js';
$event->addAsset($js);
}
public function onTemplateAdminOrderEdit(TemplateEvent $event)
{
$parameters = $event->getParameters();
$Order = $parameters['Order'];
if(count($Order->getShippings()) == 1){
$twig = '@ExpressLink42/admin/Order/order_schedule_date.twig';
$event->addSnippet($twig);
}
}
public function onTemplateAdminShippingEdit(TemplateEvent $event)
{
$source = $event->getSource();
if(preg_match("/\{\{\sform\_errors\(shippingForm\.DeliveryTime\)\s\}\}[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>/",$source, $result)){
$search = $result[0];
$replace = file_get_contents($this->eccubeConfig->get('plugin_realdir'). '/ExpressLink42/Resource/template/admin/Order/shipping_schedule_date.twig');
$source = str_replace($search, $search . $replace, $source);
}
$event->setSource($source);
}
}