app/Plugin/UnderLimitQuantityDx/EventSubscriber/AdminProductEventSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/10/24
  5.  */
  6. namespace Plugin\UnderLimitQuantityDx\EventSubscriber;
  7. use Eccube\Entity\Product;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\UnderLimitQuantityDx\Service\TwigRenderService\EventSubscriber\TwigRenderTrait;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class AdminProductEventSubscriber implements EventSubscriberInterface
  12. {
  13.     use TwigRenderTrait;
  14.     /**
  15.      * 商品管理
  16.      *
  17.      * @param TemplateEvent $event
  18.      */
  19.     public function onTemplateProductProduct(TemplateEvent $event)
  20.     {
  21.         /** @var Product $Product */
  22.         $Product $event->getParameter('Product');
  23.         if ($Product->hasProductClass()) {
  24.             // 規格あり商品
  25.         } else {
  26.             // 規格なし商品
  27.             $this->initRenderService($event);
  28.             $this->createInsertBuilder()
  29.                 ->find('#basicConfig > div')
  30.                 ->setTargetId('under_quantity_form')
  31.                 ->eq(0)
  32.                 ->setInsertModeAppend();
  33.             $this->addTwigRenderSnippet('@UnderLimitQuantityDx/admin/Product/default/product_ex.twig');
  34.         }
  35.     }
  36.     /**
  37.      * 商品規格登録
  38.      *
  39.      * @param TemplateEvent $event
  40.      * @throws \Twig_Error_Loader
  41.      * @throws \Twig_Error_Runtime
  42.      * @throws \Twig_Error_Syntax
  43.      */
  44.     public function onTemplateProductClassEdit(TemplateEvent $event)
  45.     {
  46.         $this->initRenderService($event);
  47.         $this->twigRenderHelper->addProductClassEditArea(
  48.             $event,
  49.             '@UnderLimitQuantityDx/admin/Product/class/under_limit_quantity_title.twig',
  50.             '@UnderLimitQuantityDx/admin/Product/class/under_limit_quantity_body.twig',
  51.             'UnderQuantity',
  52.             "最低購入数設定"
  53.         );
  54.         $this->addTwigRenderSnippetSlow();
  55.     }
  56.     /**
  57.      * Returns an array of event names this subscriber wants to listen to.
  58.      *
  59.      * The array keys are event names and the value can be:
  60.      *
  61.      *  * The method name to call (priority defaults to 0)
  62.      *  * An array composed of the method name to call and the priority
  63.      *  * An array of arrays composed of the method names to call and respective
  64.      *    priorities, or 0 if unset
  65.      *
  66.      * For instance:
  67.      *
  68.      *  * ['eventName' => 'methodName']
  69.      *  * ['eventName' => ['methodName', $priority]]
  70.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  71.      *
  72.      * @return array The event names to listen to
  73.      */
  74.     public static function getSubscribedEvents()
  75.     {
  76.         return [
  77.             // 商品詳細
  78.             '@admin/Product/product.twig' => ['onTemplateProductProduct'],
  79.             // 規格登録
  80.             '@admin/Product/product_class.twig' => ['onTemplateProductClassEdit', -10],
  81.         ];
  82.     }
  83. }