diff --git a/src/Model/Administrator/Mail/ResetPasswordMailFacade.php b/src/Model/Administrator/Mail/ResetPasswordMailFacade.php index b5d283cafd..9a3517519a 100644 --- a/src/Model/Administrator/Mail/ResetPasswordMailFacade.php +++ b/src/Model/Administrator/Mail/ResetPasswordMailFacade.php @@ -32,7 +32,7 @@ public function __construct( */ public function sendMail(Administrator $administrator) { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( ResetPasswordMail::MAIL_TEMPLATE_NAME, $this->domain->getId(), ); diff --git a/src/Model/Administrator/Mail/TwoFactorAuthenticationMailFacade.php b/src/Model/Administrator/Mail/TwoFactorAuthenticationMailFacade.php index 1f16cb0bce..649d13317f 100644 --- a/src/Model/Administrator/Mail/TwoFactorAuthenticationMailFacade.php +++ b/src/Model/Administrator/Mail/TwoFactorAuthenticationMailFacade.php @@ -32,7 +32,7 @@ public function __construct( */ public function sendAuthCode(TwoFactorInterface $administrator): void { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( TwoFactorAuthenticationMail::TWO_FACTOR_AUTHENTICATION_CODE, $this->domain->getId(), ); diff --git a/src/Model/Complaint/Mail/ComplaintMailFacade.php b/src/Model/Complaint/Mail/ComplaintMailFacade.php index c3de6747fd..cdc9ed106c 100644 --- a/src/Model/Complaint/Mail/ComplaintMailFacade.php +++ b/src/Model/Complaint/Mail/ComplaintMailFacade.php @@ -50,7 +50,7 @@ public function getMailTemplateByStatusAndDomainId(ComplaintStatus $complaintSta { $templateName = ComplaintMail::getMailTemplateNameByStatus($complaintStatus); - return $this->mailTemplateFacade->get($templateName, $domainId); + return $this->mailTemplateFacade->getWrappedWithGrapesJsBody($templateName, $domainId); } /** diff --git a/src/Model/Customer/Mail/CustomerMailFacade.php b/src/Model/Customer/Mail/CustomerMailFacade.php index 764ae018ec..3ede23703f 100644 --- a/src/Model/Customer/Mail/CustomerMailFacade.php +++ b/src/Model/Customer/Mail/CustomerMailFacade.php @@ -34,7 +34,7 @@ public function __construct( */ public function sendRegistrationMail(CustomerUser $customerUser): void { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( MailTemplate::REGISTRATION_CONFIRM_NAME, $customerUser->getDomainId(), ); @@ -46,7 +46,7 @@ public function sendRegistrationMail(CustomerUser $customerUser): void */ public function sendActivationMail(CustomerUser $customerUser): void { - $mailTemplate = $this->mailTemplateFacade->get(CustomerActivationMail::CUSTOMER_ACTIVATION_NAME, $customerUser->getDomainId()); + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody(CustomerActivationMail::CUSTOMER_ACTIVATION_NAME, $customerUser->getDomainId()); $this->sendActivationMailTemplate($mailTemplate, $customerUser); } diff --git a/src/Model/Customer/Mail/ResetPasswordMailFacade.php b/src/Model/Customer/Mail/ResetPasswordMailFacade.php index 4fd4696761..5899aca424 100644 --- a/src/Model/Customer/Mail/ResetPasswordMailFacade.php +++ b/src/Model/Customer/Mail/ResetPasswordMailFacade.php @@ -32,7 +32,7 @@ public function __construct( */ public function sendMail(CustomerUser $customerUser) { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( MailTemplate::RESET_PASSWORD_NAME, $customerUser->getDomainId(), ); diff --git a/src/Model/Inquiry/Mail/InquiryMailFacade.php b/src/Model/Inquiry/Mail/InquiryMailFacade.php index 63dc5cefd0..3154309d94 100644 --- a/src/Model/Inquiry/Mail/InquiryMailFacade.php +++ b/src/Model/Inquiry/Mail/InquiryMailFacade.php @@ -32,10 +32,10 @@ public function __construct( */ public function sendMail(Inquiry $inquiry): void { - $mailTemplate = $this->mailTemplateFacade->get(InquiryMail::ADMIN_MAIL_TEMPLATE_NAME, $inquiry->getDomainId()); + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody(InquiryMail::ADMIN_MAIL_TEMPLATE_NAME, $inquiry->getDomainId()); $this->sendMailTemplate($mailTemplate, $inquiry); - $mailTemplate = $this->mailTemplateFacade->get(InquiryMail::CUSTOMER_MAIL_TEMPLATE_NAME, $inquiry->getDomainId()); + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody(InquiryMail::CUSTOMER_MAIL_TEMPLATE_NAME, $inquiry->getDomainId()); $this->sendMailTemplate($mailTemplate, $inquiry); } diff --git a/src/Model/Mail/MailTemplateFacade.php b/src/Model/Mail/MailTemplateFacade.php index 595454c7f7..c6bf71fc12 100644 --- a/src/Model/Mail/MailTemplateFacade.php +++ b/src/Model/Mail/MailTemplateFacade.php @@ -40,16 +40,11 @@ public function __construct( * @param int $domainId * @return \Shopsys\FrameworkBundle\Model\Mail\MailTemplate */ - public function get($templateName, $domainId) + public function getWrappedWithGrapesJsBody(string $templateName, int $domainId): MailTemplate { $mailTemplate = $this->mailTemplateRepository->getByNameAndDomainId($templateName, $domainId); - if ($mailTemplate !== null) { - $mailTemplate->setBody($this->mailTemplateBuilder->getMailTemplateWithContent($domainId, $mailTemplate->getBody())); - $this->em->detach($mailTemplate); - } - - return $mailTemplate; + return $this->getTemplateWrappedWithGrapesBody($mailTemplate); } /** @@ -115,4 +110,16 @@ public function existsTemplateWithEnabledSendingHavingEmptyBodyOrSubject() { return $this->mailTemplateRepository->existsTemplateWithEnabledSendingHavingEmptyBodyOrSubject(); } + + /** + * @param \Shopsys\FrameworkBundle\Model\Mail\MailTemplate $mailTemplate + * @return \Shopsys\FrameworkBundle\Model\Mail\MailTemplate + */ + public function getTemplateWrappedWithGrapesBody(MailTemplate $mailTemplate): MailTemplate + { + $mailTemplate->setBody($this->mailTemplateBuilder->getMailTemplateWithContent($mailTemplate->getDomainId(), $mailTemplate->getBody())); + $this->em->detach($mailTemplate); // detach from entity manager to avoid accidental persisting the changes to the database + + return $mailTemplate; + } } diff --git a/src/Model/Mail/MailTemplateSender/MailTemplateSenderFacade.php b/src/Model/Mail/MailTemplateSender/MailTemplateSenderFacade.php index 7c366f70e0..9ac9e77cd5 100644 --- a/src/Model/Mail/MailTemplateSender/MailTemplateSenderFacade.php +++ b/src/Model/Mail/MailTemplateSender/MailTemplateSenderFacade.php @@ -5,6 +5,7 @@ namespace Shopsys\FrameworkBundle\Model\Mail\MailTemplateSender; use Shopsys\FrameworkBundle\Model\Mail\MailTemplate; +use Shopsys\FrameworkBundle\Model\Mail\MailTemplateFacade; use Shopsys\FrameworkBundle\Model\Mail\MailTemplateSender\Exception\NoSenderForMailTemplateException; use Traversable; @@ -12,9 +13,11 @@ class MailTemplateSenderFacade { /** * @param \Traversable $mailTemplateSenders + * @param \Shopsys\FrameworkBundle\Model\Mail\MailTemplateFacade $mailTemplateFacade */ public function __construct( protected readonly Traversable $mailTemplateSenders, + protected readonly MailTemplateFacade $mailTemplateFacade, ) { } @@ -34,7 +37,11 @@ public function getFormLabelForEntityIdentifier(MailTemplate $mailTemplate): ?st */ public function sendMail(MailTemplate $mailTemplate, string $mailTo, ?int $entityId): void { - $this->getTemplateSender($mailTemplate)->sendTemplate($mailTemplate, $mailTo, $entityId); + $this->getTemplateSender($mailTemplate)->sendTemplate( + $this->mailTemplateFacade->getTemplateWrappedWithGrapesBody($mailTemplate), + $mailTo, + $entityId, + ); } /** diff --git a/src/Model/Order/Mail/OrderMailFacade.php b/src/Model/Order/Mail/OrderMailFacade.php index 23c3916848..ce53d298d1 100644 --- a/src/Model/Order/Mail/OrderMailFacade.php +++ b/src/Model/Order/Mail/OrderMailFacade.php @@ -50,7 +50,7 @@ public function getMailTemplateByStatusAndDomainId(OrderStatus $orderStatus, $do { $templateName = OrderMail::getMailTemplateNameByStatus($orderStatus); - return $this->mailTemplateFacade->get($templateName, $domainId); + return $this->mailTemplateFacade->getWrappedWithGrapesJsBody($templateName, $domainId); } /** diff --git a/src/Model/PersonalData/Mail/PersonalDataAccessMailFacade.php b/src/Model/PersonalData/Mail/PersonalDataAccessMailFacade.php index db5e08ba71..8f8125634d 100644 --- a/src/Model/PersonalData/Mail/PersonalDataAccessMailFacade.php +++ b/src/Model/PersonalData/Mail/PersonalDataAccessMailFacade.php @@ -35,12 +35,12 @@ public function __construct( public function sendMail(PersonalDataAccessRequest $personalDataAccessRequest): void { if ($personalDataAccessRequest->getType() === PersonalDataAccessRequest::TYPE_DISPLAY) { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( MailTemplate::PERSONAL_DATA_ACCESS_NAME, $personalDataAccessRequest->getDomainId(), ); } else { - $mailTemplate = $this->mailTemplateFacade->get( + $mailTemplate = $this->mailTemplateFacade->getWrappedWithGrapesJsBody( MailTemplate::PERSONAL_DATA_EXPORT_NAME, $personalDataAccessRequest->getDomainId(), );