spiritracking-arch

payload plugin reviews

by spiritracking-arch
Stores & catalogs
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds a reviews collection to Payload v3 that links to a configurable products collection. Reviews have a 1-5 star rating and go through pending, approved or rejected moderation. Author email is hidden from the public API, and approved ratings can feed aggregateRating JSON-LD. The database table, API route and frontend components are set up by the developer.

Features

  • Star rating from 1 to 5 on each review
  • Moderation statuses: pending, approved and rejected
  • Verified purchase flag that only admins can set
  • Author email protected by field-level access control
  • Works with any products collection slug via an option
  • Optional admin email notification on new reviews

Use cases

  • Collect and moderate customer reviews on product pages of a Payload shop
  • Show average star ratings in Google search results using aggregateRating JSON-LD

From the author

A Payload CMS v3 plugin to add customer reviews with moderation, star ratings, and Google rich snippets support.

Installation

npm i payload-plugin-reviews

1

Stars

0

Forks

0

Open Issues

1 months ago

Last Updated

5

Weekly Downloads

v1.0.2

npm Version

13.6 KB

Unpacked Size

0

Dependencies

GitHub stars

1+1 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20261
Dec 4, 20261
Dec 3, 20261
Dec 2, 20261
Dec 1, 20261
Nov 30, 20261
Nov 29, 20261
Nov 28, 20261
Nov 27, 20261
Nov 26, 20261
Nov 25, 20261
Nov 24, 20261
Nov 23, 20261
Nov 22, 20261
Nov 21, 20261
Nov 20, 20261
Nov 19, 20261
Nov 18, 20261
Nov 17, 20261
Nov 16, 20261
Nov 15, 20261
Nov 14, 20261
Nov 13, 20261
Nov 12, 20261
Nov 11, 20261
Nov 10, 20261
Nov 9, 20261
Nov 8, 20261
Nov 7, 20261
Nov 6, 20261
Nov 5, 20261
Nov 4, 20261
Nov 3, 20261
Nov 2, 20261
Nov 1, 20261
Oct 31, 20261
Oct 30, 20261
Oct 29, 20261
Oct 28, 20261
Oct 27, 20261
Oct 26, 20261
Oct 25, 20261
Oct 24, 20261
Oct 23, 20261
Oct 22, 20261
Oct 21, 20261
Oct 20, 20261
Oct 19, 20261
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
Sep 12, 20260
Sep 11, 20260
Sep 10, 20260
Sep 9, 20260
Sep 8, 20260
Sep 7, 20260
Sep 6, 20260
npm weekly downloads

3−7 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20263
Dec 4, 20263
Dec 3, 20263
Dec 2, 20265
Dec 1, 20266
Nov 30, 20269
Nov 29, 20269
Nov 28, 20269
Nov 27, 20269
Nov 26, 20269
Nov 25, 20267
Nov 24, 20267
Nov 23, 20264
Nov 22, 20265
Nov 21, 20266
Nov 20, 20268
Nov 19, 202610
Nov 18, 202610
Nov 17, 20269
Nov 16, 202612
Nov 15, 202611
Nov 14, 202610
Nov 13, 20268
Nov 12, 202611
Nov 11, 202610
Nov 10, 202613
Nov 9, 202610
Nov 8, 202611
Nov 7, 202614
Nov 6, 202613
Nov 5, 20269
Nov 4, 20269
Nov 3, 20268
Nov 2, 202610
Nov 1, 20269
Oct 31, 20267
Oct 30, 20268
Oct 29, 20267
Oct 28, 20267
Oct 27, 20268
Oct 26, 20267
Oct 25, 20269
Oct 24, 202612
Oct 23, 202611
Oct 22, 202633
Oct 21, 202655
Oct 20, 2026340
Oct 19, 2026339
Oct 18, 2026336
Oct 17, 2026333
Oct 16, 2026333
Oct 15, 2026312
Oct 14, 2026290
Oct 13, 20262
Oct 12, 20262
Oct 11, 20263
Oct 10, 20262
Oct 9, 20262
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20260
Oct 3, 20260
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20262
Sep 26, 20265
Sep 25, 20265
Sep 24, 20265
Sep 23, 20265
Sep 22, 20266
Sep 21, 20266
Sep 20, 20266
Sep 19, 20263
Sep 18, 20263
Sep 17, 20265
Sep 16, 20266
Sep 15, 20266
Sep 14, 20269
Sep 13, 20269
Sep 12, 20269
Sep 11, 20269
Sep 10, 20267
Sep 9, 20269
Sep 8, 20269
Sep 7, 202610
Sep 6, 202610

Each point is npm's rolling 7-day download count.

Health Score

