[Backport] Fix newsletter subscription behaviour for registered customer. #17179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original Pull Request
#15479
This Pull Request fix newsletter subscription behaviour for registered customer.
Registered customer can subscribe to newsletter from 2 places:
If set Magento Admin->Stores->Configuration->Customers->Newsletter->"Need to Confirm" to "yes" subscribe to newsletter from My Account require customer confirmation, but from newsletter block confirmation not required and registered customer will be subscribed to newsletter.
We expect that in both cases behaviour will be the same: customer must confirm subscribe to newsletter action. (It also compliance with new GDPR).
Backend background:
issue with different behaviour is come because subscribe from My Account and subscribe from newsletter block use different methods with different logic.
Subscribe to newsletter from MyAccount use \Magento\Newsletter\Model\Subscriber::_updateCustomerSubscription($customerId, $subscribe)
Subscribe to newsletter from newsletter block use \Magento\Newsletter\Model\Subscriber::subscribe($email)
subscribe($email) have row which checking if email for subscribe the same as customer email
$isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
and if NeedToConfirm is active:
customer will be subscribed to newsletter without confirmation if $isSubscribeOwnEmail =true
or
customer must confirm email when $isSubscribeOwnEmail =false
Instead of subscribe($email) method _updateCustomerSubscription($customerId, $subscribe) doesn't have this check $isSubscribeOwnEmail and in any case require confirmation if NeedToConfirm is active.
PR fix remove $isSubscribeOwnEmail var from subscribe($email) method and behaviour will be the same in both cases for subscribe to newsletter action: from MyAccount and from newsletter block.