44
55namespace Codebarista ;
66
7- use Doctrine \DBAL \Connection ;
87use Psr \Log \LoggerInterface ;
98use Shopware \Core \Content \Mail \Service \AbstractMailService ;
9+ use Shopware \Core \Content \MailTemplate \MailTemplateEntity ;
10+ use Shopware \Core \Framework \DataAbstractionLayer \EntityRepository ;
11+ use Shopware \Core \Framework \DataAbstractionLayer \Search \Criteria ;
12+ use Shopware \Core \Framework \DataAbstractionLayer \Search \Filter \EqualsFilter ;
1013use Shopware \Core \Framework \RateLimiter \Exception \RateLimitExceededException ;
1114use Shopware \Core \Framework \RateLimiter \RateLimiter ;
1215use Shopware \Core \Framework \Validation \DataBag \DataBag ;
@@ -33,6 +36,7 @@ class RevocationButtonController extends StorefrontController
3336 private RevocationRequestFormValidationFactory $ validationFactory ;
3437 private RateLimiter $ rateLimiter ;
3538 private GenericPageLoaderInterface $ genericPageLoader ;
39+ private EntityRepository $ mailTemplateRepository ;
3640
3741 public function __construct (
3842 LoggerInterface $ logger ,
@@ -41,7 +45,8 @@ public function __construct(
4145 DataValidator $ dataValidator ,
4246 RevocationRequestFormValidationFactory $ validationFactory ,
4347 RateLimiter $ rateLimiter ,
44- GenericPageLoaderInterface $ genericPageLoader
48+ GenericPageLoaderInterface $ genericPageLoader ,
49+ EntityRepository $ mailTemplateRepository
4550 ) {
4651 $ this ->logger = $ logger ;
4752 $ this ->systemConfig = $ systemConfig ;
@@ -50,6 +55,7 @@ public function __construct(
5055 $ this ->validationFactory = $ validationFactory ;
5156 $ this ->rateLimiter = $ rateLimiter ;
5257 $ this ->genericPageLoader = $ genericPageLoader ;
58+ $ this ->mailTemplateRepository = $ mailTemplateRepository ;
5359 }
5460
5561 /**
@@ -197,43 +203,21 @@ private function sendMail(
197203 */
198204 private function loadTemplate (string $ technicalName , SalesChannelContext $ context ): array
199205 {
200- /** @var Connection */
201- $ connection = $ this ->container ->get ('Doctrine \\DBAL \\Connection ' );
206+ $ criteria = new Criteria ();
207+ $ criteria ->addFilter (new EqualsFilter ('mailTemplateType.technicalName ' , $ technicalName ));
208+ $ criteria ->setLimit (1 );
202209
203- $ row = $ connection ->fetchAssociative (
204- 'SELECT mtt.subject, mtt.content_html, mtt.content_plain
205- FROM mail_template mt
206- INNER JOIN mail_template_type mty ON mty.id = mt.mail_template_type_id
207- INNER JOIN mail_template_translation mtt ON mtt.mail_template_id = mt.id
208- WHERE mty.technical_name = :name
209- AND mtt.language_id = :lang
210- LIMIT 1 ' ,
211- [
212- 'name ' => $ technicalName ,
213- 'lang ' => \Shopware \Core \Framework \Uuid \Uuid::fromHexToBytes ($ context ->getContext ()->getLanguageId ()),
214- ]
215- );
216-
217- if ($ row === false ) {
218- $ row = $ connection ->fetchAssociative (
219- 'SELECT mtt.subject, mtt.content_html, mtt.content_plain
220- FROM mail_template mt
221- INNER JOIN mail_template_type mty ON mty.id = mt.mail_template_type_id
222- INNER JOIN mail_template_translation mtt ON mtt.mail_template_id = mt.id
223- WHERE mty.technical_name = :name
224- LIMIT 1 ' ,
225- ['name ' => $ technicalName ]
226- );
227- }
210+ /** @var MailTemplateEntity|null $template */
211+ $ template = $ this ->mailTemplateRepository ->search ($ criteria , $ context ->getContext ())->first ();
228212
229- if ($ row === false ) {
213+ if ($ template === null ) {
230214 throw new \RuntimeException (sprintf ('Mail template "%s" not found. ' , $ technicalName ));
231215 }
232216
233217 return [
234- 'subject ' => self ::asTrimmedString ($ row [ ' subject ' ] ),
235- 'content_html ' => self ::asTrimmedString ($ row [ ' content_html ' ] ),
236- 'content_plain ' => self ::asTrimmedString ($ row [ ' content_plain ' ] ),
218+ 'subject ' => self ::asTrimmedString ($ template -> getSubject () ),
219+ 'content_html ' => self ::asTrimmedString ($ template -> getContentHtml () ),
220+ 'content_plain ' => self ::asTrimmedString ($ template -> getContentPlain () ),
237221 ];
238222 }
239223
0 commit comments