src/EventListener/ConfirmationMailListener.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Services\MailService;
  4. use Pimcore\Event\Model\Ecommerce\SendConfirmationMailEvent;
  5. use Pimcore\Log\ApplicationLogger;
  6. class ConfirmationMailListener
  7. {
  8.     public function __construct(protected MailService $mailService, protected ApplicationLogger $applicationLogger)
  9.     {
  10.     }
  11.     public function onSendConfirmationMail(SendConfirmationMailEvent $e)
  12.     {
  13.         $e->setSkipDefaultBehaviour(true);
  14.         $order $e->getOrder();
  15.         try {
  16.             if ($this->mailService->sendConfirmationMail($order, ['to' => $order->getCustomerEMail()])) {
  17.                 $order->setProperty('confirmationEmailSent''bool'true);
  18.                 $order->save();
  19.             }
  20.         } catch (\Throwable $exception) {
  21.             $this->applicationLogger->error('could not send Confirmation Mail: ' $exception, ['component' => 'ConfirmationMailListener''relatedObject' => $order]);
  22.         }
  23.     }
  24. }