<?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\Event\EventArgs;
use Eccube\Event\TemplateEvent;
use Plugin\ExpressLink42\Service\ConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ExpressLinkEvent implements EventSubscriberInterface
{
protected $configService;
public function __construct(
ConfigService $configService
)
{
$this->configService = $configService;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'@admin/Order/index.twig' => 'onTemplateAdminOrder',
'Mypage/history.twig' => 'onTemplateFrontMypageHistory',
'csvimportproductext.admin.product.csv.import.product.process' => 'hookAdminProductCsvImportProductProcess',
];
}
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);
}
public function onTemplateFrontMypageHistory(TemplateEvent $event)
{
$source = $event->getSource();
if(preg_match("/\{\{\sShipping\.shipping\_delivery\_name\s\}\}\<\/dd\>[\n|\r\n|\r]\s*\<\/div\>/",$source, $result)){
$search = $result[0];
$replace = $search . "{{ include('@ExpressLink42/default/Mypage/tracking_info.twig') }}";
$source = str_replace($search, $replace, $source);
}
$event->setSource($source);
}
public function hookAdminProductCsvImportProductProcess(EventArgs $event)
{
$row = $event->getArgument('row');
$ProductClass = $event->getArgument('ProductClass');
$Product = $ProductClass->getProduct();
if(isset($row[trans('expresslink.admin.form.product.label.shipping_name')])){
$Product->setShippingName($row[trans('expresslink.admin.form.product.label.shipping_name')]);
}
}
}