Skip to content

Commit 0c6fb69

Browse files
ACP2E-3336: Stock alert email translation to the wrong language
1 parent d01ee51 commit 0c6fb69

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-10
lines changed

app/code/Magento/ProductAlert/Model/Mailing/AlertProcessor.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ private function processAlerts(string $alertType, array $customerIds, int $websi
171171
if ($alert->getStoreId()) {
172172
$email->setStoreId($alert->getStoreId());
173173
}
174-
if ($customer === null) {
175-
$customer = $this->customerRepository->getById($alert->getCustomerId());
176-
} elseif ((int)$customer->getId() !== (int)$alert->getCustomerId()) {
177-
$this->sendEmail($customer, $email);
174+
175+
if ($customer === null || (int)$customer->getId() !== (int)$alert->getCustomerId()) {
178176
$customer = $this->customerRepository->getById($alert->getCustomerId());
179177
}
180178

@@ -193,13 +191,7 @@ private function processAlerts(string $alertType, array $customerIds, int $websi
193191
$this->savePriceAlert($alert, $product, $customer, $email);
194192
break;
195193
}
196-
} catch (\Exception $e) {
197-
$errors[] = $e->getMessage();
198-
}
199-
}
200194

201-
if ($customer !== null) {
202-
try {
203195
$this->sendEmail($customer, $email);
204196
} catch (\Exception $e) {
205197
$errors[] = $e->getMessage();

dev/tests/integration/testsuite/Magento/ProductAlert/Model/Mailing/AlertProcessorTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,78 @@ public function testValidateCurrentTheme()
243243
);
244244
}
245245

246+
#[
247+
DbIsolation(false),
248+
DataFixture(StoreFixture::class, ['code' => 'pt_br_store'], 'store2'),
249+
DataFixture(CustomerFixture::class, as: 'customer'),
250+
DataFixture(ProductFixture::class, as: 'product'),
251+
DataFixture(
252+
PriceAlertFixture::class,
253+
[
254+
'customer_id' => '$customer.id$',
255+
'product_id' => '$product.id$',
256+
'store_id' => '1',
257+
]
258+
),
259+
DataFixture(
260+
PriceAlertFixture::class,
261+
[
262+
'customer_id' => '$customer.id$',
263+
'product_id' => '$product.id$',
264+
'store_id' => '$store2.id$',
265+
]
266+
),
267+
DataFixture(
268+
TranslationFixture::class,
269+
[
270+
'string' => 'Price change alert! We wanted you to know that prices have changed for these products:',
271+
'translate' => 'Alerte changement de prix! Nous voulions que vous sachiez' .
272+
' que les prix ont changé pour ces produits:',
273+
'locale' => 'fr_FR',
274+
],
275+
'frTxt'
276+
),
277+
DataFixture(
278+
TranslationFixture::class,
279+
[
280+
'string' => 'Price change alert! We wanted you to know that prices have changed for these products:',
281+
'translate' => 'Alerta de mudanca de preco! Queriamos que voce soubesse' .
282+
' que os precos mudaram para esses produtos:',
283+
'locale' => 'pt_BR',
284+
],
285+
'ptTxt'
286+
),
287+
Config('catalog/productalert/allow_price', 1),
288+
Config('general/locale/code', 'fr_FR', ScopeInterface::SCOPE_STORE, 'default'),
289+
Config('general/locale/code', 'pt_BR', ScopeInterface::SCOPE_STORE, 'pt_br_store'),
290+
]
291+
public function testEmailShouldBeTranslatedToStoreViewLanguage()
292+
{
293+
$customerId = (int)$this->fixtures->get('customer')->getId();
294+
295+
$frMailSent = false;
296+
$ptMailSent = false;
297+
$this->transportBuilder->setOnMessageSentCallback(
298+
function ($message) use (&$frMailSent, &$ptMailSent) {
299+
$messageContent = $message->getBody()->getParts()[0]->getRawContent();
300+
$frTxt = $this->fixtures->get('frTxt')->getTranslate();
301+
$ptTxt = $this->fixtures->get('ptTxt')->getTranslate();
302+
303+
if (str_contains($messageContent, $frTxt)) {
304+
$frMailSent = true;
305+
}
306+
307+
if (str_contains($messageContent, $ptTxt)) {
308+
$ptMailSent = true;
309+
}
310+
}
311+
);
312+
313+
$this->processAlerts($customerId);
314+
$this->assertTrue($frMailSent);
315+
$this->assertTrue($ptMailSent);
316+
}
317+
246318
/**
247319
* @param int $customerId
248320
* @param int $websiteId

0 commit comments

Comments
 (0)