Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newsletter subscriptions status not isolated between multi stores #10014

Closed
mikelevy300 opened this issue Jun 21, 2017 · 7 comments
Closed

Newsletter subscriptions status not isolated between multi stores #10014

mikelevy300 opened this issue Jun 21, 2017 · 7 comments
Assignees
Labels
bug report Component: Customer Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@mikelevy300
Copy link

mikelevy300 commented Jun 21, 2017

When a customer with the same email address has an account on different multi stores in the same Magento installation, changes to the newsletter subscription in one account affect the other.

Preconditions

  1. Magento 2.1.5
  2. PHP 7.0.16
  3. MySQL 5.7
  4. Apache 2.4
  5. At least two stores setup with nothing shared
  6. A customer exists in both stores with the same email address

Steps to reproduce

  1. Login with customer 1 in store A, go to My Account -> Newsletter Subscriptions, and make sure he's subscribed to the general newsletter
  2. Login with customer 2 in store B, go to My Account -> Newsletter Subscriptions, and make sure he's subscribed to the general newsletter
  3. Unsubscribe customer 1 from the newsletter
  4. Refresh the page for customer 2

Expected result

  1. Customer 1 is unsubscribed
  2. Customer 2 is subscribed

Actual Result

  1. Customer 1 is unsubscribed
  2. Customer 2 is unsubscribed

Extra info

When looking in the newsletter_subscriber table, instead of there being one record for each customer per store, there's one global record. When customer 1 in store A updates, the store_id in newsletter subscriber is updated to store A's ID. When customer 2 in store B updates, the store_id in newsletter_subscriber is updated to store B's ID.

Tracing the code out, I think the problem is in Magento_Newsletter\Model\ResourceModel\Subscriber.php, specifically the loadByCustomerData function.
Here's the function:

public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer){
	$select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id');

	$result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]);

	if ($result) {
		return $result;
	}

	$select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');

	$result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);

	if ($result) {
		return $result;
	}

	return [];
}

It basically uses the customerId as the lookup key but then falls back to the customerEmail if nothing is found. This creates the unintended consequence where updates in one store show in the other. A suggested fix would be to either only use the customerId or add an additional field to the select that matches the store_id of the customer, something like

select * from newsletter_subscriber where subscriber_email = $customer->getEmail() and store_id = $customer->getStoreId()
@AlexWorking
Copy link

Hello @mikelevy300. Based on Your issue an internal ticket was created - MAGETWO-70081. You'll be informed right after Your issue is resolved. Thank You for applying.

@veloraven veloraven added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 22, 2017
@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Customer Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 9, 2017
@magento-engcom-team
Copy link
Contributor

@mikelevy300, thank you for your report.
We've created internal ticket(s) MAGETWO-70081 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 11, 2017
@sbaixauli
Copy link

I am working on it at #mm17es

@okorshenko
Copy link
Contributor

The issue has been fixed and delivered to 2.2-develop branch. Will be available with 2.2.2 release

@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 13, 2017
@TomashKhamlai
Copy link
Contributor

Not "stores" but "websites"

@magento-engcom-team
Copy link
Contributor

Hi @mikelevy300. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1289 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@dianacle
Copy link

dianacle commented Jul 12, 2019

Hello, is this a regression or a breaking change in version > 2.2?

I tested the newsletter subscription in many version of magento ce.
It seems to me that:

  • in magento <= 2.1 (including magento 1.x) > newsletter subscription are unique per email (guest or customer doesn't matter, subscribing the same email for different store_id do overwrite previous record)
  • in magento version > 2.2 > newsletter subscription are unique per email/website (can subscribe the same email for different store_id of different websites, but not for store_id of same website)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Customer Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

9 participants