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

Fix productcomments when not logged #213

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

CedricKiwik
Copy link

Questions Answers
Description? When a customer is not logged, it is possible to publish a review if the customer informations are in the cookie. We should check if the customer is logged or not with $this->context->customer->isLogged() instead of checking the cookie.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket?
How to test? Go to Back Office, configure module productcomments and disallow guest to post reviews. Go to Front Office and post a review in a product : if you are not logged a error message should display, if you are logged then the review is posted.

@ps-jarvis
Copy link

Hello @CedricKiwik!

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

Thank you, and welcome to this Open Source community!

@leemyongpakva
Copy link
Contributor

In usual procedures, you need to create an issue at PrestaShop/issues first. Once QA team confirmed the issue, you can fill it here into the Fixed ticket? section, then we can proceed the PR.

@Hlavtox
Copy link
Contributor

Hlavtox commented Oct 29, 2024

@florine2623 This is a legit fix. I did not test it, but by looking at the code, I can see the issue.

$context->cookie->id_customer will be filled also if you fill data in checkout as a guest, and that's not precise. 👍

Thanks @CedricKiwik 👍

Copy link
Contributor

@florine2623 florine2623 left a comment

Choose a reason for hiding this comment

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

Hello @CedricKiwik ,

Could you show how to check the information of a logged-in customer or not in the cookie ?
In the traditional way of logging into your customer account, I can't reproduce the issue.

Screen.Recording.2024-10-29.at.15.17.37.mov

Waiting for your feedback :)
Thanks!

@CedricKiwik
Copy link
Author

Hello @florine2623,
Unfortunately, I didn’t record my screen when I noticed the bug.
However, I know how to reproduce it, though it’s a bit complicated.
You need to wait until you are automatically logged out from the PrestaShop store’s front end.
In this case, the 'Post a review' button appears on the product pages when it shouldn't.
If a review is posted, there’s no immediate error, but during the review's database save, the customer_name field is missing :
image
This causes an error in the structured data :
image

However, when logging out using the logout button, there are no issues; the button to post reviews does not appear.

Finally, upon looking at the code in controllers/front/PostComment.php line 37, we realize that we are using $this->context->cookie->id_customer to check if the customer is logged but we should use $this->context->customer->isLogged() instead.

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.

5 participants