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

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryPlus4
  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\DeliveryPlus42\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->setDeliveryplusWeight($ProductClass->getDeliveryplusWeight());
  50.                 $CopyProductClass->setDeliveryplusSize($ProductClass->getDeliveryplusSize());
  51.                 $this->entityManager->persist($CopyProductClass);
  52.             }
  53.         }
  54.         $this->entityManager->flush();
  55.     }
  56.     public function onTemplateAdminProductEdit(TemplateEvent $event)
  57.     {
  58.         $twig '@DeliveryPlus42/admin/Product/product_weight_size.twig';
  59.         $event->addSnippet($twig);
  60.         $js '@DeliveryPlus42/admin/Product/product_weight_size.js';
  61.         $event->addAsset($js);
  62.     }
  63.     public function onTemplateAdminProductClassEdit(TemplateEvent $event)
  64.     {
  65.         $twig '@DeliveryPlus42/admin/Product/product_class_weight_size.twig';
  66.         $event->addSnippet($twig);
  67.         $js '@DeliveryPlus42/admin/Product/product_class_weight_size.js';
  68.         $event->addAsset($js);
  69.     }
  70. }