Ecommerce Product Reviews

Adds product reviews and aggregate ratings to a Payload ecommerce shop, with verified-purchase detection and moderation before reviews go public.

Community 0 MIT v1.0.0

Installation

pnpm add payload-reviews

About

This plugin adds a reviews collection and two aggregate rating fields to a shop built with `@payloadcms/plugin-ecommerce`. It extends the ecommerce plugin rather than replacing it: the products collection gains `ratingAverage` and `ratingCount` fields, and a new `reviews` collection holds the rows that feed them. Reviews carry a product relationship, a rating between 1 and a configurable maximum, a title, a body, an author name and email, plus a `verifiedPurchase` flag and a `status` of pending, approved or rejected. The verified-purchase flag is computed, not self-reported. On every write that could change it, the plugin runs a single count query against the orders collection for an order whose status is in the configured purchase statuses (processing or completed by default), that carries the reviewed product on one of its lines, and that belongs to the reviewer either through a customer relationship or a customer email. An order belongs to a signed-in customer or carries an address, never both, so the query matches on either half. `cancelled` and `refunded` orders do not count. The aggregate rating is never incremented or decremented. Each time a review is created, changed or deleted, the product's rating is recounted from the approved rows in the `afterChange` and `afterDelete` hooks, running inside the same transaction as the triggering write. Count queries on indexed columns produce the number of reviews and the sum of ratings exactly, with no drift and no truncation. A rebuild endpoint recounts every product and accepts a bearer secret for unattended runs. Reading is public but narrowed: anyone who does not pass the admin access rule sees only approved reviews, through REST, GraphQL or the local API. Creating is open by default, while updating and deleting are closed to the admin rule. A submitter cannot approve their own review or set their own verified flag. Options cover the access rules, field and collection slugs, maximum lengths, the rating scale, whether to refuse a second review of the same product by the same person, and a `disabled` switch that stops the logic while leaving the schema intact.

Package info

Package name
payload-reviews
Latest version
1.0.0
Unpacked size
39 kB
License
MIT
Last publish
Aug 20, 2026

More from Poseidonas

View profile