143 \
Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory,
146 \
Magento\ProductAlert\Model\EmailFactory $emailFactory,
150 $this->_catalogData = $catalogData;
151 $this->_scopeConfig = $scopeConfig;
153 $this->_priceColFactory = $priceColFactory;
156 $this->_dateFactory = $dateFactory;
157 $this->_stockColFactory = $stockColFactory;
158 $this->_transportBuilder = $transportBuilder;
159 $this->_emailFactory = $emailFactory;
173 if ($this->_websites ===
null) {
175 $this->_websites = $this->_storeManager->getWebsites();
177 $this->_errors[] = $e->getMessage();
198 if (!
$website->getDefaultGroup() || !
$website->getDefaultGroup()->getDefaultStore()) {
201 if (!$this->_scopeConfig->getValue(
202 self::XML_PATH_PRICE_ALLOW,
204 $website->getDefaultGroup()->getDefaultStore()->getId()
210 $collection = $this->_priceColFactory->create()->addWebsiteFilter(
212 )->setCustomerOrder();
214 $this->_errors[] = $e->getMessage();
218 $previousCustomer =
null;
222 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
223 $customer = $this->customerRepository->getById($alert->getCustomerId());
224 if ($previousCustomer) {
237 $product = $this->productRepository->getById(
238 $alert->getProductId(),
240 $website->getDefaultStore()->getId()
244 if ($alert->getPrice() >
$product->getFinalPrice()) {
245 $productPrice =
$product->getFinalPrice();
246 $product->setFinalPrice($this->_catalogData->getTaxPrice(
$product, $productPrice));
250 $alert->setPrice($productPrice);
251 $alert->setLastSendDate($this->_dateFactory->create()->gmtDate());
252 $alert->setSendCount($alert->getSendCount() + 1);
253 $alert->setStatus(1);
257 $this->_errors[] = $e->getMessage();
261 if ($previousCustomer) {
265 $this->_errors[] = $e->getMessage();
289 if (!
$website->getDefaultGroup() || !
$website->getDefaultGroup()->getDefaultStore()) {
292 if (!$this->_scopeConfig->getValue(
293 self::XML_PATH_STOCK_ALLOW,
295 $website->getDefaultGroup()->getDefaultStore()->getId()
301 $collection = $this->_stockColFactory->create()->addWebsiteFilter(
305 )->setCustomerOrder();
307 $this->_errors[] = $e->getMessage();
311 $previousCustomer =
null;
315 if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
316 $customer = $this->customerRepository->getById($alert->getCustomerId());
317 if ($previousCustomer) {
330 $product = $this->productRepository->getById(
331 $alert->getProductId(),
333 $website->getDefaultStore()->getId()
341 $alert->setSendDate($this->_dateFactory->create()->gmtDate());
342 $alert->setSendCount($alert->getSendCount() + 1);
343 $alert->setStatus(1);
347 $this->_errors[] = $e->getMessage();
352 if ($previousCustomer) {
356 $this->_errors[] = $e->getMessage();
372 if (count($this->_errors)) {
373 if (!$this->_scopeConfig->getValue(
374 self::XML_PATH_ERROR_TEMPLATE,
381 $this->inlineTranslation->suspend();
383 $transport = $this->_transportBuilder->setTemplateIdentifier(
384 $this->_scopeConfig->getValue(
385 self::XML_PATH_ERROR_TEMPLATE,
388 )->setTemplateOptions(
394 [
'warnings' => join(
"\n", $this->_errors)]
396 $this->_scopeConfig->getValue(
397 self::XML_PATH_ERROR_IDENTITY,
401 $this->_scopeConfig->getValue(
402 self::XML_PATH_ERROR_RECIPIENT,
407 $transport->sendMessage();
409 $this->inlineTranslation->resume();
410 $this->_errors[] = [];
423 $email = $this->_emailFactory->create();
const XML_PATH_ERROR_IDENTITY
const XML_PATH_PRICE_ALLOW
const XML_PATH_STOCK_ALLOW
_processPrice(\Magento\ProductAlert\Model\Email $email)
_processStock(\Magento\ProductAlert\Model\Email $email)
const XML_PATH_ERROR_TEMPLATE
__construct(\Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ProductAlert\Model\ResourceModel\Price\CollectionFactory $priceColFactory, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory, \Magento\ProductAlert\Model\ResourceModel\Stock\CollectionFactory $stockColFactory, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\ProductAlert\Model\EmailFactory $emailFactory, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, ProductSalability $productSalability=null)
const XML_PATH_ERROR_RECIPIENT