📝 Product-Specific Reviews
This guide focuses on managing and displaying reviews for individual products using the Alphabite Reviews Plugin.
✅ Prerequisites
- A Medusa backend with the Reviews plugin installed and configured.
- Existing reviews associated with products.
🔨 Step-by-Step Implementation
1. List Reviews for a Product
To get all reviews for a specific product, use the listProductReviews
endpoint.
- Using SDK
- Using REST (Medusa SDK or fetch)
const { reviews, count } = await sdk.alphabite.reviews.listProductReviews({
product_id: "prod_...",
limit: 10,
offset: 0,
// Optional filters:
// my_reviews_only: true,
// verified_purchase_only: true,
// rating: 4,
// sort: "created_at", // or "rating"
// order: "desc", // or "asc"
});
console.log(`Found ${count} reviews for product:`, reviews);
import { ListProductReviewsInput, ListProductReviewsOutput } from "@alphabite/medusa-sdk";
const { reviews, count } = await sdk.client.fetch<ListProductReviewsOutput>(`/store/reviews/product/prod_...`, {
method: "GET",
query: {
limit: 10,
offset: 0,
// Optional filters:
// my_reviews_only: true,
// verified_purchase_only: true,
// rating: 4,
// sort: "created_at",
// order: "desc",
} as ListProductReviewsInput,
});
console.log(`Found ${count} reviews for product:`, reviews);
2. Get Aggregate Counts for a Product
To retrieve the average rating and distribution of ratings for a product, use the aggregateCounts
endpoint.
- Using SDK
- Using REST (Medusa SDK or fetch)
const { average, counts, total_count } = await sdk.alphabite.reviews.aggregateCounts({
product_id: "prod_...",
// Optional filter:
// verified_purchase_only: true,
});
console.log(`Average rating: ${average}`);
console.log(`Total reviews: ${total_count}`);
console.log("Rating distribution:", counts);
import { AggregateCountsInput, AggregateCountsOutput } from "@alphabite/medusa-sdk";
const { average, counts, total_count } = await sdk.client.fetch<AggregateCountsOutput>(
`/store/reviews/product/prod_.../aggregate-counts`,
{
method: "GET",
query: {
// Optional filter:
// verified_purchase_only: true,
} as AggregateCountsInput,
}
);
console.log(`Average rating: ${average}`);
console.log(`Total reviews: ${total_count}`);
console.log("Rating distribution:", counts);
API Reference
Learn more about our Medusa SDK Wrapper Alphabite Medusa SDK Wrapper 🔗
You can view the full endpoint documentation for:
📝 Notes
- The
listProductReviews
endpoint allows filtering bymy_reviews_only
,verified_purchase_only
,rating
, and sorting bycreated_at
orrating
. - The
aggregateCounts
endpoint provides a quick summary of review data for a product, useful for displaying star ratings and review counts on product listings.
🔗 Related
- Docs: Alphabite Medusa SDK Wrapper
- Docs: List Product Reviews - GET /store/reviews/product/:product_id
- Docs: Aggregate Counts - GET /store/reviews/product/:product_id/aggregate-counts