[4.x] Get reviews aggregations via php#50
Conversation
| $reviewsCountPerStar = []; | ||
| for ($i = 1; $i <= $stars; $i++) { | ||
| $reviewsCountPerStar[$i] = 0; | ||
| foreach ($reviewsGroupedByAveragePercent as $averagePercent => $reviewsCount) { | ||
| if (ceil($averagePercent / (100 / $stars)) == $i) { | ||
| $reviewsCountPerStar[$i] += $reviewsCount; | ||
| } | ||
| } |
There was a problem hiding this comment.
Doing it this way ensures we don't drop any ratings in shops that allow multiple ratings to be given per review.
e.g. 5 stars for quality, 4 stars for service would be (100 + 80) / 2 = 90
The previous calculation would leave this out entirely ratings?.filter(e => e.average_rating == {{ $i * 20 }}) while this new calculation rounds it up.
| }); | ||
| }); | ||
|
|
||
| config('rapidez.models.product')::macro('reviewCountPerStar', function (int $stars = 5) { |
There was a problem hiding this comment.
I find this function quite weird. If we're using stars, that's always a 1-5 scale. But here you can choose whether it's up to 5 or something else. Maybe a more fitting name could be reviewCountBuckets, then it would at least make sense to me.
|
|
||
| public function ratingOptionVotes(): HasMany | ||
| { | ||
| return $this->hasMany(RatingOptionVote::class, 'review_id'); |
There was a problem hiding this comment.
The models config should be used instead of using the model classes directly here.
This PR gets the aggregated review counts using the backend. Getting rid of a graphql query requesting a size of 9999

Ref: RAP-1572