local/modules/Cheque/Listener/SendPaymentConfirmationEmail.php line 44

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Cheque\Listener;
  12. use Cheque\Cheque;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Thelia\Action\BaseAction;
  15. use Thelia\Core\Event\Order\OrderEvent;
  16. use Thelia\Core\Event\TheliaEvents;
  17. use Thelia\Mailer\MailerFactory;
  18. /**
  19.  * Class SendEMail.
  20.  *
  21.  * @author Thelia <info@thelia.net>
  22.  */
  23. class SendPaymentConfirmationEmail extends BaseAction implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @var MailerFactory
  27.      */
  28.     protected $mailer;
  29.     public function __construct(MailerFactory $mailer)
  30.     {
  31.         $this->mailer $mailer;
  32.     }
  33.     /**
  34.      * @param orderEvent $event
  35.      *
  36.      * Check if we're the payment module, and send the payment confirmation email to the customer if it's the case
  37.      */
  38.     public function sendConfirmationEmail(OrderEvent $event): void
  39.     {
  40.         if ($event->getOrder()->getPaymentModuleId() === Cheque::getModuleId()) {
  41.             if ($event->getOrder()->isPaid()) {
  42.                 $order $event->getOrder();
  43.                 $this->mailer->sendEmailToCustomer(
  44.                     'order_confirmation_cheque',
  45.                     $order->getCustomer(),
  46.                     [
  47.                         'order_id' => $order->getId(),
  48.                         'order_ref' => $order->getRef(),
  49.                     ]
  50.                 );
  51.             }
  52.         }
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      */
  57.     public static function getSubscribedEvents()
  58.     {
  59.         return [
  60.             TheliaEvents::ORDER_UPDATE_STATUS => ['sendConfirmationEmail'128],
  61.         ];
  62.     }
  63. }