Skip to content

Multiple newsletter confirmation emails sent #12876

@nfourteen

Description

@nfourteen

Preconditions

  1. Magento 2.2.1
  2. Php 7.0

Steps to reproduce

  1. Change configuration under Stores > Configuration > Customers > Newsletter > Subscription Options > Need to Confirm to Yes
  2. Sign up for Newsletter on frontend as a guest
  3. Follow confirmation link in email
  4. 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:

  1. 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.
  2. 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

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions