Skip to content

Commit

Permalink
return full float in getAverageRating instead of rounded value
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jun 11, 2024
1 parent e1050b1 commit 769fd9b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 769fd9b

Please sign in to comment.