Skip to main content
Add a Store API route that returns a product’s or a store’s average rating, because core ships no public rating endpoint. You can call the Review module service’s rating helpers, which average every linked review, or compute the average from published reviews with query.graph.

Before you begin

Pick the approach that matches what should count toward the number:
  • Rating helpers: one SQL query per call; counts pending, rejected, and soft deleted reviews too
  • Published only: loads the target’s reviews with query.graph and averages the published ones
1

Return a store's average from the service

Resolve the service with MercurModules.REVIEW and call getAvgRating:
src/api/store/sellers/[id]/rating/route.ts
The first argument is "product" or "seller", the second the target’s id. The method returns a numeric string, or null when the target has no reviews, so the route converts it to a number.
2

Average published reviews only

Load the product’s linked reviews with query.graph and average the published ones:
src/api/store/products/[id]/rating/route.ts
reviews is the alias the product to review link adds to a product. Soft deleted reviews don’t come back from query.graph, so they never count.

Rate every product or store in one query

For list pages, getProductsWithRating and getSellersWithRating return every row of the product or seller table with its average joined in:
Pass column names of the target table. Each row gains a rating string, or null for rows without reviews. The helpers take no filters or pagination and include soft deleted products and sellers, so filter the result before you return it.

Next steps