<?php
/*
* Plugin Name : CustomerRank
*
* 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\CustomerRank42\Event;
use Eccube\Event\TemplateEvent;
use Plugin\CustomerRank42\Service\CustomerRankService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminCustomerEvent implements EventSubscriberInterface
{
private $customerRankService;
public function __construct(
CustomerRankService $customerRankService
)
{
$this->customerRankService = $customerRankService;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'@admin/Customer/index.twig' => 'onTemplateAdminCustomer',
'@admin/Customer/edit.twig' => 'onTemplateAdminCustomerEdit',
];
}
public function onTemplateAdminCustomer(TemplateEvent $event)
{
$twig = '@CustomerRank42/admin/Customer/customer_index.twig';
$event->addSnippet($twig);
$js = '@CustomerRank42/admin/Customer/customer_index.js';
$event->addAsset($js);
}
public function onTemplateAdminCustomerEdit(TemplateEvent $event)
{
$parameters = $event->getParameters();
$Customer = $parameters['Customer'];
$condition = null;
if(!is_null($Customer) && $Customer->getId()){
$condition = $this->customerRankService->getCurrentCondition($Customer);
}
$parameters['CustomerCondition'] = $condition;
$event->setParameters($parameters);
$twig = '@CustomerRank42/admin/Customer/customer_rank.twig';
$event->addSnippet($twig);
$js = '@CustomerRank42/admin/Customer/customer_rank.js';
$event->addAsset($js);
}
}