From c85666b4d0ba7365c526e30685145558296914d1 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Mon, 17 Feb 2020 16:02:37 +0100 Subject: [PATCH 1/4] Prevent Same value for different contacts --- EventListener/EmailSubscriber.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EventListener/EmailSubscriber.php b/EventListener/EmailSubscriber.php index 85c7040..03712dd 100644 --- a/EventListener/EmailSubscriber.php +++ b/EventListener/EmailSubscriber.php @@ -36,8 +36,8 @@ public function __construct(TemplateProcessor $templateProcessor) public static function getSubscribedEvents() { return [ - EmailEvents::EMAIL_ON_SEND => ['onEmailGenerate', 0], - EmailEvents::EMAIL_ON_DISPLAY => ['onEmailGenerate', 0] + EmailEvents::EMAIL_ON_SEND => ['onEmailGenerate', 300], + EmailEvents::EMAIL_ON_DISPLAY => ['onEmailGenerate', 0], ]; } @@ -52,7 +52,7 @@ public static function getSubscribedEvents() public function onEmailGenerate(Events\EmailSendEvent $event) { $this->logger->info('onEmailGenerate MauticAdvancedTemplatesBundle\EmailSubscriber'); - $content = $event->getContent(); + $content = $event->getEmail()->getCustomHtml(); $content = $this->templateProcessor->processTemplate($content, $event->getLead()); $event->setContent($content); if ( empty( trim($event->getPlainText()) ) ) { From 306e4b6ad0454317c31b2f7fb953a294976ce95e Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Thu, 20 Feb 2020 11:31:35 +0100 Subject: [PATCH 2/4] Add support for subjects --- EventListener/EmailSubscriber.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/EventListener/EmailSubscriber.php b/EventListener/EmailSubscriber.php index 03712dd..a2ae0b7 100644 --- a/EventListener/EmailSubscriber.php +++ b/EventListener/EmailSubscriber.php @@ -52,8 +52,10 @@ public static function getSubscribedEvents() public function onEmailGenerate(Events\EmailSendEvent $event) { $this->logger->info('onEmailGenerate MauticAdvancedTemplatesBundle\EmailSubscriber'); - $content = $event->getEmail()->getCustomHtml(); - $content = $this->templateProcessor->processTemplate($content, $event->getLead()); + $subject = $this->templateProcessor->processTemplate($event->getEmail()->getSubject(), $event->getLead()); + $event->setSubject($subject); + + $content = $this->templateProcessor->processTemplate($event->getEmail()->getCustomHtml(), $event->getLead()); $event->setContent($content); if ( empty( trim($event->getPlainText()) ) ) { $event->setPlainText( (new PlainTextHelper($content))->getText() ); From 071a6fbeeafdf5ca61f5386a947428389f940fe9 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Fri, 21 Feb 2020 11:52:27 +0100 Subject: [PATCH 3/4] Fix send custom email action --- EventListener/EmailSubscriber.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/EventListener/EmailSubscriber.php b/EventListener/EmailSubscriber.php index a2ae0b7..71d9d11 100644 --- a/EventListener/EmailSubscriber.php +++ b/EventListener/EmailSubscriber.php @@ -52,11 +52,18 @@ public static function getSubscribedEvents() public function onEmailGenerate(Events\EmailSendEvent $event) { $this->logger->info('onEmailGenerate MauticAdvancedTemplatesBundle\EmailSubscriber'); - $subject = $this->templateProcessor->processTemplate($event->getEmail()->getSubject(), $event->getLead()); - $event->setSubject($subject); + if ($event->getEmail()) { + $subject = $this->templateProcessor->processTemplate($event->getEmail()->getSubject(), $event->getLead()); + $event->setSubject($subject); + + $content = $this->templateProcessor->processTemplate($event->getEmail()->getCustomHtml(), $event->getLead()); + $event->setContent($content); + }else{ + $content = $this->templateProcessor->processTemplate($event->getContent(), $event->getLead()); + $event->setContent($content); + } + - $content = $this->templateProcessor->processTemplate($event->getEmail()->getCustomHtml(), $event->getLead()); - $event->setContent($content); if ( empty( trim($event->getPlainText()) ) ) { $event->setPlainText( (new PlainTextHelper($content))->getText() ); } From c3b5cb545afc7ee39f172882ea17437b753871e6 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Fri, 21 Feb 2020 16:09:50 +0100 Subject: [PATCH 4/4] Fix subject for Send custom email --- EventListener/EmailSubscriber.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/EventListener/EmailSubscriber.php b/EventListener/EmailSubscriber.php index 71d9d11..66e01a7 100644 --- a/EventListener/EmailSubscriber.php +++ b/EventListener/EmailSubscriber.php @@ -52,17 +52,21 @@ public static function getSubscribedEvents() public function onEmailGenerate(Events\EmailSendEvent $event) { $this->logger->info('onEmailGenerate MauticAdvancedTemplatesBundle\EmailSubscriber'); - if ($event->getEmail()) { - $subject = $this->templateProcessor->processTemplate($event->getEmail()->getSubject(), $event->getLead()); - $event->setSubject($subject); - $content = $this->templateProcessor->processTemplate($event->getEmail()->getCustomHtml(), $event->getLead()); - $event->setContent($content); + if ($event->getEmail()) { + $subject = $event->getEmail()->getSubject(); + $content = $event->getEmail()->getCustomHtml(); }else{ - $content = $this->templateProcessor->processTemplate($event->getContent(), $event->getLead()); - $event->setContent($content); + $subject = $event->getSubject(); + $content = $event->getContent(); } + $subject = $this->templateProcessor->processTemplate($subject, $event->getLead()); + $event->setSubject($subject); + + $content = $this->templateProcessor->processTemplate($content, $event->getLead()); + $event->setContent($content); + if ( empty( trim($event->getPlainText()) ) ) { $event->setPlainText( (new PlainTextHelper($content))->getText() );