app/Plugin/DeliveryCool42/Event/AdminProductEvent.php line 48

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryCool4
  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\DeliveryCool42\Event;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Eccube\Event\TemplateEvent;
  16. use Eccube\Repository\ProductClassRepository;
  17. use Plugin\DeliveryCool42\Service\DeliveryCoolService;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. class AdminProductEvent implements EventSubscriberInterface
  20. {
  21.     private $entityManager;
  22.     private $productClassRepository;
  23.     public function __construct(
  24.             EntityManagerInterface $entityManager,
  25.             ProductClassRepository $productClassRepository
  26.             )
  27.     {
  28.         $this->entityManager $entityManager;
  29.         $this->productClassRepository $productClassRepository;
  30.     }
  31.     /**
  32.      * @return array
  33.      */
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             '@admin/Product/product_class.twig' => 'onTemplateAdminProductClassEdit',
  38.             EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE => 'hookAdminProductCopyComplete',
  39.             EccubeEvents::ADMIN_PRODUCT_CSV_EXPORT => 'hookAdminProductCsvExport',
  40.         ];
  41.     }
  42.     public function onTemplateAdminProductClassEdit(TemplateEvent $event)
  43.     {
  44.         $twig '@DeliveryCool42/admin/Product/product_class_js.twig';
  45.         $event->addSnippet($twig);
  46.     }
  47.     public function hookAdminProductCopyComplete(EventArgs $event)
  48.     {
  49.         $Product $event->getArgument('Product');
  50.         $CopyProduct $event->getArgument('CopyProduct');
  51.         $orgProductClasses $Product->getProductClasses();
  52.         foreach ($orgProductClasses as $ProductClass) {
  53.             $CopyProductClass $this->productClassRepository->findOneBy(['Product'=> $CopyProduct'ClassCategory1' => $ProductClass->getClassCategory1(), 'ClassCategory2' => $ProductClass->getClassCategory2()]);
  54.             if($CopyProductClass){
  55.                 $CopyProductClass->setDeliveryCoolType($ProductClass->getDeliveryCoolType());
  56.                 $this->entityManager->persist($CopyProductClass);
  57.             }
  58.         }
  59.         $this->entityManager->flush();
  60.     }
  61.     public function hookAdminProductCsvExport(EventArgs $event)
  62.     {
  63.         $arrTYPE = [];
  64.         $arrTYPE[DeliveryCoolService::REGULAR_PRODUCT] = trans('deliverycool.const.product.temptype.normal_not_all');
  65.         $arrTYPE[DeliveryCoolService::REGULAR_INC_COOL_PRODUCT] = trans('deliverycool.const.product.temptype.normal_inc_cool');
  66.         $arrTYPE[DeliveryCoolService::REGULAR_INC_ALL_PRODUCT] = trans('deliverycool.const.product.temptype.normal_inc_all');
  67.         $arrTYPE[DeliveryCoolService::COOL_PRODUCT] = trans('deliverycool.const.product.temptype.cool_not_all');
  68.         $arrTYPE[DeliveryCoolService::COOL_INC_COLD_PRODUCT] = trans('deliverycool.const.product.temptype.cool_inc_cold');
  69.         $arrTYPE[DeliveryCoolService::COLD_PRODUCT] = trans('deliverycool.const.product.temptype.cold');
  70.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  71.         if ($ExportCsvRow->isDataNull()) {
  72.             $ProductClass $event->getArgument('ProductClass');
  73.             $Csv $event->getArgument('Csv');
  74.             $csvEntityName str_replace('\\\\''\\'$Csv->getEntityName());
  75.             if($csvEntityName == 'Eccube\Entity\ProductClass' && $Csv->getFieldName() == 'delivery_cool_disp_name'){
  76.                 $type $ProductClass->getDeliveryCoolType();
  77.                 if(is_null($type))return;
  78.                 $data $arrTYPE[$type];
  79.                 $ExportCsvRow->setData($data);
  80.             }
  81.         }
  82.     }
  83. }