local/modules/FairDelivery/EventListeners/OrderBeforePaymentListener.php line 47
<?phpnamespace FairDelivery\EventListeners;use FairDelivery\FairDelivery;use FairDelivery\Model\FairDelivery as ModelFairDelivery;use FairDelivery\Services\FairDeliveryService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\RequestStack;use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\Order\OrderEvent;use Thelia\Log\Tlog;/*** Class OrderBeforePaymentListener* @package FairDelivery* @author FrançoisCarfantan <f.carfantan@orange.fr>*/class OrderBeforePaymentListener implements EventSubscriberInterface{protected RequestStack $requestStack;protected FairDeliveryService $fdService;public function __construct(RequestStack $requestStack, FairDeliveryService $fdService){$this->requestStack = $requestStack;$this->fdService = $fdService;}protected function checkModule($id){return $id == FairDelivery::getModuleId();}/*** @return Request*/public function getRequest(){return $this->requestStack->getCurrentRequest();;}public function setDeliveryType(OrderEvent $orderEvent){if ($this->checkModule($orderEvent->getDeliveryModule())) {$request = $this->getRequest();$request->getSession()->set('fair_id',$request->get('fair-id'));}return ;}/*** @param OrderEvent $orderEvent* @throws \Propel\Runtime\Exception\PropelException*/public function saveFairDeliveryOrder(OrderEvent $orderEvent){if ($this->checkModule($orderEvent->getOrder()->getDeliveryModuleId())) {$request = $this->getRequest();$fairId = intval($request->getSession()->get('fair_id'));$orderId = $orderEvent->getOrder()->getId();$this->fdService->saveFairDelivery($fairId,$orderId);$request->getSession()->set('order_id',$orderId);}return;}public static function getSubscribedEvents(){return array(TheliaEvents::ORDER_SET_DELIVERY_MODULE => array('setDeliveryType', 64),TheliaEvents::ORDER_BEFORE_PAYMENT => array('saveFairDeliveryOrder', 256));}}