Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
EmailNotification Class Reference
Inheritance diagram for EmailNotification:
EmailNotificationInterface

Public Member Functions

 __construct (CustomerRegistry $customerRegistry, StoreManagerInterface $storeManager, TransportBuilder $transportBuilder, CustomerViewHelper $customerViewHelper, DataObjectProcessor $dataProcessor, ScopeConfigInterface $scopeConfig, SenderResolverInterface $senderResolver=null)
 
 credentialsChanged (CustomerInterface $savedCustomer, $origCustomerEmail, $isPasswordChanged=false)
 
 passwordReminder (CustomerInterface $customer)
 
 passwordResetConfirmation (CustomerInterface $customer)
 
 newAccount (CustomerInterface $customer, $type=self::NEW_ACCOUNT_EMAIL_REGISTERED, $backUrl='', $storeId=0, $sendemailStoreId=null)
 

Data Fields

const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity'
 
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template'
 
const XML_PATH_CHANGE_EMAIL_TEMPLATE = 'customer/account_information/change_email_template'
 
const XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE
 
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template'
 
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template'
 
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity'
 
const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template'
 
const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template'
 
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'
 
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template'
 
const TEMPLATE_TYPES
 
- Data Fields inherited from EmailNotificationInterface
const NEW_ACCOUNT_EMAIL_REGISTERED = 'registered'
 
const NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD = 'registered_no_password'
 
const NEW_ACCOUNT_EMAIL_CONFIRMATION = 'confirmation'
 
const NEW_ACCOUNT_EMAIL_CONFIRMED = 'confirmed'
 

Protected Attributes

 $customerViewHelper
 
 $dataProcessor
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 22 of file EmailNotification.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( CustomerRegistry  $customerRegistry,
StoreManagerInterface  $storeManager,
TransportBuilder  $transportBuilder,
CustomerViewHelper  $customerViewHelper,
DataObjectProcessor  $dataProcessor,
ScopeConfigInterface  $scopeConfig,
SenderResolverInterface  $senderResolver = null 
)
Parameters
CustomerRegistry$customerRegistry
StoreManagerInterface$storeManager
TransportBuilder$transportBuilder
CustomerViewHelper$customerViewHelper
DataObjectProcessor$dataProcessor
ScopeConfigInterface$scopeConfig
SenderResolverInterface | null$senderResolver

Definition at line 110 of file EmailNotification.php.

118  {
119  $this->customerRegistry = $customerRegistry;
120  $this->storeManager = $storeManager;
121  $this->transportBuilder = $transportBuilder;
122  $this->customerViewHelper = $customerViewHelper;
123  $this->dataProcessor = $dataProcessor;
124  $this->scopeConfig = $scopeConfig;
125  $this->senderResolver = $senderResolver ?: ObjectManager::getInstance()->get(SenderResolverInterface::class);
126  }

Member Function Documentation

◆ credentialsChanged()

credentialsChanged ( CustomerInterface  $savedCustomer,
  $origCustomerEmail,
  $isPasswordChanged = false 
)

Send notification to customer when email or/and password changed

Parameters
CustomerInterface$savedCustomer
string$origCustomerEmail
bool$isPasswordChanged
Returns
void

Implements EmailNotificationInterface.

Definition at line 136 of file EmailNotification.php.

140  {
141  if ($origCustomerEmail != $savedCustomer->getEmail()) {
142  if ($isPasswordChanged) {
143  $this->emailAndPasswordChanged($savedCustomer, $origCustomerEmail);
144  $this->emailAndPasswordChanged($savedCustomer, $savedCustomer->getEmail());
145  return;
146  }
147 
148  $this->emailChanged($savedCustomer, $origCustomerEmail);
149  $this->emailChanged($savedCustomer, $savedCustomer->getEmail());
150  return;
151  }
152 
153  if ($isPasswordChanged) {
154  $this->passwordReset($savedCustomer);
155  }
156  }

◆ newAccount()

newAccount ( CustomerInterface  $customer,
  $type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
  $backUrl = '',
  $storeId = 0,
  $sendemailStoreId = null 
)

Send email with new account related information

Parameters
CustomerInterface$customer
string$type
string$backUrl
string$storeId
string$sendemailStoreId
Returns
void
Exceptions
LocalizedException

Implements EmailNotificationInterface.

Definition at line 368 of file EmailNotification.php.

374  {
375  $types = self::TEMPLATE_TYPES;
376 
377  if (!isset($types[$type])) {
378  throw new LocalizedException(
379  __('The transactional account email type is incorrect. Verify and try again.')
380  );
381  }
382 
383  if (!$storeId) {
384  $storeId = $this->getWebsiteStoreId($customer, $sendemailStoreId);
385  }
386 
387  $store = $this->storeManager->getStore($customer->getStoreId());
388 
389  $customerEmailData = $this->getFullCustomerObject($customer);
390 
391  $this->sendEmailTemplate(
392  $customer,
393  $types[$type],
394  self::XML_PATH_REGISTER_EMAIL_IDENTITY,
395  ['customer' => $customerEmailData, 'back_url' => $backUrl, 'store' => $store],
396  $storeId
397  );
398  }
$customer
Definition: customers.php:11
__()
Definition: __.php:13
$type
Definition: item.phtml:13

