Skip to content

Commit bd31597

Browse files
author
Serhii Balko
committed
MC-41917: Issue with 'catalog_product_alert' cron
1 parent 8d2a50d commit bd31597

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,12 @@ private function processAlerts(string $alertType, array $customerIds, int $websi
204204
* Validate Alert Type
205205
*
206206
* @param string $alertType
207-
* @throws \Exception
207+
* @throws \InvalidArgumentException
208208
*/
209209
private function validateAlertType(string $alertType): void
210210
{
211-
switch ($alertType) {
212-
case self::ALERT_TYPE_STOCK:
213-
case self::ALERT_TYPE_PRICE:
214-
break;
215-
default:
216-
throw new \Exception('Invalid alert type');
211+
if (!in_array($alertType, [self::ALERT_TYPE_STOCK, self::ALERT_TYPE_PRICE])) {
212+
throw new \InvalidArgumentException('Invalid alert type');
217213
}
218214
}
219215

@@ -222,8 +218,9 @@ private function validateAlertType(string $alertType): void
222218
*
223219
* @param string $alertType
224220
* @param array $customerIds
221+
* @param int $websiteId
225222
* @return AbstractCollection
226-
* @throws \Exception
223+
* @throws \InvalidArgumentException
227224
*/
228225
private function getAlertCollection(string $alertType, array $customerIds, int $websiteId): AbstractCollection
229226
{
@@ -244,7 +241,7 @@ private function getAlertCollection(string $alertType, array $customerIds, int $
244241
->addOrder('product_id');
245242
break;
246243
default:
247-
throw new \Exception('Invalid alert type');
244+
throw new \InvalidArgumentException('Invalid alert type');
248245
}
249246

250247
return $collection;

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Mail\Template\TransportBuilder;
1313
use Magento\Framework\Translate\Inline\StateInterface;
1414
use Magento\Store\Model\ScopeInterface;
15+
use Psr\Log\LoggerInterface;
1516

1617
/**
1718
* Class to send error emails to administrator
@@ -48,19 +49,27 @@ class ErrorEmailSender
4849
*/
4950
private $inlineTranslation;
5051

52+
/**
53+
* @var LoggerInterface
54+
*/
55+
private $logger;
56+
5157
/**
5258
* @param ScopeConfigInterface $scopeConfig
5359
* @param TransportBuilder $transportBuilder
5460
* @param StateInterface $inlineTranslation
61+
* @param LoggerInterface $logger
5562
*/
5663
public function __construct(
5764
ScopeConfigInterface $scopeConfig,
5865
TransportBuilder $transportBuilder,
59-
StateInterface $inlineTranslation
66+
StateInterface $inlineTranslation,
67+
LoggerInterface $logger
6068
) {
6169
$this->scopeConfig = $scopeConfig;
6270
$this->transportBuilder = $transportBuilder;
6371
$this->inlineTranslation = $inlineTranslation;
72+
$this->logger = $logger;
6473
}
6574

6675
/**
@@ -76,6 +85,10 @@ public function execute(array $errors, int $storeId): void
7685
return;
7786
}
7887

88+
$this->logger->error(
89+
'Product Alerts: ' . count($errors) . ' errors occurred during sending alerts.'
90+
);
91+
7992
if (!$this->scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, ScopeInterface::SCOPE_STORE, $storeId)) {
8093
return;
8194
}

0 commit comments

Comments
 (0)