app/Plugin/ProductDisplayRank4/Event.php line 25

Open in your IDE?
  1. <?php
  2. namespace Plugin\ProductDisplayRank4;
  3. use Doctrine\ORM\Event\LifecycleEventArgs;
  4. use Doctrine\ORM\Events;
  5. use Eccube\Entity\Product;
  6. use Eccube\Event\TemplateEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class Event implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @return array
  12.      */
  13.     public static function getSubscribedEvents()
  14.     {
  15.         return [
  16.             '@admin/Product/index.twig' => 'onAdminProductIndexTwig',
  17.             Events::preUpdate => 'postPersist',
  18.             Events::postPersist => 'postPersist',
  19.         ];
  20.     }
  21.     public function onAdminProductIndexTwig(TemplateEvent $event)
  22.     {
  23.         $event->addSnippet('@ProductDisplayRank4/admin/Product/index_js.twig');
  24.     }
  25.     public function postPersist(LifecycleEventArgs $args)
  26.     {
  27.         /* @var $Product Product */
  28.         $Product $args->getObject();
  29.         if ($Product instanceof Product) {
  30.             if (is_null($Product->getDisplayRank())) {
  31.                 $Product->setDisplayRank(0);
  32.             }
  33.         }
  34.     }
  35. }