app/Plugin/CustomerRank42/Event/AdminCustomerEvent.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : CustomerRank
  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\CustomerRank42\Event;
  12. use Eccube\Event\TemplateEvent;
  13. use Plugin\CustomerRank42\Service\CustomerRankService;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class AdminCustomerEvent implements EventSubscriberInterface
  16. {
  17.     private $customerRankService;
  18.     public function __construct(
  19.             CustomerRankService $customerRankService
  20.             )
  21.     {
  22.         $this->customerRankService $customerRankService;
  23.     }
  24.     /**
  25.      * @return array
  26.      */
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             '@admin/Customer/index.twig' => 'onTemplateAdminCustomer',
  31.             '@admin/Customer/edit.twig' => 'onTemplateAdminCustomerEdit',
  32.         ];
  33.     }
  34.     public function onTemplateAdminCustomer(TemplateEvent $event)
  35.     {
  36.         $twig '@CustomerRank42/admin/Customer/customer_index.twig';
  37.         $event->addSnippet($twig);
  38.         $js '@CustomerRank42/admin/Customer/customer_index.js';
  39.         $event->addAsset($js);
  40.     }
  41.     public function onTemplateAdminCustomerEdit(TemplateEvent $event)
  42.     {
  43.         $parameters $event->getParameters();
  44.         $Customer $parameters['Customer'];
  45.         $condition null;
  46.         if(!is_null($Customer) && $Customer->getId()){
  47.             $condition $this->customerRankService->getCurrentCondition($Customer);
  48.         }
  49.         $parameters['CustomerCondition'] = $condition;
  50.         $event->setParameters($parameters);
  51.         $twig '@CustomerRank42/admin/Customer/customer_rank.twig';
  52.         $event->addSnippet($twig);
  53.         $js '@CustomerRank42/admin/Customer/customer_rank.js';
  54.         $event->addAsset($js);
  55.     }
  56. }