app/Plugin/CustomerRank/CustomerRankEvent.php line 217

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.         
  235.         $CustomerRank $this->customerRankRepository->findOneBy(['initial_flg' => true]);
  236.         if(!is_null($CustomerRank)){
  237.             $Customer->setCustomerRank($CustomerRank);
  238.             $this->entityManager->persist($Customer);
  239.             $this->entityManager->flush($Customer);
  240.         }
  241.         
  242.         /// コスモピア独自カスタマイズ START ////////////////////////////////////////////////////////////////////
  243.         
  244.         $customData $Customer->getCustomData(CPSHOP_CUSTOMER_ITEM_EHONCLUB);
  245.         if (!empty($customData) && is_array($customData))
  246.         {
  247.             // 「英語の絵本クラブ会員になる」にチェックが入っている場合
  248.             if ($customData[0] == CPSHOP_CUSTOMER_DATA_EHONCLUB)
  249.             {
  250.                 // 一般会員(または なし)から英語の絵本クラブ会員に変更
  251.                 
  252.                 $ehonclubRank $this->customerRankRepository->findOneBy(['id' => CPSHOP_CUSTOMER_RANK_EHONCLUB]);
  253.                 $Customer->setCustomerRank($ehonclubRank);
  254.             }
  255.         }
  256.         
  257.         /// コスモピア独自カスタマイズ END ////////////////////////////////////////////////////////////////////
  258.     }
  259.     public function onTemplateProductDetail(TemplateEvent $event)
  260.     {
  261.         $this->rankCheckForFront();
  262.         $parameters $event->getParameters();
  263.         $Product $parameters['Product'];
  264.         $class_categories = [];
  265.         $loginDisp $this->customerRankService->getConfig('login_disp');
  266.         $initFlag $loginDisp == CustomerRankConfig::DISABLED true false;
  267.         $CustomerRank $this->customerRankService->getCustomerRank($initFlag);
  268.         if(!is_null($CustomerRank)){
  269.             $class_categories[$Product->getId()]['__unselected']['#'] = [
  270.                 'customer_rank_price' => '',
  271.                 'customer_rank_price_inc_tax' => '',
  272.             ];
  273.             foreach($Product->getProductClasses() as $ProductClass){
  274.                 if(!$ProductClass->isVisible())continue;
  275.                 // ver.1.1.0未満のバージョン用に残しておく
  276.                 $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  277.                 $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  278.                 $ClassCategory1 $ProductClass->getClassCategory1();
  279.                 $ClassCategory2 $ProductClass->getClassCategory2();
  280.                 if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  281.                     continue;
  282.                 }
  283.                 $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  284.                 $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  285.                 $class_category_name2 $ClassCategory2 $ClassCategory2->getName().($ProductClass->getStockFind() ? '' trans('product.text.out_of_stock')) : '';
  286.                 $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  287.                     'customer_rank_price' => '',
  288.                     'customer_rank_price_inc_tax' => '',
  289.                 ];
  290.                 $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  291.                     'customer_rank_price' => number_format($ProductClass->getCustomerRankPrice($CustomerRank->getId())),
  292.                     'customer_rank_price_inc_tax' => number_format($ProductClass->getCustomerRankPriceIncTax($CustomerRank->getId())),
  293.                 ];
  294.             }
  295.         }
  296.         $parameters['CustomerRank'] = $CustomerRank;
  297.         $parameters['CustomerPrices'] = $class_categories;
  298.         $event->setParameters($parameters);
  299.         $twig '@CustomerRank/default/Product/product_js.twig';
  300.         $event->addSnippet($twig);
  301.     }
  302.     public function onTemplateProductList(TemplateEvent $event)
  303.     {
  304.         $this->rankCheckForFront();
  305.         $parameters $event->getParameters();
  306.         $pagination $parameters['pagination'];
  307.         $class_categories = [];
  308.         $loginDisp $this->customerRankService->getConfig('login_disp');
  309.         $initFlag $loginDisp == CustomerRankConfig::DISABLED true false;
  310.         $CustomerRank $this->customerRankService->getCustomerRank($initFlag);
  311.         if(!is_null($CustomerRank)){
  312.             foreach($pagination as $Product){
  313.                 $class_categories[$Product->getId()]['__unselected']['#'] = [
  314.                     'customer_rank_price' => '',
  315.                     'customer_rank_price_inc_tax' => '',
  316.                 ];
  317.                 foreach($Product->getProductClasses() as $ProductClass){
  318.                     if(!$ProductClass->isVisible())continue;
  319.                     // ver.1.1.0未満のバージョン用に残しておく
  320.                     $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  321.                     $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  322.                     $ClassCategory1 $ProductClass->getClassCategory1();
  323.                     $ClassCategory2 $ProductClass->getClassCategory2();
  324.                     if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  325.                         continue;
  326.                     }
  327.                     $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  328.                     $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  329.                     $class_category_name2 $ClassCategory2 $ClassCategory2->getName().($ProductClass->getStockFind() ? '' trans('product.text.out_of_stock')) : '';
  330.                     $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  331.                         'customer_rank_price' => '',
  332.                         'customer_rank_price_inc_tax' => '',
  333.                     ];
  334.                     $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  335.                         'customer_rank_price' => number_format($ProductClass->getCustomerRankPrice($CustomerRank->getId())),
  336.                         'customer_rank_price_inc_tax' => number_format($ProductClass->getCustomerRankPriceIncTax($CustomerRank->getId())),
  337.                     ];
  338.                 }
  339.             }
  340.         }
  341.         $parameters['CustomerRank'] = $CustomerRank;
  342.         $parameters['CustomerPrices'] = $class_categories;
  343.         $event->setParameters($parameters);
  344.         $twig '@CustomerRank/default/Product/product_js.twig';
  345.         $event->addSnippet($twig);
  346.     }
  347.     public function onTemplateCart(TemplateEvent $event)
  348.     {
  349.         $parameters $event->getParameters();
  350.         $least $parameters['least'];
  351.         $isDeliveryFree $parameters['is_delivery_free'];
  352.         $CustomerRank $this->customerRankService->getCustomerRank(false);
  353.         if(!is_null($CustomerRank)){
  354.             $Carts $this->cartService->getCarts();
  355.             if (strlen($CustomerRank->getDeliveryFreeCondition()) > 0) {
  356.                 foreach ($Carts as $Cart) {
  357.                     $isDeliveryFree[$Cart->getCartKey()] = false;
  358.                     if ($CustomerRank->getDeliveryFreeCondition() <= $Cart->getTotalPrice()) {
  359.                         $isDeliveryFree[$Cart->getCartKey()] = true;
  360.                     } else {
  361.                         $least[$Cart->getCartKey()] = $CustomerRank->getDeliveryFreeCondition() - $Cart->getTotalPrice();
  362.                     }
  363.                 }
  364.             }
  365.         }
  366.         $parameters['least'] = $least;
  367.         $parameters['is_delivery_free'] = $isDeliveryFree;
  368.         $event->setParameters($parameters);
  369.     }
  370.     public function hookFrontShoppingCompleteInitialize(EventArgs $event)
  371.     {
  372.         $Order $event->getArgument('Order');
  373.         $Customer $Order->getCustomer();
  374.         if(!is_null($Customer))$this->customerRankService->checkRank($Customer);
  375.     }
  376.     public function onTemplateMypageHistory(TemplateEvent $event)
  377.     {
  378.         $this->rankCheckForFront();
  379.         $parameters $event->getParameters();
  380.         $Order $parameters['Order'];
  381.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  382.         foreach($Order->getOrderItems() as $OrderItem){
  383.             $ProductClass $OrderItem->getProductClass();
  384.             if(!is_null($ProductClass)){
  385.                 if(!$ProductClass->isVisible())continue;
  386.                 $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  387.                 $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  388.             }
  389.         }
  390.         $event->setParameters($parameters);
  391.         $source $event->getSource();
  392.         $source preg_replace("/price02/","customer_rank_price",$source);
  393.         $event->setSource($source);
  394.     }
  395.     public function onTemplateMypageFavorite(TemplateEvent $event)
  396.     {
  397.         $this->rankCheckForFront();
  398.         $parameters $event->getParameters();
  399.         $pagination $parameters['pagination'];
  400.         $CustomerRank $this->customerRankService->getCustomerRank(true);
  401.         foreach($pagination as $FavoriteItem){
  402.             $Product $FavoriteItem->getProduct();
  403.             foreach($Product->getProductClasses() as $ProductClass){
  404.                 if(!is_null($ProductClass)){
  405.                     if(!$ProductClass->isVisible())continue;
  406.                     $ProductClass->setCustomerRankPrice($this->customerPriceRepository->getCustomerPriceByProductClass($CustomerRank$ProductClass));
  407.                     $ProductClass->setCustomerRankPriceIncTax($this->customerPriceRepository->getCustomerPriceIncTaxByProductClass($CustomerRank$ProductClass));
  408.                 }
  409.             }
  410.         }
  411.         $parameters['CustomerRank'] = $CustomerRank;
  412.         $event->setParameters($parameters);
  413.     }
  414.     public function hookAdminProductCsvImportProductDescriptions(EventArgs $event)
  415.     {
  416.         $header $event->getArgument('header');
  417.         $key $event->getArgument('key');
  418.         $CustomerRanks $this->customerRankRepository->findAll();
  419.         foreach($CustomerRanks as $CustomerRank){
  420.             if($key == $CustomerRank->getName() . trans('customerrank.common.customer_price')){
  421.                 $header['description'] = trans('customerrank.admin.product.product_csv.customer_price_description');
  422.                 $header['required'] = false;
  423.             }
  424.         }
  425.         $event->setArgument('header',$header);
  426.     }
  427.     public function hookAdminProductCsvImportProductCheck(EventArgs $event)
  428.     {
  429.         $row $event->getArgument('row');
  430.         $data $event->getArgument('data');
  431.         $errors $event->getArgument('errors');
  432.         $CustomerRanks $this->customerRankRepository->findAll();
  433.         foreach($CustomerRanks as $CustomerRank){
  434.             if(isset($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')])){
  435.                 if($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')] !== '' && !is_numeric($row[$CustomerRank->getName(). trans('customerrank.common.customer_price')])){
  436.                     $message trans('admin.common.csv_invalid_greater_than_zero', [
  437.                         '%line%' => $data->key() + 1,
  438.                         '%name%' => $CustomerRank->getName(). trans('customerrank.common.customer_price'),
  439.                     ]);
  440.                     $errors[] = $message;
  441.                 }
  442.             }
  443.         }
  444.         $event->setArgument('errors',$errors);
  445.     }
  446.     public function hookAdminProductCsvImportProductProcess(EventArgs $event)
  447.     {
  448.         $row $event->getArgument('row');
  449.         $data $event->getArgument('data');
  450.         $ProductClass $event->getArgument('ProductClass');
  451.         $Product $ProductClass->getProduct();
  452.         $CustomerRanks $this->customerRankRepository->findAll();
  453.         foreach($CustomerRanks as $CustomerRank){
  454.             if(isset($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')])){
  455.                 $plgPrice $this->customerPriceRepository->findOneBy(['ProductClass' => $ProductClass'CustomerRank' => $CustomerRank]);
  456.                 if($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')] != ''){
  457.                     if(is_null($plgPrice)){
  458.                         $plgPrice = new CustomerPrice();
  459.                         $plgPrice->setProductClass($ProductClass);
  460.                         $plgPrice->setCustomerRank($CustomerRank);
  461.                     }
  462.                     $plgPrice->setPrice($row[$CustomerRank->getName() . trans('customerrank.common.customer_price')]);
  463.                     $this->entityManager->persist($plgPrice);
  464.                 }else{
  465.                     if(isset($plgPrice))$this->entityManager->remove($plgPrice);
  466.                 }
  467.             }
  468.             if(isset($plgPrice))unset($plgPrice);
  469.         }
  470.     }
  471.     public function onTemplateMailmagazineHistoryCondition(TemplateEvent $event)
  472.     {
  473.         $parameters $event->getParameters();
  474.         $searchData $parameters['search_data'];
  475.         if(isset($searchData['customer_rank']) && is_array($searchData['customer_rank'])){
  476.             $val = [];
  477.             foreach($searchData['customer_rank'] as $id){
  478.                 $CustomerRank $this->customerRankRepository->find($id);
  479.                 if($CustomerRank){
  480.                     $val[] = $CustomerRank->getName();
  481.                 }
  482.             }
  483.             if(count($val) != 0){
  484.                 $searchData['customer_rank'] = implode(', '$val);
  485.             }else{
  486.                 $searchData['customer_rank'] = null;
  487.             }
  488.         }
  489.         $parameters['search_data'] = $searchData;
  490.         $event->setParameters($parameters);
  491.         $twig '@CustomerRank/admin/mailmagazine_history_condition_add.twig';
  492.         $event->addSnippet($twig);
  493.     }
  494.     public function rankCheckForFront()
  495.     {
  496.         $Customer $this->customerRankService->getLoginCustomer();
  497.         if(!is_null($Customer))$this->customerRankService->checkRank($Customer);
  498.     }
  499. }