Reviews and rating rollups on a product
Keep reviews in their own collection, each referencing the product it is about, with a number field for the rating. Add rollups to the product that count its reviews and average their ratings, filtered to published reviews, so the product always shows current numbers and an unapproved review never moves them.
Keep reviews in their own collection, each referencing the product it is about, with a number field for the rating. Add rollups to the product that count its reviews and average their ratings, filtered to published reviews, so the product always shows current numbers and an unapproved review never moves them.
Requirements
A role that can create collections and fields. For reviews submitted from your site: a connected website; see How collections power a site.
The model
- A Reviews collection. One entry per review, with a reference to the product it is about, a number field for the rating, and a text field for the review itself. A review has its own author, date, and text, which is why it is a collection rather than a field on the product; see New collection vs new field.
- A saved filter for published reviews. On the Reviews collection, save a filter that keeps only reviews whose status is published.
- Two rollups on the product. One counts the product's reviews, the other averages their rating. Both read reviews through the reference that points back at the product, and both use the published-reviews filter.
The product now shows, for example, 4.6 from 38 reviews, and the numbers update by themselves when a review is added, changed, or published. Rollup vs lookup explains rollups in general.
How reviews arrive and get approved
- Give your website permission to create entries in the Reviews collection, and nothing else there. A review form on a product page then writes a new review straight into the collection.
- New entries in a collection you created start as drafts. A submitted review is therefore invisible on the site and left out of the rollups until someone publishes it. Publishing is the approval.
- An automation can notify the team when a new review arrives. Set it to listen to entries created by the website; see Automation triggers.
Showing it on the site
The site reads the product with its rollup values, like any other field, and reads the published reviews for that product by filtering the Reviews collection on the product reference. Draft reviews never reach it.
Notes and limitations
- A rollup's average needs a number field as its source. A rating kept as a choice field cannot be averaged.
- Rollups are computed by the system and cannot be edited by hand or through an import.
- If a review's product is archived, the review's reference reads as empty and it no longer counts for any product.
- The same pattern fits any rated or counted relationship: a consultant's client scores, a property's inspection results, a supplier's delivery ratings.
Related
For the wider picture of running your site from Sonta, see Using Sonta as your site's backend.