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

Impossible to load the Yotpo Reviews Widget if a product doesn't have a primary category #21

Open
gchapot opened this issue Jul 5, 2024 · 0 comments

Comments

@gchapot
Copy link

gchapot commented Jul 5, 2024

There is a small bug in the yotpoUtils.js file that causes the function getRatingsOrReviewsData() to return an empty object when there is no Primary Category on a Product. The current check cat.parent != null fails if cat itself is null.

Affected File

Current Code
while (cat.parent != null) { if (cat.online) { path[0] = cat.getDisplayName(); } cat = cat.parent; }

Issue
The condition cat.parent != null does not account for the case when cat is null. This can lead to an error and cause the function getRatingsOrReviewsData() to return an empty object.

Proposed Fix
Update the while loop condition to check if cat is not null before accessing cat.parent. This ensures that the loop only executes when cat is a valid object.

Suggested Code Change
while (cat && cat.parent != null) { if (cat.online) { path[0] = cat.getDisplayName(); } cat = cat.parent; }

With this change, the productCategory will be empty if cat is null, but all other data will remain intact. This prevents the function from returning an empty object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant