You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes#135 by preserving existing emailsubscription records when a customer account is updated without changing the newsletter subscription status.
The customer is reloaded from the database to retrieve the newsletter state before the update, while the object received by the hook already contains the new value. Comparing both states allows the module to detect an actual newsletter subscription transition (0 -> 1) and remove the existing emailsubscription record only in that case.
I also added comments in both hookActionObjectCustomerUpdateBefore() and hookActionCustomerAccountUpdate() to clarify this behavior and make the relationship between the persisted newsletter state and the new customer state easier to understand.
1. Subscribe to the newsletter as a guest. 2. Create a customer account using the same email address without selecting the newsletter option. 3. Verify that the corresponding emailsubscription record is still present. 4. Update an unrelated customer field, such as the first name. 5. Verify that the emailsubscription record is preserved. 6. Enable the newsletter option from the customer account. 7. Verify that the emailsubscription record is removed and the customer newsletter status is enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
emailsubscriptionrecords when a customer account is updated without changing the newsletter subscription status.The customer is reloaded from the database to retrieve the newsletter state before the update, while the object received by the hook already contains the new value. Comparing both states allows the module to detect an actual newsletter subscription transition (
0 -> 1) and remove the existingemailsubscriptionrecord only in that case.I also added comments in both
hookActionObjectCustomerUpdateBefore()andhookActionCustomerAccountUpdate()to clarify this behavior and make the relationship between the persisted newsletter state and the new customer state easier to understand.2. Create a customer account using the same email address without selecting the newsletter option.
3. Verify that the corresponding
emailsubscriptionrecord is still present.4. Update an unrelated customer field, such as the first name.
5. Verify that the
emailsubscriptionrecord is preserved.6. Enable the newsletter option from the customer account.
7. Verify that the
emailsubscriptionrecord is removed and the customer newsletter status is enabled.