<?php
namespace App\EventListener;
use App\Entity\Addressing\Zone;
use App\Entity\Channel\Channel;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\EventDispatcher\Event;
class ShippingMethodListener
{
/** @var EntityManagerInterface */
protected EntityManagerInterface $em;
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em) {
$this->em = $em;
}
/**
* @param Event $event
* @return void
*/
public function onShippingMethodInitializeCreate(Event $event): void
{
$shippingMethod = $event->getSubject();
$shippingMethod->setZone(
$this->em->getRepository(Zone::class)->findOneBy([
'code' => 'france'
])
);
$shippingMethod->addChannel(
$this->em->getRepository(Channel::class)->findOneBy([
'name' => 'fntv'
])
);
}
}