60/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1270699948-root.svg)](https://payloaddirectory.dev/plugins/1270699948-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1270699948-root"><img src="https://payloaddirectory.dev/badge/1270699948-root.svg" alt="Payload Directory"></a>
Updated Oct 11, 2026Created Jun 16, 2026Published Oct 11, 2026

README

payload-plugin-reviews

npm version npm downloads GitHub stars Payload v3 License: MIT

A Payload CMS v3 ecommerce plugin to add customer reviews with moderation, star ratings, and Google rich snippets (Schema.org) support.

⭐ If this plugin saves you time, star it on GitHub. It is the main way other Payload developers find it.

Features

  • ⭐ Star rating system (1–5)
  • 🛡️ Admin moderation (pending / approved / rejected)
  • ✔️ Verified purchase badge (admin-only)
  • 📧 Author email hidden from public API
  • 🔍 Google rich snippets ready (Schema.org aggregateRating)
  • 🌐 Works with any products collection slug

Installation

npm install payload-plugin-reviews

Usage

1. Add the plugin to your Payload config

// payload.config.ts
import { reviewsPlugin } from 'payload-plugin-reviews'

export default buildConfig({
  plugins: [
    reviewsPlugin({
      productsCollection: 'products', // default
    }),
  ],
})

2. Create the database table

⚠️ If Payload is running in dev mode (migration batch -1), the table won't be created automatically. Run this SQL manually:

CREATE TYPE "public"."enum_reviews_status" AS ENUM('pending', 'approved', 'rejected');

CREATE TABLE IF NOT EXISTS "reviews" (
  "id" serial PRIMARY KEY,
  "product_id" integer NOT NULL REFERENCES "products"("id") ON DELETE SET NULL,
  "author_name" varchar NOT NULL,
  "author_email" varchar NOT NULL,
  "rating" numeric NOT NULL,
  "title" varchar,
  "comment" varchar NOT NULL,
  "verified" boolean DEFAULT false,
  "status" "enum_reviews_status" DEFAULT 'pending',
  "updated_at" timestamp(3) with time zone NOT NULL DEFAULT now(),
  "created_at" timestamp(3) with time zone NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS "reviews_created_at_idx" ON "reviews" USING btree ("created_at");

ALTER TABLE "payload_locked_documents_rels"
  ADD COLUMN IF NOT EXISTS "reviews_id" integer REFERENCES "reviews"("id") ON DELETE CASCADE;

CREATE INDEX IF NOT EXISTS "payload_locked_documents_rels_reviews_id_idx"
  ON "payload_locked_documents_rels" USING btree ("reviews_id");

3. Add the API route (Next.js App Router)

Create src/app/(app)/api/reviews/product/[productId]/route.ts:

import configPromise from '@payload-config'
import { getPayload } from 'payload'
import { NextRequest } from 'next/server'

export async function GET(
  req: NextRequest,
  { params }: { params: Promise<{ productId: string }> }
) {
  const { productId } = await params
  const payload = await getPayload({ config: configPromise })

  const reviews = await payload.find({
    collection: 'reviews',
    where: {
      and: [
        { product: { equals: parseInt(productId, 10) } },
        { status: { equals: 'approved' } },
      ],
    },
    sort: '-createdAt',
    limit: 50,
  })

  const avg =
    reviews.docs.length > 0
      ? reviews.docs.reduce((acc, r) => acc + (r.rating as number), 0) / reviews.docs.length
      : 0

  return Response.json({
    docs: reviews.docs,
    totalDocs: reviews.totalDocs,
    averageRating: Math.round(avg * 10) / 10,
  })
}

4. Add frontend components

Copy the following components to your project:

  • StarRating.tsx — star display and interactive picker
  • ReviewForm.tsx — public review submission form
  • ReviewsList.tsx — reviews list with average, distribution bars, and form toggle

See the /examples folder for full source.

5. Add to your product page

import { ReviewsList } from '@/components/ReviewsList'

// In your product page component:
<ReviewsList productId={`${product.id}`} />

In your product page, fetch reviews server-side and include aggregateRating in your JSON-LD:

const reviewsData = await payload.find({
  collection: 'reviews',
  where: {
    and: [
      { product: { equals: product.id } },
      { status: { equals: 'approved' } },
    ],
  },
  pagination: false,
})

const avg = reviewsData.docs.length > 0
  ? reviewsData.docs.reduce((a, b) => a + (b.rating as number), 0) / reviewsData.docs.length
  : 0

const productJsonLd = {
  '@context': 'https://schema.org',
  '@type': 'Product',
  name: product.title,
  ...(reviewsData.docs.length > 0 ? {
    aggregateRating: {
      '@type': 'AggregateRating',
      ratingValue: Math.round(avg * 10) / 10,
      reviewCount: reviewsData.docs.length,
      bestRating: 5,
      worstRating: 1,
    }
  } : {}),
  offers: {
    '@type': 'AggregateOffer',
    price: product.price / 100, // prices stored in cents
    priceCurrency: 'EUR',
  },
}

Test your rich snippets: Google Rich Results Test This article summarizes the functions on: dev.to

Plugin Options

OptionTypeDefaultDescription
enabledbooleantrueEnable or disable the plugin
productsCollectionstring'products'Slug of your products collection
adminEmailstringundefinedEmail to notify on new review (requires email adapter)

Notes

  • parseInt(productId, 10) is required when submitting reviews — Payload rejects string IDs for relationship fields.
  • verified is always reset to false on creation — only admins can mark a review as verified purchase.
  • Author email is protected by field-level access control — never exposed in the public API.
  • Prices in cents — if your prices are stored in cents (e.g. 3990 = €39.90), divide by 100 in JSON-LD and frontend display.

About the author

I'm Camille Guerineau. I spent ten years as a jewelry maker and founder of Loch Ness Paris before going back to full-stack development. I build Payload CMS shops for real e-commerce, and I publish the pieces that were missing.

  • 🧩 Also by me: payload-plugin-seo-jsonld, Schema.org JSON-LD for Product, BreadcrumbList, ItemList, WebSite and Organization
  • ✅ Verumano, a verifiable "human-made" label for creators, with an open spec and an npm client (verumano)
  • ✍️ Writing on dev.to
  • 💬 Questions, bugs or ideas: open an issue

Need help with a Payload CMS v3 shop, SEO or rich snippets? Get in touch through lochness-paris.com.

License

MIT © Camille Guerineau

Similar plugins