app/Plugin/DeliveryDate42/Event/AdminProductEvent.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryDate4
  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\DeliveryDate42\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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. class AdminProductEvent implements EventSubscriberInterface
  19. {
  20.     private $entityManager;
  21.     private $productClassRepository;
  22.     public function __construct(
  23.             EntityManagerInterface $entityManager,
  24.             ProductClassRepository $productClassRepository
  25.             )
  26.     {
  27.         $this->entityManager $entityManager;
  28.         $this->productClassRepository $productClassRepository;
  29.     }
  30.     /**
  31.      * @return array
  32.      */
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE => 'hookAdminProductCopyComplete',
  37.             '@admin/Product/product.twig' => 'onTemplateAdminProductEdit',
  38.             '@admin/Product/product_class.twig' => 'onTemplateAdminProductClassEdit',
  39.         ];
  40.     }
  41.     public function hookAdminProductCopyComplete(EventArgs $event)
  42.     {
  43.         $Product $event->getArgument('Product');
  44.         $CopyProduct $event->getArgument('CopyProduct');
  45.         $orgProductClasses $Product->getProductClasses();
  46.         foreach ($orgProductClasses as $ProductClass) {
  47.             $CopyProductClass $this->productClassRepository->findOneBy(['Product'=> $CopyProduct'ClassCategory1' => $ProductClass->getClassCategory1(), 'ClassCategory2' => $ProductClass->getClassCategory2()]);
  48.             if($CopyProductClass){
  49.                 $CopyProductClass->setDeliveryDateDays($ProductClass->getDeliveryDateDays());
  50.                 $this->entityManager->persist($CopyProductClass);
  51.             }
  52.         }
  53.         $this->entityManager->flush();
  54.     }
  55.     public function onTemplateAdminProductEdit(TemplateEvent $event)
  56.     {
  57.         $twig '@DeliveryDate42/admin/Product/product_days.twig';
  58.         $event->addSnippet($twig);
  59.         $js '@DeliveryDate42/admin/Product/product_days.js';
  60.         $event->addAsset($js);
  61.     }
  62.     public function onTemplateAdminProductClassEdit(TemplateEvent $event)
  63.     {
  64.         $twig '@DeliveryDate42/admin/Product/product_class_days.twig';
  65.         $event->addSnippet($twig);
  66.         $js '@DeliveryDate42/admin/Product/product_class_days.js';
  67.         $event->addAsset($js);
  68.     }
  69. }