Skip to content

Refactor hookActionCustomerAccountAdd in ps_emailsubscription - #121

Merged
kpodemski merged 3 commits into
PrestaShop:devfrom
Codencode:refactor/email-subscription-cleanup-hook
Aug 29, 2026
Merged

Refactor hookActionCustomerAccountAdd in ps_emailsubscription#121
kpodemski merged 3 commits into
PrestaShop:devfrom
Codencode:refactor/email-subscription-cleanup-hook

Conversation

@Codencode

@Codencode Codencode commented Dec 7, 2025

Copy link
Copy Markdown
Member
Questions Answers
Description? This PR simplifies the hookActionCustomerAccountAdd logic by acting only on valid emails and newsletter-subscribed customers, removing unnecessary and unreachable code.

Related: #114 (comment)
Type? refacto
BC breaks? no
Deprecations? no
Fixed ticket?
How to test?

Touxten
Touxten previously approved these changes Jan 21, 2026
Comment thread ps_emailsubscription.php Outdated
$this->sendVoucher($email, $code);
}

return (bool) Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE id_shop=' . (int) $id_shop . ' AND email=\'' . pSQL($email) . "'");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (bool) Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE id_shop=' . (int) $id_shop . ' AND email=\'' . pSQL($email) . "'");
return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'emailsubscription` WHERE id_shop = ' . (int) $id_shop . 'AND email = "' . pSQL($email) . '"');

@Touxten Touxten Jan 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or only ' with slash ' ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Touxten, I based it on the previous code, but if you think it's better this way, I'll make the change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw that. What's causing me trouble is the mix of ' / ” at the end of the query.

I've validated the PR. I'll leave it up to you to choose :D Nice job !

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Touxten I made the change you suggested, it does look better stylistically :-)
Thanks!

Touxten
Touxten previously approved these changes Jan 21, 2026
@Codencode
Codencode requested a review from a team February 27, 2026 20:14
@Touxten Touxten closed this Feb 28, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Closed in PR Dashboard Feb 28, 2026
@Touxten Touxten reopened this Feb 28, 2026
@ps-jarvis ps-jarvis moved this from Closed to Ready for review in PR Dashboard Feb 28, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Reopened in PR Dashboard Feb 28, 2026
@Touxten

Touxten commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

I'm going to do a PR to correct the tests.

@Touxten

Touxten commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

#123

@Codencode
Codencode force-pushed the refactor/email-subscription-cleanup-hook branch from 3756e51 to b4ba7f6 Compare March 2, 2026 14:23
@Codencode

Copy link
Copy Markdown
Member Author

@Touxten your PR worked perfectly!

Thanks!

@Codencode

Copy link
Copy Markdown
Member Author

ping @kpodemski

kpodemski
kpodemski previously approved these changes Mar 25, 2026
@ps-jarvis ps-jarvis moved this from Reopened to To be tested in PR Dashboard Mar 25, 2026
@kpodemski kpodemski added Waiting for QA by Community Status: Action required, Waiting for test feedback by Community Waiting for QA and removed Waiting for QA Waiting for QA by Community Status: Action required, Waiting for test feedback by Community labels Mar 25, 2026
@paulnoelcholot paulnoelcholot self-assigned this Mar 26, 2026

@paulnoelcholot paulnoelcholot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Codencode,

I tested your PR and I found some bug :

Image
PR-2026-03-26_10.57.47.mp4

I have the problem when Double opt-in are activated or desactivated. And only for an account creation. I don't have this problem when I want to subscribe to the newsletter without creating an account.

Can you check that please?

Thanks!

@Codencode

Copy link
Copy Markdown
Member Author

Ping @Touxten @kpodemski

@Codencode Codencode added this to the 2.8.4 milestone May 26, 2026
@Codencode

Copy link
Copy Markdown
Member Author

@Touxten @kpodemski could you re-approve the PR with this fix in place?

