157 Data $productAlertData,
161 View $customerHelper,
168 $this->_productAlertData = $productAlertData;
169 $this->_scopeConfig = $scopeConfig;
172 $this->_appEmulation = $appEmulation;
173 $this->_transportBuilder = $transportBuilder;
174 $this->_customerHelper = $customerHelper;
187 $this->_type =
$type;
223 $this->_website = $this->_storeManager->getWebsite(
$websiteId);
238 $this->_customer = $this->customerRepository->getById(
$customerId);
262 $this->_customer =
null;
263 $this->_priceProducts = [];
264 $this->_stockProducts = [];
303 if ($this->_priceBlock ===
null) {
304 $this->_priceBlock = $this->_productAlertData->createBlock(Price::class);
317 if ($this->_stockBlock ===
null) {
318 $this->_stockBlock = $this->_productAlertData->createBlock(Stock::class);
333 if ($this->_website ===
null || $this->_customer ===
null) {
337 if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
341 if (!in_array($this->_type, [
'price',
'stock'])) {
350 $templateConfigPath = $this->getTemplateConfigPath();
351 if (!$templateConfigPath) {
355 $store = $this->getStore((
int) $this->_customer->getStoreId());
358 $this->_appEmulation->startEnvironmentEmulation(
$storeId);
360 $block = $this->getBlock();
365 $product->setCustomerGroupId($this->_customer->getGroupId());
375 $alertGrid = $this->_appState->emulateAreaCode(
379 $this->_appEmulation->stopEnvironmentEmulation();
381 $customerName = $this->_customerHelper->getCustomerName($this->_customer);
382 $this->_transportBuilder->setTemplateIdentifier(
384 )->setTemplateOptions(
388 'customerName' => $customerName,
389 'alertGrid' => $alertGrid,
392 $this->_scopeConfig->getValue(
393 self::XML_PATH_EMAIL_IDENTITY,
398 $this->_customer->getEmail(),
400 )->getTransport()->sendMessage();
415 return $customerStoreId > 0
416 ? $this->_storeManager->getStore($customerStoreId)
417 : $this->_website->getDefaultStore();
426 private function getBlock(): AbstractEmail
428 return $this->_type ===
'price' 438 private function getProducts(): array
440 return $this->_type ===
'price' 441 ? $this->_priceProducts
450 private function getTemplateConfigPath(): string
452 return $this->_type ===
'price'
const XML_PATH_EMAIL_STOCK_TEMPLATE
__construct(Context $context, Registry $registry, Data $productAlertData, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, CustomerRepositoryInterface $customerRepository, View $customerHelper, Emulation $appEmulation, TransportBuilder $transportBuilder, AbstractResource $resource=null, AbstractDb $resourceCollection=null, array $data=[])
const XML_PATH_EMAIL_IDENTITY
const XML_PATH_EMAIL_PRICE_TEMPLATE
addStockProduct(\Magento\Catalog\Model\Product $product)
setCustomerData($customer)
setWebsite(\Magento\Store\Model\Website $website)
addPriceProduct(\Magento\Catalog\Model\Product $product)
setCustomerId($customerId)