app/Plugin/CustomerRank42/Event/MypageEvent.php line 45

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\Repository\CustomerPriceRepository;
  14. use Plugin\CustomerRank42\Service\CustomerRankService;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class MypageEvent implements EventSubscriberInterface
  17. {
  18.     private $customerPriceRepository;
  19.     private $customerRankService;
  20.     public function __construct(
  21.             CustomerPriceRepository $customerPriceRepository,
  22.             CustomerRankService $customerRankService
  23.             )
  24.     {
  25.         $this->customerPriceRepository $customerPriceRepository;
  26.         $this->customerRankService $customerRankService;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             'Mypage/history.twig' => 'onTemplateMypageHistory',
  35.             'Mypage/favorite.twig' => 'onTemplateMypageFavorite',
  36.         ];
  37.     }
  38.     public function onTemplateMypageHistory(TemplateEvent $event)
  39.     {
  40.         $this->customerRankService->rankCheckForFront();
  41.         $parameters $event->getParameters();
  42.         $Order $parameters['Order'];
  43.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  44.         foreach($Order->getOrderItems() as $OrderItem){
  45.             $ProductClass $OrderItem->getProductClass();
  46.             if(!is_null($ProductClass)){
  47.                 if(!$ProductClass->isVisible())continue;
  48.                 $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  49.                 $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  50.             }
  51.         }
  52.         $event->setParameters($parameters);
  53.         $source $event->getSource();
  54.         $source preg_replace("/price02/","customer_rank_price",$source);
  55.         $event->setSource($source);
  56.     }
  57.     public function onTemplateMypageFavorite(TemplateEvent $event)
  58.     {
  59.         $this->customerRankService->rankCheckForFront();
  60.         $parameters $event->getParameters();
  61.         $pagination $parameters['pagination'];
  62.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  63.         foreach($pagination as $FavoriteItem){
  64.             $Product $FavoriteItem->getProduct();
  65.             foreach($Product->getProductClasses() as $ProductClass){
  66.                 if(!is_null($ProductClass)){
  67.                     if(!$ProductClass->isVisible())continue;
  68.                     $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  69.                     $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  70.                 }
  71.             }
  72.         }
  73.         $parameters['CustomerRank'] = $CustomerRank;
  74.         $event->setParameters($parameters);
  75.     }
  76. }