@Codencode Codencode added the Waiting for QA by Community Status: Action required, Waiting for test feedback by Community label Jun 20, 2026
@mattgoud mattgoud modified the milestones: 2.8.4, 3.0.1 Jul 2, 2026
@Codencode
Codencode requested a review from paulnoelcholot July 9, 2026 12:15
@Touxten

Touxten commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Tests performed

Scenario 1 — Account created without newsletter subscription

  1. Subscribe to the newsletter without creating a customer account.
  2. Check that the email address exists in the ps_emailsubscription table.
  3. Create a customer account using the same email address.
  4. Do not select the newsletter checkbox.

Result: ✅ The customer remains subscribed, and the email address is still present in the ps_emailsubscription table.

test-pr-email.mp4

Scenario 2 — Account created with newsletter subscription

  1. Subscribe to the newsletter without creating a customer account.
  2. Check that the email address exists in the ps_emailsubscription table.
  3. Create a customer account using the same email address.
  4. Select the newsletter checkbox.

Result: ✅ The customer is subscribed through their customer account, and the email address is correctly removed from the ps_emailsubscription table.

test-pr-email-2.mp4

@kpodemski and @Codencode Is this really what I was supposed to test?

@Touxten Touxten added QA ✔️ Status: Check done, Code approved and removed Waiting for QA by Community Status: Action required, Waiting for test feedback by Community Waiting for QA labels Aug 28, 2026
@Touxten

Touxten commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

I wait before merge

@Touxten Touxten assigned Touxten and unassigned paulnoelcholot Aug 28, 2026
@Codencode

Copy link
Copy Markdown
Member Author

@Touxten
Thanks for the QA!

While preparing the How to test, I noticed that when a customer creates an account and subscribes to the newsletter, the method returns before reaching sendConfirmationEmail(). This means that even if NW_CONFIRMATION_EMAIL is enabled, the newsletter confirmation email is not sent in this case.

This behavior already exists today, so the PR does not introduce it, but I’d like to confirm whether it is actually expected.

If the email should be sent, I could update this PR to handle it, or would it be better to create a separate PR for that change?

@kpodemski, what do you think?

@kpodemski

Copy link
Copy Markdown
Contributor

@Codencode

If the confirmation is required, then the email should be sent. My understanding is that this person shouldn't be considered as an active subscriber for as long as they haven't confirmed their subscription, correct?

@Codencode

Copy link
Copy Markdown
Member Author

@kpodemski I was initially referring specifically to NW_CONFIRMATION_EMAIL and sendConfirmationEmail().

However, looking deeper into this, I found PrestaShop/PrestaShop#17097, which describes a broader issue with account creation: when a customer creates an account and subscribes to the newsletter, neither the verification email nor the confirmation email is sent, and the customer is immediately considered subscribed.

So I think there are actually two related cases here:

  • NW_CONFIRMATION_EMAIL: the confirmation email is currently never reached during account creation.
  • NW_VERIFICATION_EMAIL: if double opt-in is enabled, the customer should probably not be considered an active subscriber until the subscription is verified.

In my opinion, it would be better to merge this PR as it is and then open a separate PR to address both issues properly: sending the confirmation email and handling the verification email flow during account creation.

What do you think?

@Touxten

Touxten commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

I agree—in any case, it has nothing to do with this PR; we'd have to create another one.

@Codencode

Copy link
Copy Markdown
Member Author

Yes, I think so too. Let's wait for confirmation from @kpodemski, after which we can merge it and I'll create a separate PR.

Actually, it's almost ready, so as soon as we merge this one I'll publish it so we can verify and merge it in a way that the new module release will also include the new fixes.

@kpodemski
kpodemski merged commit 1d577e6 into PrestaShop:dev Aug 29, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from To be tested to Merged in PR Dashboard Aug 29, 2026
@kpodemski

Copy link
Copy Markdown
Contributor

This one is not related to my comment, merged 👍🏻 thanks guys

@Codencode
Codencode deleted the refactor/email-subscription-cleanup-hook branch August 29, 2026 12:16
@Codencode

Copy link
Copy Markdown
Member Author

New PR: #139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA ✔️ Status: Check done, Code approved

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

6 participants