app/Plugin/EccubePaymentLite4/EventListener/EventSubscriber/Admin/Product/AddRegularCycleFormToProductClassType.php line 31

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite4\EventListener\EventSubscriber\Admin\Product;
  3. use Eccube\Entity\Master\SaleType;
  4. use Eccube\Entity\Product;
  5. use Eccube\Event\TemplateEvent;
  6. use Eccube\Repository\Master\SaleTypeRepository;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class AddRegularCycleFormToProductClassType implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var SaleTypeRepository
  12.      */
  13.     private $saleTypeRepository;
  14.     public function __construct(
  15.         SaleTypeRepository $saleTypeRepository
  16.     ) {
  17.         $this->saleTypeRepository $saleTypeRepository;
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             '@admin/Product/product.twig' => 'product',
  23.         ];
  24.     }
  25.     public function product(TemplateEvent $event)
  26.     {
  27.         /** @var Product $Product */
  28.         $Product $event->getParameter('Product');
  29.         if ($Product->getProductClasses()->count() > 1) {
  30.             return;
  31.         }
  32.         /** @var SaleType $SaleType */
  33.         $SaleType $this->saleTypeRepository->findOneBy([
  34.             'name' => '定期商品',
  35.         ]);
  36.         if (is_null($SaleType)) {
  37.             return;
  38.         }
  39.         $event->setParameter('regularSaleTypeId'$SaleType->getId());
  40.         $event->addSnippet('@EccubePaymentLite4/admin/Product/regular_cycle_form.twig');
  41.     }
  42. }