|
| __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) |
|
| process () |
|
ProductAlert observer
- Author
- Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 14 of file Observer.php.
◆ __construct()
__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 |
|
) |
| |
- Parameters
-
\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 | null | $productSalability | @SuppressWarnings(PHPMD.ExcessiveParameterList) |
Definition at line 136 of file Observer.php.
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;
◆ _getWebsites()
Retrieve website collection array
- Returns
- array
- Exceptions
-
Definition at line 171 of file Observer.php.
173 if ($this->_websites ===
null) {
175 $this->_websites = $this->_storeManager->getWebsites();
176 }
catch (\Exception $e) {
177 $this->_errors[] = $e->getMessage();
◆ _processPrice()
Process price emails
- Parameters
-
\Magento\ProductAlert\Model\Email | $email | |
- Returns
- $this
- Exceptions
-
Definition at line 193 of file Observer.php.
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();
213 }
catch (\Exception $e) {
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);
256 }
catch (\Exception $e) {
257 $this->_errors[] = $e->getMessage();
261 if ($previousCustomer) {
264 }
catch (\Exception $e) {
265 $this->_errors[] = $e->getMessage();
◆ _processStock()
Process stock emails
- Parameters
-
\Magento\ProductAlert\Model\Email | $email | |
- Returns
- $this
- Exceptions
-
Definition at line 282 of file Observer.php.
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();
306 }
catch (\Exception $e) {
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);
346 }
catch (\Exception $e) {
347 $this->_errors[] = $e->getMessage();
352 if ($previousCustomer) {
355 }
catch (\Exception $e) {
356 $this->_errors[] = $e->getMessage();
◆ _sendErrorEmail()
Send email to administrator if error
- Returns
- $this
Definition at line 370 of file Observer.php.
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(
390 'area' => \
Magento\Backend\
App\Area\FrontNameResolver::AREA_CODE,
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[] = [];
◆ process()
Run process send product alerts
- Returns
- $this
Definition at line 420 of file Observer.php.
423 $email = $this->_emailFactory->create();
_processPrice(\Magento\ProductAlert\Model\Email $email)
_processStock(\Magento\ProductAlert\Model\Email $email)
◆ $_catalogData
◆ $_dateFactory
◆ $_emailFactory
◆ $_errors
◆ $_priceColFactory
◆ $_scopeConfig
◆ $_stockColFactory
◆ $_storeManager
◆ $_transportBuilder
◆ $_websites
◆ $customerRepository
◆ $inlineTranslation
◆ $productRepository
◆ $productSalability
◆ XML_PATH_ERROR_IDENTITY
const XML_PATH_ERROR_IDENTITY = 'catalog/productalert_cron/error_email_identity' |
Error email identity configuration
Definition at line 24 of file Observer.php.
◆ XML_PATH_ERROR_RECIPIENT
const XML_PATH_ERROR_RECIPIENT = 'catalog/productalert_cron/error_email' |
'Send error emails to' configuration
Definition at line 29 of file Observer.php.
◆ XML_PATH_ERROR_TEMPLATE
const XML_PATH_ERROR_TEMPLATE = 'catalog/productalert_cron/error_email_template' |
Error email template configuration
Definition at line 19 of file Observer.php.
◆ XML_PATH_PRICE_ALLOW
const XML_PATH_PRICE_ALLOW = 'catalog/productalert/allow_price' |
◆ XML_PATH_STOCK_ALLOW
const XML_PATH_STOCK_ALLOW = 'catalog/productalert/allow_stock' |
The documentation for this class was generated from the following file: