Skip to content

Commit 11d649a

Browse files
jasperP98shyim
andauthored
Allow mails to be translated by a given language (#68)
* Allow mails to be translated by a given language * Update FlowSubscriber.php --------- Co-authored-by: Shyim <[email protected]>
1 parent 62b48ef commit 11d649a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Services/TemplateMailContext.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TemplateMailContext
1414
public function __construct(
1515
private readonly string $salesChannelId,
1616
private readonly Context $context,
17+
private readonly ?string $languageId = null,
1718
) {}
1819

1920
public function getSalesChannelId(): string
@@ -25,4 +26,9 @@ public function getContext(): Context
2526
{
2627
return $this->context;
2728
}
29+
30+
public function getLanguageId(): ?string
31+
{
32+
return $this->languageId;
33+
}
2834
}

src/Subscriber/FlowSubscriber.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,31 @@ private function sendMail(DataBag $dataBag, string $mailTemplateTypeId, Context
101101
private function createTemplateMailContext(ParameterBag $dataBag, Context $context): TemplateMailContext
102102
{
103103
$salesChannelId = $dataBag->get('salesChannelId');
104+
$languageId = $dataBag->get('languageId');
104105

105106
return new TemplateMailContext(
106107
\is_string($salesChannelId) ? $salesChannelId : Defaults::SALES_CHANNEL_TYPE_STOREFRONT,
107108
$context,
109+
\is_string($languageId) ? $languageId : null,
108110
);
109111
}
110112

111113
private function fixTranslator(TemplateMailContext $businessEvent): void
112114
{
115+
$languageId = $businessEvent->getLanguageId() ?? $businessEvent->getContext()->getLanguageId();
113116
$localCode = $this->getLocaleCode(
114-
$businessEvent->getContext()->getLanguageId(),
117+
$languageId,
115118
$businessEvent->getContext(),
116119
);
117120

121+
118122
if ($localCode === null) {
119123
return;
120124
}
121125

122126
$this->translator->injectSettings(
123127
$businessEvent->getSalesChannelId(),
124-
$businessEvent->getContext()->getLanguageId(),
128+
$languageId,
125129
$localCode,
126130
$businessEvent->getContext(),
127131
);

0 commit comments

Comments
 (0)