Skip to content

check for Guest validity in hookActionAuthentication#37

Open
mcaldex wants to merge 1 commit intoPrestaShop:devfrom
mcaldex:bugfix/authetication_id_guest
Open

check for Guest validity in hookActionAuthentication#37
mcaldex wants to merge 1 commit intoPrestaShop:devfrom
mcaldex:bugfix/authetication_id_guest

Conversation

@mcaldex
Copy link
Copy Markdown

@mcaldex mcaldex commented Oct 14, 2025

Questions Answers
Description? Sometimes the id_guest property of the cookie object retrieved from the hookActionAuthentication function is empty / invalid or just old. This can happen easily if the same guest submits the login form with valid data on the front office twice or more while being unlogged (he could simply click 2+ times on the login button for example), so the login procedure will succeed N times in N different php processes, and so the hookActionAuthentication function will be fired N times while containing the same id_guest: the issue here lies within the $guest->mergeWithCustomer() function call, which if it's called with an empty Guest object, it will execute this query: Db::getInstance()->update('cart', ['id_guest' => (int) $idGuest,], 'id_guest = ' . (int) $this->id); where $this->id will be equal to zero due to the fact that the same Guest object got deleted during the first login procedure by calling $guest->mergeWithCustomer(). That UPDATE query will set an id_guest for every cart in the database having id_guest = 0. Carts that have the id_guest set to 0 are temporary carts created from the Order creation page in the Backfofice. With this PR I'm proposing to check the validity of the Guest object before proceeeding to execute the hookActionAuthentication logic.
Type? bug fix
BC breaks? no
Deprecations? no
How to test? Please indicate how to best verify that this PR is correct.

@ps-jarvis
Copy link
Copy Markdown

Hello @mcaldex!

This is your first pull request on statsdata repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation bot moved this to Ready for review in PR Dashboard Oct 14, 2025
@mcaldex
Copy link
Copy Markdown
Author

mcaldex commented Oct 14, 2025

I've added some context for the issue I'm proposing to fix for this module.

@mcaldex mcaldex force-pushed the bugfix/authetication_id_guest branch from f50f13e to ffef876 Compare October 15, 2025 08:28
@mcaldex
Copy link
Copy Markdown
Author

mcaldex commented Oct 15, 2025

ping @kpodemski @nicosomb , what do you guys think?

Copy link
Copy Markdown
Contributor

@kpodemski kpodemski left a comment

Choose a reason for hiding this comment

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

Makes sense. I'm adding one suggestion to meet the coding requirements.

Copy link
Copy Markdown
Contributor

@kpodemski kpodemski left a comment

Choose a reason for hiding this comment

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

Hello @mcaldex

Your change makes sense, but you should target the dev branch.

@mcaldex mcaldex force-pushed the bugfix/authetication_id_guest branch from b0f7e21 to 04733a7 Compare March 25, 2026 14:10
@mcaldex mcaldex marked this pull request as draft March 25, 2026 14:14
@mcaldex mcaldex changed the base branch from master to dev March 25, 2026 14:15
@mcaldex mcaldex force-pushed the bugfix/authetication_id_guest branch from 04733a7 to faa9dc0 Compare March 25, 2026 14:19
@mcaldex mcaldex marked this pull request as ready for review March 25, 2026 14:19
@mcaldex
Copy link
Copy Markdown
Author

mcaldex commented Mar 25, 2026

done @kpodemski

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

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

3 participants