◆ passwordReminder()

passwordReminder ( CustomerInterface  $customer)

Send email with new customer password

Parameters
CustomerInterface$customer
Returns
void

Implements EmailNotificationInterface.

Definition at line 315 of file EmailNotification.php.

316  {
317  $storeId = $customer->getStoreId();
318  if (!$storeId) {
319  $storeId = $this->getWebsiteStoreId($customer);
320  }
321 
322  $customerEmailData = $this->getFullCustomerObject($customer);
323 
324  $this->sendEmailTemplate(
325  $customer,
326  self::XML_PATH_REMIND_EMAIL_TEMPLATE,
327  self::XML_PATH_FORGOT_EMAIL_IDENTITY,
328  ['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)],
329  $storeId
330  );
331  }
$customer
Definition: customers.php:11

◆ passwordResetConfirmation()

passwordResetConfirmation ( CustomerInterface  $customer)

Send email with reset password confirmation link

Parameters
CustomerInterface$customer
Returns
void

Implements EmailNotificationInterface.

Definition at line 339 of file EmailNotification.php.

340  {
341  $storeId = $this->storeManager->getStore()->getId();
342  if (!$storeId) {
343  $storeId = $this->getWebsiteStoreId($customer);
344  }
345 
346  $customerEmailData = $this->getFullCustomerObject($customer);
347 
348  $this->sendEmailTemplate(
349  $customer,
350  self::XML_PATH_FORGOT_EMAIL_TEMPLATE,
351  self::XML_PATH_FORGOT_EMAIL_IDENTITY,
352  ['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)],
353  $storeId
354  );
355  }
$customer
Definition: customers.php:11

Field Documentation

◆ $customerViewHelper

$customerViewHelper
protected

Definition at line 84 of file EmailNotification.php.

◆ $dataProcessor

$dataProcessor
protected

Definition at line 89 of file EmailNotification.php.

◆ TEMPLATE_TYPES

const TEMPLATE_TYPES
Initial value:
= [
self::NEW_ACCOUNT_EMAIL_REGISTERED => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,
self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD => self::XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE,
self::NEW_ACCOUNT_EMAIL_CONFIRMED => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE,
self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
]

self::NEW_ACCOUNT_EMAIL_REGISTERED welcome email, when confirmation is disabled and password is set self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD welcome email, when confirmation is disabled and password is not set self::NEW_ACCOUNT_EMAIL_CONFIRMED welcome email, when confirmation is enabled and password is set self::NEW_ACCOUNT_EMAIL_CONFIRMATION email with confirmation link

Definition at line 59 of file EmailNotification.php.

◆ XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE

const XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE
Initial value:
=
'customer/account_information/change_email_and_password_template'

Definition at line 33 of file EmailNotification.php.

◆ XML_PATH_CHANGE_EMAIL_TEMPLATE

const XML_PATH_CHANGE_EMAIL_TEMPLATE = 'customer/account_information/change_email_template'

Definition at line 31 of file EmailNotification.php.

◆ XML_PATH_CONFIRM_EMAIL_TEMPLATE

const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'

Definition at line 46 of file EmailNotification.php.

◆ XML_PATH_CONFIRMED_EMAIL_TEMPLATE

const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template'

Definition at line 48 of file EmailNotification.php.

◆ XML_PATH_FORGOT_EMAIL_IDENTITY

const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity'

#+ Configuration paths for email templates and identities

Definition at line 27 of file EmailNotification.php.

◆ XML_PATH_FORGOT_EMAIL_TEMPLATE

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template'

Definition at line 36 of file EmailNotification.php.

◆ XML_PATH_REGISTER_EMAIL_IDENTITY

const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity'

Definition at line 40 of file EmailNotification.php.

◆ XML_PATH_REGISTER_EMAIL_TEMPLATE

const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template'

Definition at line 42 of file EmailNotification.php.

◆ XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE

const XML_PATH_REGISTER_NO_PASSWORD_EMAIL_TEMPLATE = 'customer/create_account/email_no_password_template'

Definition at line 44 of file EmailNotification.php.

◆ XML_PATH_REMIND_EMAIL_TEMPLATE

const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template'

Definition at line 38 of file EmailNotification.php.

◆ XML_PATH_RESET_PASSWORD_TEMPLATE

const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template'

Definition at line 29 of file EmailNotification.php.


The documentation for this class was generated from the following file: