From 769fd9bcf79e987a09321742e865d710478e4f70 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 11 Jun 2024 07:37:34 +0400 Subject: [PATCH] return full float in getAverageRating instead of rounded value --- src/models/Product.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/models/Product.php b/src/models/Product.php index 8fb9c1f..ee87bd6 100644 --- a/src/models/Product.php +++ b/src/models/Product.php @@ -276,19 +276,17 @@ public function getAverageRating(): float -- get IDs of all clients who purchased current product SELECT DISTINCT o.client_id FROM `order` o - JOIN order_product op ON o.order_id = op.order_id - WHERE op.product_id = r.product_id + JOIN order_product op + ON o.order_id = op.order_id + AND op.product_id = r.product_id ) EOL; - $params = ['product_id' => $this->product_id]; - - $result = $this->query($query, $params); + $result = $this->query($query, ['product_id' => $this->product_id]); // Extract the average rating from the result array if (!empty($result)) { - $averageRating = $result[0]->average_rating; - return $averageRating !== null ? round((float)$averageRating, 2) : 0; // Round to two decimal places + return (float)$result[0]->average_rating; } return 0; // No reviews, return 0 as the average rating