app/Plugin/CustomerRank/CustomerRankEvent.php line 155

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\CustomerRank;
  12. use Eccube\Event\EccubeEvents;
  13. use Eccube\Event\RenderEvent;
  14. use Eccube\Event\TemplateEvent;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Repository\CustomerRepository;
  17. use Eccube\Repository\ProductClassRepository;
  18. use Eccube\Service\CartService;
  19. use Plugin\CustomerRank\Repository\CustomerRankRepository;
  20. use Plugin\CustomerRank\Repository\CustomerPriceRepository;
  21. use Plugin\CustomerRank\Entity\CustomerPrice;
  22. use Plugin\CustomerRank\Entity\CustomerRankConfig;
  23. use Plugin\CustomerRank\Service\CustomerRankService;
  24. use Symfony\Component\Form\Extension\Core\Type;
  25. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  26. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. class CustomerRankEvent implements EventSubscriberInterface
  29. {
  30.     private $entityManager;
  31.     private $customerRepository;
  32.     private $productClassRepository;
  33.     private $cartService;
  34.     private $customerRankRepository;
  35.     private $customerPriceRepository;
  36.     private $customerRankService;
  37.     /**
  38.      * CustomerRankController constructor.
  39.      * @param CustomerRankRepository $customerRankRepository
  40.      */
  41.     public function __construct(
  42.             EntityManagerInterface $entityManager,
  43.             CustomerRepository $customerRepository,
  44.             ProductClassRepository $productClassRepository,
  45.             CartService $cartService,
  46.             CustomerRankRepository $customerRankRepository,
  47.             CustomerPriceRepository $customerPriceRepository,
  48.             CustomerRankService $customerRankService
  49.             )
  50.     {
  51.         $this->entityManager $entityManager;
  52.         $this->customerRepository $customerRepository;
  53.         $this->productClassRepository $productClassRepository;
  54.         $this->cartService $cartService;
  55.         $this->customerRankRepository $customerRankRepository;
  56.         $this->customerPriceRepository $customerPriceRepository;
  57.         $this->customerRankService $customerRankService;
  58.     }
  59.     /**
  60.      * @return array
  61.      */
  62.     public static function getSubscribedEvents()
  63.     {
  64.         return [
  65.             '@admin/Customer/index.twig' => 'onTemplateAdminCustomer',
  66.             '@admin/Customer/edit.twig' => 'onTemplateAdminCustomerEdit',
  67.             '@admin/Product/product.twig' => 'onTemplateAdminProductEdit',
  68.             EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE => 'hookAdminProductEditComplete',
  69.             EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE => 'hookAdminProductCopyComplete',
  70.             EccubeEvents::ADMIN_PRODUCT_CSV_EXPORT => 'hookAdminProductCsvExport',
  71.             '@admin/Product/product_class.twig' => 'onTemplateAdminProductClassEdit',
  72.             '@admin/Order/index.twig' => 'onTemplateAdminOrder',
  73.             '@admin/Order/edit.twig' => 'onTemplateAdminOrderEdit',
  74.             EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE => 'hookAdminOrderEditSearchProductComplete',
  75.             EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE => 'hookAdminOrderEditIndexComplete',
  76.             'Product/list.twig' => 'onTemplateProductList',
  77.             'Product/detail.twig' => 'onTemplateProductDetail',
  78.             'Cart/index.twig' => 'onTemplateCart',
  79.             EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'hookFrontEntryIndexComplete',
  80.             EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE => 'hookFrontShoppingCompleteInitialize',
  81.             'Mypage/history.twig' => 'onTemplateMypageHistory',
  82.             'Mypage/favorite.twig' => 'onTemplateMypageFavorite',
  83.             'csvimportproductext.admin.product.csv.import.product.descriptions' => 'hookAdminProductCsvImportProductDescriptions',
  84.             'csvimportproductext.admin.product.csv.import.product.check'=> 'hookAdminProductCsvImportProductCheck',
  85.             'csvimportproductext.admin.product.csv.import.product.process' => 'hookAdminProductCsvImportProductProcess',
  86.             '@MailMagazine4/admin/index.twig' => 'onTemplateAdminCustomer',
  87.             '@MailMagazine4/admin/history_condition.twig' => 'onTemplateMailmagazineHistoryCondition',
  88.         ];
  89.     }
  90.     public function onTemplateAdminCustomer(TemplateEvent $event)
  91.     {
  92.         $twig '@CustomerRank/admin/Customer/customer_index.twig';
  93.         $event->addSnippet($twig);
  94.     }
  95.     public function onTemplateAdminCustomerEdit(TemplateEvent $event)
  96.     {
  97.         $twig '@CustomerRank/admin/Customer/customer_rank.twig';
  98.         $event->addSnippet($twig);
  99.     }
  100.     public function onTemplateAdminProductEdit(TemplateEvent $event)
  101.     {
  102.         $parameters $event->getParameters();
  103.         $CustomerRanks $this->customerRankRepository->getList();
  104.         $parameters['CustomerRanks'] = $CustomerRanks;
  105.         $event->setParameters($parameters);
  106.         $twig '@CustomerRank/admin/Product/customer_price.twig';
  107.         $event->addSnippet($twig);
  108.     }
  109.     public function hookAdminProductEditComplete(EventArgs $event)
  110.     {
  111.         $Product $event->getArgument('Product');
  112.         $form $event->getArgument('form');
  113.         $has_class $Product->hasProductClass();
  114.         if(!$has_class){
  115.             $CustomerRanks $this->customerRankRepository->getList();
  116.             $ProductClass $form['class']->getData();
  117.             foreach($CustomerRanks as $CustomerRank){
  118.                 if($form['class']->has('customer_price_'$CustomerRank->getId())){
  119.                     $CustomerPrice $this->customerPriceRepository->findOneBy(['ProductClass' => $ProductClass'CustomerRank' => $CustomerRank]);
  120.                     if(!$CustomerPrice){
  121.                         $CustomerPrice =  new CustomerPrice();
  122.                         $CustomerPrice->setProductClass($ProductClass);
  123.                         $CustomerPrice->setCustomerRank($CustomerRank);
  124.                     }
  125.                     $CustomerPrice->setPrice($form['class']->get('customer_price_'$CustomerRank->getId())->getData());
  126.                     $this->entityManager->persist($CustomerPrice);
  127.                 }
  128.             }
  129.             $this->entityManager->flush();
  130.         }
  131.     }
  132.     public function hookAdminProductCopyComplete(EventArgs $event)
  133.     {
  134.         $Product $event->getArgument('Product');
  135.         $CopyProduct $event->getArgument('CopyProduct');
  136.         $orgProductClasses $Product->getProductClasses();
  137.         $CustomerRanks $this->customerRankRepository->getList();
  138.         foreach($CustomerRanks as $CustomerRank){
  139.             foreach ($orgProductClasses as $ProductClass) {
  140.                 $CopyProductClass $this->productClassRepository->findOneBy(['Product'=> $CopyProduct'ClassCategory1' => $ProductClass->getClassCategory1(), 'ClassCategory2' => $ProductClass->getClassCategory2()]);
  141.                 $orgCustomerPrice $this->customerPriceRepository->findOneBy(['ProductClass' => $ProductClass'CustomerRank' => $CustomerRank]);
  142.                 if($CopyProductClass){
  143.                     $CustomerPrice = new CustomerPrice();
  144.                     $CustomerPrice->setProductClass($CopyProductClass);
  145.                     $CustomerPrice->setCustomerRank($CustomerRank);
  146.                     if($orgCustomerPrice){
  147.                         $CustomerPrice->setPrice($orgCustomerPrice->getPrice());
  148.                     }
  149.                     $this->entityManager->persist($CustomerPrice);
  150.                 }
  151.             }
  152.         }
  153.         $this->entityManager->flush();
  154.     }
  155.     public function hookAdminProductCsvExport(EventArgs $event)
  156.     {
  157.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  158.         if ($ExportCsvRow->isDataNull()) {
  159.             $csvService $event->getArgument('csvService');
  160.             $ProductClass $event->getArgument('ProductClass');
  161.             $Csv $event->getArgument('Csv');
  162.             $csvEntityName str_replace('\\\\''\\'$Csv->getEntityName());
  163.             if($csvEntityName == 'Plugin\CustomerRank\Entity\CustomerPrice'){
  164.                 $customer_rank_id ltrim($Csv->getFieldName(), 'customerrank_price_');
  165.                 if(is_numeric($customer_rank_id)){
  166.                     $CustomerRank $this->customerRankRepository->find($customer_rank_id);
  167.                     if(!is_null($CustomerRank)){
  168.                         $CustomerPrice $this->customerPriceRepository->findOneBy(['ProductClass' => $ProductClass'CustomerRank' => $CustomerRank]);
  169.                         if(!is_null($CustomerPrice)){
  170.                             $ExportCsvRow->setData($CustomerPrice->getPrice());
  171.                         }
  172.                     }
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     public function onTemplateAdminProductClassEdit(TemplateEvent $event)
  178.     {
  179.         $parameters $event->getParameters();
  180.         $CustomerRanks $this->customerRankRepository->getList();
  181.         $parameters['CustomerRanks'] = $CustomerRanks;
  182.         $event->setParameters($parameters);
  183.         $twig '@CustomerRank/admin/Product/customer_price_class.twig';
  184.         $event->addSnippet($twig);
  185.     }
  186.     public function onTemplateAdminOrder(TemplateEvent $event)
  187.     {
  188.         $twig '@CustomerRank/admin/Order/order_index.twig';
  189.         $event->addSnippet($twig);
  190.     }
  191.     public function onTemplateAdminOrderEdit(TemplateEvent $event)
  192.     {
  193.         $source $event->getSource();
  194.         if(preg_match("/\\$\('\#admin\_search\_product\_id'\)\.val\(\),/",$source$result)){
  195.             $search $result[0];
  196.             $replace $search "\n'customer_id':$('#order_CustomerId').text(),";
  197.             $source str_replace($search$replace$source);
  198.         }
  199.         $event->setSource($source);
  200.         $twig '@CustomerRank/admin/Order/customer_rank.twig';
  201.         $event->addSnippet($twig);
  202.     }
  203.     public function hookAdminOrderEditSearchProductComplete(EventArgs $event)
  204.     {
  205.         $request $event->getRequest();
  206.         $session $request->getSession();
  207.         $pagination $event->getArgument('pagination');
  208.         if ('POST' === $request->getMethod()) {
  209.             $customer_id $request->get('customer_id');
  210.             $session->set('eccube.cusstomerrank.order.product.search'$customer_id);
  211.         }else{
  212.             $customer_id $session->get('eccube.cusstomerrank.order.product.search');
  213.         }
  214.         if($customer_id 0){
  215.             $Customer $this->customerRepository->find($customer_id);
  216.             $CustomerRank $Customer->getCustomerRank();
  217.             if(!is_null($CustomerRank)){
  218.                 foreach($pagination as $Product){
  219.                     foreach($Product->getProductClasses() as $ProductClass){
  220.                         $ProductClass->setPrice02($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  221.                     }
  222.                 }
  223.             }
  224.         }
  225.     }
  226.     public function hookAdminOrderEditIndexComplete(EventArgs $event)
  227.     {
  228.         $Customer $event->getArgument('Customer');
  229.         if(!is_null($Customer))$this->customerRankService->checkRank($Customer);
  230.     }
  231.     public function hookFrontEntryIndexComplete(EventArgs $event)
  232.     {
  233.         $Customer $event->getArgument('Customer');
  234.         $CustomerRank $this->customerRankRepository->findOneBy(['initial_flg' => true]);
  235.         if(!is_null($CustomerRank)){
  236.             $Customer->setCustomerRank($CustomerRank);
  237.             $this->entityManager->persist($Customer);
  238.             $this->entityManager->flush($Customer);
  239.         }
  240.     }
  241.     public function onTemplateProductDetail(TemplateEvent $event)
  242.     {
  243.         $this->rankCheckForFront();
  244.         $parameters $event->getParameters();
  245.         $Product $parameters['Product'];
  246.         $class_categories = [];
  247.         $loginDisp $this->customerRankService->getConfig('login_disp');
  248.         $initFlag $loginDisp == CustomerRankConfig::DISABLED true false;
  249.         $CustomerRank $this->customerRankService->getCustomerRank($initFlag);
  250.         if(!is_null($CustomerRank)){
  251.             $class_categories[$Product->getId()]['__unselected']['#'] = [
  252.                 'customer_rank_price' => '',
  253.                 'customer_rank_price_inc_tax' => '',
  254.             ];
  255.             foreach($Product->getProductClasses() as $ProductClass){
  256.                 if(!$ProductClass->isVisible())continue;
  257.                 // ver.1.1.0未満のバージョン用に残しておく
  258.                 $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  259.                 $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  260.                 $ClassCategory1 $ProductClass->getClassCategory1();
  261.                 $ClassCategory2 $ProductClass->getClassCategory2();
  262.                 if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  263.                     continue;
  264.                 }
  265.                 $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  266.                 $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  267.                 $class_category_name2 $ClassCategory2 $ClassCategory2->getName().($ProductClass->getStockFind() ? '' trans('product.text.out_of_stock')) : '';
  268.                 $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  269.                     'customer_rank_price' => '',
  270.                     'customer_rank_price_inc_tax' => '',
  271.                 ];
  272.                 $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  273.                     'customer_rank_price' => number_format($ProductClass->getCustomerRankPrice($CustomerRank->getId())),
  274.                     'customer_rank_price_inc_tax' => number_format($ProductClass->getCustomerRankPriceIncTax($CustomerRank->getId())),
  275.                 ];
  276.             }
  277.         }
  278.         $parameters['CustomerRank'] = $CustomerRank;
  279.         $parameters['CustomerPrices'] = $class_categories;
  280.         $event->setParameters($parameters);
  281.         $twig '@CustomerRank/default/Product/product_js.twig';
  282.         $event->addSnippet($twig);
  283.     }
  284.     public function onTemplateProductList(TemplateEvent $event)
  285.     {
  286.         $this->rankCheckForFront();
  287.         $parameters $event->getParameters();
  288.         $pagination $parameters['pagination'];
  289.         $class_categories = [];
  290.         $loginDisp $this->customerRankService->getConfig('login_disp');
  291.         $initFlag $loginDisp == CustomerRankConfig::DISABLED true false;
  292.         $CustomerRank $this->customerRankService->getCustomerRank($initFlag);
  293.         if(!is_null($CustomerRank)){
  294.             foreach($pagination as $Product){
  295.                 $class_categories[$Product->getId()]['__unselected']['#'] = [
  296.                     'customer_rank_price' => '',
  297.                     'customer_rank_price_inc_tax' => '',
  298.                 ];
  299.                 foreach($Product->getProductClasses() as $ProductClass){
  300.                     if(!$ProductClass->isVisible())continue;
  301.                     // ver.1.1.0未満のバージョン用に残しておく
  302.                     $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  303.                     $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  304.                     $ClassCategory1 $ProductClass->getClassCategory1();
  305.                     $ClassCategory2 $ProductClass->getClassCategory2();
  306.                     if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  307.                         continue;
  308.                     }
  309.                     $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  310.                     $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  311.                     $class_category_name2 $ClassCategory2 $ClassCategory2->getName().($ProductClass->getStockFind() ? '' trans('product.text.out_of_stock')) : '';
  312.                     $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  313.                         'customer_rank_price' => '',
  314.                         'customer_rank_price_inc_tax' => '',
  315.                     ];
  316.                     $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  317.                         'customer_rank_price' => number_format($ProductClass->getCustomerRankPrice($CustomerRank->getId())),
  318.                         'customer_rank_price_inc_tax' => number_format($ProductClass->getCustomerRankPriceIncTax($CustomerRank->getId())),
  319.                     ];
  320.                 }
  321.             }
  322.         }
  323.         $parameters['CustomerRank'] = $CustomerRank;
  324.         $parameters['CustomerPrices'] = $class_categories;
  325.         $event->setParameters($parameters);
  326.         $twig '@CustomerRank/default/Product/product_js.twig';
  327.         $event->addSnippet($twig);
  328.     }
  329.     public function onTemplateCart(TemplateEvent $event)
  330.     {
  331.         $parameters $event->getParameters();
  332.         $least $parameters['least'];
  333.         $isDeliveryFree $parameters['is_delivery_free'];
  334.         $CustomerRank $this->customerRankService->getCustomerRank(false);
  335.         if(!is_null($CustomerRank)){
  336.             $Carts $this->cartService->getCarts();
  337.             if (strlen($CustomerRank->getDeliveryFreeCondition()) > 0) {
  338.                 foreach ($Carts as $Cart) {
  339.                     $isDeliveryFree[$Cart->getCartKey()] = false;
  340.                     if ($CustomerRank->getDeliveryFreeCondition() <= $Cart->getTotalPrice()) {
  341.                         $isDeliveryFree[$Cart->getCartKey()] = true;
  342.                     } else {
  343.                         $least[$Cart->getCartKey()] = $CustomerRank->getDeliveryFreeCondition() - $Cart->getTotalPrice();
  344.                     }
  345.                 }
  346.             }
  347.         }
  348.         $parameters['least'] = $least;
  349.         $parameters['is_delivery_free'] = $isDeliveryFree;
  350.         $event->setParameters($parameters);
  351.     }
  352.     public function hookFrontShoppingCompleteInitialize(EventArgs $event)
  353.     {
  354.         $Order $event->getArgument('Order');
  355.         $Customer $Order->getCustomer();
  356.         if(!is_null($Customer))$this->customerRankService->checkRank($Customer);
  357.     }
  358.     public function onTemplateMypageHistory(TemplateEvent $event)
  359.     {
  360.         $this->rankCheckForFront();
  361.         $parameters $event->getParameters();
  362.         $Order $parameters['Order'];
  363.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  364.         foreach($Order->getOrderItems() as $OrderItem){
  365.             $ProductClass $OrderItem->getProductClass();
  366.             if(!is_null($ProductClass)){
  367.                 if(!$ProductClass->isVisible())continue;
  368.                 $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  369.                 $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  370.             }
  371.         }
  372.         $event->setParameters($parameters);
  373.         $source $event->getSource();
  374.         $source preg_replace("/price02/","customer_rank_price",$source);
  375.         $event->setSource($source);
  376.     }
  377.     public function onTemplateMypageFavorite(TemplateEvent $event)
  378.     {
  379.         $this->rankCheckForFront();
  380.         $parameters $event->getParameters();
  381.         $pagination $parameters['pagination'];
  382.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  383.         foreach($pagination as $FavoriteItem){
  384.             $Product $FavoriteItem->getProduct();
  385.             foreach($Product->getProductClasses() as $ProductClass){
  386.                 if(!is_null($ProductClass)){
  387.                     if(!$ProductClass->isVisible())continue;
  388.                     $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  389.                     $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  390.                 }
  391.             }
  392.         }
  393.         $parameters['CustomerRank'] = $CustomerRank;
  394.         $event->setParameters($parameters);
  395.     }
  396.     public function hookAdminProductCsvImportProductDescriptions(EventArgs $event)
  397.     {
  398.         $header $event->getArgument('header');
  399.         $key $event->getArgument('key');
  400.         $CustomerRanks $this->customerRankRepository->findAll();
  401.         foreach($CustomerRanks as $CustomerRank){
  402.             if($key == $CustomerRank->getName() . trans('customerrank.common.customer_price')){
  403.                 $header['description'] = trans('customerrank.admin.product.product_csv.customer_price_description');
  404.                 $header['required'] = false;
  405.             }
  406.         }
  407.         $event->setArgument('header',$header);
  408.     }
  409.     public function hookAdminProductCsvImportProductCheck(EventArgs $event)
  410.     {
  411.         $row $event->getArgument('row');
  412.         $data $event->getArgument('data');
  413.         $errors $event->getArgument('errors');
  414.         $CustomerRanks $this->customerRankRepository->findAll();
  415.         foreach($CustomerRanks as $CustomerRank){
  416.             if(isset($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')])){
  417.                 if($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')] !== '' && !is_numeric($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')])){
  418.                     $message trans('admin.common.csv_invalid_greater_than_zero', [
  419.                         '%line%' => $data->key() + 1,
  420.                         '%name%' => $CustomerRank->getName(). trans('customerrank.common.customer_price'),
  421.                     ]);
  422.                     $errors[] = $message;
  423.                 }
  424.             }
  425.         }
  426.         $event->setArgument('errors',$errors);
  427.     }
  428.     public function hookAdminProductCsvImportProductProcess(EventArgs $event)
  429.     {
  430.         $row $event->getArgument('row');
  431.         $data $event->getArgument('data');
  432.         $ProductClass $event->getArgument('ProductClass');
  433.         $Product $ProductClass->getProduct();
  434.         $CustomerRanks $this->customerRankRepository->findAll();
  435.         foreach($CustomerRanks as $CustomerRank){
  436.             if(isset($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')])){
  437.                 $plgPrice $this->customerPriceRepository->findOneBy(['ProductClass' => $ProductClass'CustomerRank' => $CustomerRank]);
  438.                 if($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')] != ''){
  439.                     if(is_null($plgPrice)){
  440.                         $plgPrice = new CustomerPrice();
  441.                         $plgPrice->setProductClass($ProductClass);
  442.                         $plgPrice->setCustomerRank($CustomerRank);
  443.                     }
  444.                     $plgPrice->setPrice($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')]);
  445.                     $this->entityManager->persist($plgPrice);
  446.                 }else{
  447.                     if(isset($plgPrice))$this->entityManager->remove($plgPrice);
  448.                 }
  449.             }
  450.             if(isset($plgPrice))unset($plgPrice);
  451.         }
  452.     }
  453.     public function onTemplateMailmagazineHistoryCondition(TemplateEvent $event)
  454.     {
  455.         $parameters $event->getParameters();
  456.         $searchData $parameters['search_data'];
  457.         if(isset($searchData['customer_rank']) && is_array($searchData['customer_rank'])){
  458.             $val = [];
  459.             foreach($searchData['customer_rank'] as $id){
  460.                 $CustomerRank $this->customerRankRepository->find($id);
  461.                 if($CustomerRank){
  462.                     $val[] = $CustomerRank->getName();
  463.                 }
  464.             }
  465.             if(count($val) != 0){
  466.                 $searchData['customer_rank'] = implode(', '$val);
  467.             }else{
  468.                 $searchData['customer_rank'] = null;
  469.             }
  470.         }
  471.         $parameters['search_data'] = $searchData;
  472.         $event->setParameters($parameters);
  473.         $twig '@CustomerRank/admin/mailmagazine_history_condition_add.twig';
  474.         $event->addSnippet($twig);
  475.     }
  476.     public function rankCheckForFront()
  477.     {
  478.         $Customer $this->customerRankService->getLoginCustomer();
  479.         if(!is_null($Customer))$this->customerRankService->checkRank($Customer);
  480.     }
  481. }