src/EventListener/ShippingMethodListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Addressing\Zone;
  4. use App\Entity\Channel\Channel;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Contracts\EventDispatcher\Event;
  7. class ShippingMethodListener
  8. {
  9.     /** @var EntityManagerInterface */
  10.     protected EntityManagerInterface $em;
  11.     /**
  12.      * @param EntityManagerInterface $em
  13.      */
  14.     public function __construct(EntityManagerInterface $em) {
  15.         $this->em $em;
  16.     }
  17.     /**
  18.      * @param Event $event
  19.      * @return void
  20.      */
  21.     public function onShippingMethodInitializeCreate(Event $event): void
  22.     {
  23.         $shippingMethod $event->getSubject();
  24.         $shippingMethod->setZone(
  25.             $this->em->getRepository(Zone::class)->findOneBy([
  26.                 'code' => 'france'
  27.             ])
  28.         );
  29.         $shippingMethod->addChannel(
  30.             $this->em->getRepository(Channel::class)->findOneBy([
  31.                 'name' => 'fntv'
  32.             ])
  33.         );
  34.     }
  35. }