magento2: Newsletter subscription does not set the correct store_id if already subscribed. Not Fixed in 2.3-dev
Regarding https://github.com/magento/magento2/issues/19131. I (again) tried it on 2.3-dev an the issue is not fixed in 2.3-dev.
Preconditions (*)
- latest Magento Version 2.3-dev
- Have at least two stores ( A and B)
Steps to reproduce (*)
- Register a user in A
- Subscribe to Newsletter in A
- Switch to Store B
- Subscribe to Newsletter again
Expected result (*)
- When in store B, Subscriber::loadByEmail() should work
2.
SELECT store_id, customer_id FROM newsletter_subscriber
should look like this:
+----------+-------------+
| store_id | customer_id |
+----------+-------------+
| 1 | 1 |
| 2 | 1 |
Actual result (*)
- When in store B, loadByEmail() (or loadById() ) cant find the subscriber since
SELECT store_id, customer_id FROM newsletter_subscriber
looks like this:
+----------+-------------+
| store_id | customer_id |
+----------+-------------+
| 1 | 1 |
| 1 | 1 |
What i think where the error is
In app/code/Magento/Newsletter/Model/Subscriber.php
starting on line 468:
If the subscriber already exists with this email, the new entry gets the $customer->getStoreId()
not the $this->_storeManager->getStore()->getId()
If this is the intended behavior then loadByEmail()
or loadByCustomerId()
should be store_id agnostic.
Cheers! Ben
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (11 by maintainers)
I also spot issue related to this and there is another way to reproduce it, in backend:
A success message is displayed, the customer is added to the newsletter_subscriber table, but the customer is still not marked as subscribed in the edit form. Doing steps 7 to 9 results in duplicating entry in subscribers table. After few saves I see following:
Additionally, it sends an email confirmation to the customer each time.
The same problem occurs when such customer is subscribed or saved by CLI or CRON job.
It looks it was introduced in the https://github.com/magento/magento2/commit/65000d81b388a7218ae9c9ec5c12bcb00d932c3c commit.
The problem doesn’t occur in 2.1.5 as
loadByCustomerData
method was ignoring store_id there.Maybe
\Magento\Newsletter\Model\Subscriber::loadByCustomerId
shouldn’t overwrtite store_id on customer record? In my case it seems to fix the problem.Another issue is that when customer for the new website is created by admin in the backend and he is subscribed to the newsletter by admin, store_id of his record in newsletter_subscriber is 1. This can lead to other buggy use cases.