-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: add option to aggregate similar products to verified reviews #634
Open
pedrobernardina
wants to merge
4
commits into
deco-cx:main
Choose a base branch
from
pedrobernardina:feat/verified-reviews-aggregate-similars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add option to aggregate similar products to verified reviews #634
pedrobernardina
wants to merge
4
commits into
deco-cx:main
from
pedrobernardina:feat/verified-reviews-aggregate-similars
Conversation
This file contains 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
pedrobernardina
force-pushed
the
feat/verified-reviews-aggregate-similars
branch
from
June 5, 2024 14:52
b729cb7
to
d05d067
Compare
gabrielMatosBoubee
requested changes
Jun 7, 2024
Comment on lines
+14
to
+23
let weightedRating = 0; | ||
let totalRatings = 0; | ||
|
||
Object.entries(ratings ?? {}).forEach(([_, [rating]]) => { | ||
const count = Number(rating.count); | ||
const value = Number(parseFloat(rating.rate).toFixed(1)); | ||
|
||
totalRatings += count; | ||
weightedRating += count * value; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use reduce:
const { weightedRating, totalRatings } = Object.entries(ratings ?? {}).reduce(
(acc, [_, ratingDetails]) => {
const count = Number(ratingDetails.count);
const value = Number(parseFloat(ratingDetails.rate).toFixed(1));
acc.totalRatings += count;
acc.weightedRating += count * value;
return acc;
},
{ weightedRating: 0, totalRatings: 0 }
);
@pedrobernardina Can you apply the @gabrielMatosBoubee suggestion? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In some segments it's common to register product variations as similar products instead of different SKUs. For instance, it's useful to register different colours of t-shirts as different products, otherwise the "colour - size" sku variations would be greater than some e-commerce support, although, in the end, they are the same product (e.g Camiseta Manga Curta Algodão Peruano). In these cases it's useful to aggregate the reviews of all similar products.
This PR makes some changes on the verified reviews loader and client in order to support this feature. The final rating is an weighted average of the rating of all similar products by their reviews count.
Obs: This branch was created from the one of #633 , so checking only the last commit will be easier to review the changes.
Obs2: There is a change on one method (client.reviews) that is breaking. The argument name was changed from "productId" to "productsIds". We can (i) add the latter as a new argument and change the logic a bit for it no to be breaking anymore; OR just keep the argument name as "productId" and extend it's type to "string | string[]", and check it before passing it to the function. The latter is cleaner, but the argument name is misleading.
This can be tested in the Admin by enabling the new option "aggregateSimilarProducts" and running the loader.
A local version (created on our repository) of both #633 and this PR can be seen in the preview bellow.
https://deco-sites-simples-f7ec095wncm9.deno.dev/camiseta-manga-curta-algodao-peruano-branca-0077065014/p