1919use Shopware \Core \Framework \Validation \DataBag \DataBag ;
2020use Shopware \Core \System \Language \LanguageCollection ;
2121use Shopware \Core \System \Language \LanguageEntity ;
22+ use Shopware \Core \System \SalesChannel \SalesChannelCollection ;
23+ use Shopware \Core \System \SalesChannel \SalesChannelEntity ;
24+ use Shopware \Core \System \SystemConfig \SystemConfigService ;
2225use Symfony \Component \DependencyInjection \Attribute \Autowire ;
2326use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
2427use Symfony \Component \HttpFoundation \ParameterBag ;
@@ -28,13 +31,16 @@ class FlowSubscriber implements EventSubscriberInterface
2831 /**
2932 * @param EntityRepository<MailTemplateTypeCollection> $mailTemplateTypeRepository
3033 * @param EntityRepository<LanguageCollection> $languageRepository
34+ * @param EntityRepository<SalesChannelCollection> $salesChannelRepository
3135 */
3236 public function __construct (
3337 private readonly EntityRepository $ mailTemplateTypeRepository ,
3438 private readonly MailFinderServiceInterface $ mailFinderService ,
3539 #[Autowire(service: Translator::class)]
3640 private readonly AbstractTranslator $ translator ,
3741 private readonly EntityRepository $ languageRepository ,
42+ private readonly SystemConfigService $ systemConfigService ,
43+ private readonly EntityRepository $ salesChannelRepository ,
3844 ) {}
3945
4046 public static function getSubscribedEvents (): array
@@ -77,6 +83,17 @@ private function sendMail(DataBag $dataBag, string $mailTemplateTypeId, Context
7783 }
7884
7985 if ($ subject ) {
86+ $ salesChannelId = $ dataBag ->getString ('salesChannelId ' );
87+ $ debugMode = $ this ->systemConfigService ->getBool ('FroshPlatformTemplateMail.config.debugMode ' , $ salesChannelId );
88+ if ($ debugMode ) {
89+ $ subject = sprintf (
90+ 'DEBUG: %s (%s - %s - %s) ' ,
91+ $ subject ,
92+ $ this ->getSalesChannelName ($ salesChannelId , $ context ),
93+ $ this ->getLocaleCode ($ context ->getLanguageId (), $ context ),
94+ $ technicalName ,
95+ );
96+ }
8097 $ dataBag ->set ('subject ' , $ subject );
8198 }
8299 }
@@ -93,13 +110,11 @@ private function createTemplateMailContext(ParameterBag $dataBag, Context $conte
93110
94111 private function fixTranslator (TemplateMailContext $ businessEvent ): void
95112 {
96- $ criteria = new Criteria ([$ businessEvent ->getContext ()->getLanguageId ()]);
97- $ criteria ->addAssociation ('locale ' );
98-
99- /** @var LanguageEntity $language */
100- $ language = $ this ->languageRepository ->search ($ criteria , $ businessEvent ->getContext ())->first ();
113+ $ localCode = $ this ->getLocaleCode (
114+ $ businessEvent ->getContext ()->getLanguageId (),
115+ $ businessEvent ->getContext (),
116+ );
101117
102- $ localCode = $ language ->getLocale ()?->getCode();
103118 if ($ localCode === null ) {
104119 return ;
105120 }
@@ -111,4 +126,25 @@ private function fixTranslator(TemplateMailContext $businessEvent): void
111126 $ businessEvent ->getContext (),
112127 );
113128 }
129+
130+ private function getLocaleCode (string $ languageId , Context $ context ): ?string
131+ {
132+ $ criteria = new Criteria ([$ languageId ]);
133+ $ criteria ->addAssociation ('locale ' );
134+
135+ /** @var LanguageEntity $language */
136+ $ language = $ this ->languageRepository ->search ($ criteria , $ context )->first ();
137+
138+ return $ language ->getLocale ()?->getCode();
139+ }
140+
141+ private function getSalesChannelName (string $ salesChannelId , Context $ context ): ?string
142+ {
143+ $ criteria = new Criteria ([$ salesChannelId ]);
144+
145+ /** @var SalesChannelEntity $salesChannel */
146+ $ salesChannel = $ this ->salesChannelRepository ->search ($ criteria , $ context )->first ();
147+
148+ return $ salesChannel ->getName ();
149+ }
114150}
0 commit comments