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

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