From 8904051df07bd4a93d7f118511af970bf60bf909 Mon Sep 17 00:00:00 2001 From: Da Silva Mendonca Thomas Date: Thu, 21 Sep 2023 10:58:20 +0200 Subject: [PATCH 1/2] add notification event for update order status --- EventListeners/SendConfirmationEmail.php | 37 +++++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/EventListeners/SendConfirmationEmail.php b/EventListeners/SendConfirmationEmail.php index 8749812..b24358c 100644 --- a/EventListeners/SendConfirmationEmail.php +++ b/EventListeners/SendConfirmationEmail.php @@ -13,13 +13,16 @@ namespace CmCIC\EventListeners; use CmCIC\CmCIC; +use Exception; +use Propel\Runtime\Exception\PropelException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Action\BaseAction; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Log\Tlog; -class SendConfirmationEmail implements EventSubscriberInterface +class SendConfirmationEmail extends BaseAction implements EventSubscriberInterface { protected EventDispatcherInterface $dispatcher; @@ -31,9 +34,9 @@ public function __construct(EventDispatcherInterface $dispatcher) /** * @param OrderEvent $event * - * @throws \Exception if the message cannot be loaded. + * @throws Exception if the message cannot be loaded. */ - public function sendConfirmationEmail(OrderEvent $event) + public function sendConfirmationEmail(OrderEvent $event): void { if (CmCIC::getConfigValue('send_confirmation_message_only_if_paid')) { // We send the order confirmation email only if the order is paid @@ -46,26 +49,44 @@ public function sendConfirmationEmail(OrderEvent $event) /** * @param OrderEvent $event - * @throws \Propel\Runtime\Exception\PropelException + * + * @throws Exception if the message cannot be loaded. + */ + public function sendNotificationEmail(OrderEvent $event): void + { + if (CmCIC::getConfigValue('send_confirmation_message_only_if_paid')) { + // We send the order notification email only if the order is paid + $order = $event->getOrder(); + if (!$order->isPaid() && $order->getPaymentModuleId() == CmCIC::getModuleId()) { + $event->stopPropagation(); + } + } + } + + /** + * @param OrderEvent $event + * @throws PropelException */ - public function updateStatus(OrderEvent $event) + public function updateStatus(OrderEvent $event): void { $order = $event->getOrder(); if ($order->isPaid() && $order->getPaymentModuleId() == CmCIC::getModuleId()) { // Send confirmation email if required. if (CmCIC::getConfigValue('send_confirmation_message_only_if_paid')) { $this->dispatcher->dispatch($event, TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL); + $this->dispatcher->dispatch($event, TheliaEvents::ORDER_SEND_NOTIFICATION_EMAIL); } Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail()); } } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return array( - TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 100), - TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL => array("sendConfirmationEmail", 129) + TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128), + TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL => array("sendConfirmationEmail", 129), + TheliaEvents::ORDER_SEND_NOTIFICATION_EMAIL => array("sendNotificationEmail", 129) ); } } From 1992fdcb3c39db181d12faf49eb6843de15bc735 Mon Sep 17 00:00:00 2001 From: Da Silva Mendonca Thomas Date: Thu, 21 Sep 2023 11:07:02 +0200 Subject: [PATCH 2/2] update version --- Config/module.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/module.xml b/Config/module.xml index 06b7bbc..96a6f9f 100755 --- a/Config/module.xml +++ b/Config/module.xml @@ -14,7 +14,7 @@ fr_FR en_US - 2.0.1 + 2.0.2 Thelia