Skip to content

Commit 946c6fa

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

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

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

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,50 +151,59 @@ private function processAlerts(string $alertType, array $customerIds, int $websi
151151
$email->setWebsiteId($websiteId);
152152
$errors = [];
153153

154-
try {
155-
$collection = $this->getAlertCollection($alertType, $customerIds, $websiteId);
156-
} catch (\Exception $e) {
157-
$errors[] = $e->getMessage();
158-
return $errors;
159-
}
160-
161-
/** @var CustomerInterface $customer */
162-
$customer = null;
163154
/** @var Website $website */
164155
$website = $this->storeManager->getWebsite($websiteId);
165-
$defaultStoreId = $website->getDefaultStore()->getId();
166-
$products = [];
167156

168-
/** @var Price|Stock $alert */
169-
foreach ($collection as $alert) {
170-
try {
171-
if ($alert->getStoreId()) {
172-
$email->setStoreId($alert->getStoreId());
173-
}
157+
foreach ($website->getStores() as $store) {
158+
/** @var CustomerInterface $customer */
159+
$customer = null;
160+
$products = [];
161+
$storeId = (int)$store->getId();
162+
$email->setStoreId($storeId);
174163

175-
if ($customer === null || (int)$customer->getId() !== (int)$alert->getCustomerId()) {
176-
$customer = $this->customerRepository->getById($alert->getCustomerId());
177-
}
164+
try {
165+
$collection = $this->getAlertCollection($alertType, $customerIds, $websiteId, $storeId);
166+
} catch (\Exception $e) {
167+
$errors[] = $e->getMessage();
168+
return $errors;
169+
}
178170

179-
if (!isset($products[$alert->getProductId()])) {
180-
$product = $this->productRepository->getById($alert->getProductId(), false, $defaultStoreId, true);
181-
$products[$alert->getProductId()] = $product;
182-
} else {
183-
$product = $products[$alert->getProductId()];
171+
/** @var Price|Stock $alert */
172+
foreach ($collection as $alert) {
173+
try {
174+
if ($customer === null) {
175+
$customer = $this->customerRepository->getById($alert->getCustomerId());
176+
} elseif ((int)$customer->getId() !== (int)$alert->getCustomerId()) {
177+
$this->sendEmail($customer, $email);
178+
$customer = $this->customerRepository->getById($alert->getCustomerId());
179+
}
180+
181+
if (!isset($products[$alert->getProductId()])) {
182+
$product = $this->productRepository->getById($alert->getProductId(), false, $storeId, true);
183+
$products[$alert->getProductId()] = $product;
184+
} else {
185+
$product = $products[$alert->getProductId()];
186+
}
187+
188+
switch ($alertType) {
189+
case self::ALERT_TYPE_STOCK:
190+
$this->saveStockAlert($alert, $product, $website, $email);
191+
break;
192+
case self::ALERT_TYPE_PRICE:
193+
$this->savePriceAlert($alert, $product, $customer, $email);
194+
break;
195+
}
196+
} catch (\Exception $e) {
197+
$errors[] = $e->getMessage();
184198
}
199+
}
185200

186-
switch ($alertType) {
187-
case self::ALERT_TYPE_STOCK:
188-
$this->saveStockAlert($alert, $product, $website, $email);
189-
break;
190-
case self::ALERT_TYPE_PRICE:
191-
$this->savePriceAlert($alert, $product, $customer, $email);
192-
break;
201+
if ($customer !== null) {
202+
try {
203+
$this->sendEmail($customer, $email);
204+
} catch (\Exception $e) {
205+
$errors[] = $e->getMessage();
193206
}
194-
195-
$this->sendEmail($customer, $email);
196-
} catch (\Exception $e) {
197-
$errors[] = $e->getMessage();
198207
}
199208
}
200209

@@ -220,24 +229,27 @@ private function validateAlertType(string $alertType): void
220229
* @param string $alertType
221230
* @param array $customerIds
222231
* @param int $websiteId
232+
* @param int $storeId
223233
* @return AbstractCollection
224234
* @throws \InvalidArgumentException
225235
*/
226-
private function getAlertCollection(string $alertType, array $customerIds, int $websiteId): AbstractCollection
236+
private function getAlertCollection(string $alertType, array $customerIds, int $websiteId, int $storeId): AbstractCollection
227237
{
228238
switch ($alertType) {
229239
case self::ALERT_TYPE_STOCK:
230240
$collection = $this->stockCollectionFactory->create();
231241
$collection->addFieldToFilter('customer_id', ['in' => $customerIds])
232242
->addWebsiteFilter($websiteId)
233243
->addStatusFilter(0)
244+
->addFilter('store_id', $storeId)
234245
->setCustomerOrder()
235246
->addOrder('product_id');
236247
break;
237248
case self::ALERT_TYPE_PRICE:
238249
$collection = $this->priceCollectionFactory->create();
239250
$collection->addFieldToFilter('customer_id', ['in' => $customerIds])
240251
->addWebsiteFilter($websiteId)
252+
->addFilter('store_id', $storeId)
241253
->setCustomerOrder()
242254
->addOrder('product_id');
243255
break;

0 commit comments

Comments
 (0)