-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions
- Magento 2.2.1
- Php 7.0
Steps to reproduce
- Change configuration under
Stores > Configuration > Customers > Newsletter > Subscription Options > Need to Confirm
to Yes - Sign up for Newsletter on frontend as a guest
- Follow confirmation link in email
- Create an account and check Sign Up for Newsletter within the form and use the same email as in Step 2
Expected result
There are a couple different results that I'll leave to the Magento core team:
- If someone signed up for a Newsletter subscription as a guest, have confirmed that subscription, and then create an account with the same email—then the Magento application could update the Newsletter Subscribers with the customer data and leave the status as Subscribed, thus no Need to Confirm email is sent since they've already confirmed they wanted to receive the newsletter.
- The Magento application could change the guest email status to
STATUS_UNCONFIRMED
, update the guest email with the customer data, and send the Need to Confirm email for the new account.
Actual result
- Three Need to Confirm emails are received.
Reason
The first two emails are received because of the \Magento\Newsletter\Model\Plugin\CustomerPlugin::afterSave()
method. When \Magento\Customer\Controller\Account\CreatePost::execute()
is called a new customer account is created on line 313
with \Magento\Customer\Model\AccountManagement::createAccount()
. The createAccount()
method calls createAccountWithPasswordHash()
whereby the customer is saved on line 748
and then that same method calls $this->changeResetPasswordLinkToken()
on line 775
, which again saves the customer on line 1242
. Thus these two customer saves trigger the afterSave()
method calls on the CustomerPlugin
, which updates the subscription and sends the two emails.
The third and final email is received within the Magento\Customer\Controller\Account\CreatePost::execute()
method on line 317
when the is_subscribed
param is retrieved from the form data within the request and the if
conditional equals true
because of Step 4 above.