Simple reviews and ratings for Medusajs
If you are not familiar with Medusa, you can learn more on the project web site.
Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.
- Adds review object and data repository
- Adds endpoints for retrieving reviews by product and by customer
- Adds endpoint for adding a review
- By default, reviews are set with field
approved
tofalse
(boolean) - Until Medusa adds extensibility for the admin app, approval must be done manually in the database.
yarn add medusa-plugin-ratings
medusa migrations run
Enable in your medusa-config.js file similar to other plugins:
const plugins = [
...
{
resolve: `medusa-plugin-ratings`,
options: {
enableUI: true
}
},
...
]
Frontend code examples are not currently included. API is detailed below.
Returns a json object with an array of reviews for the product with the given id
Returns a json object with an array of reviews for the logged in customer
Returns a json object with the review with the given id
Adds a review for the product with the given id. The request must come from a logged in customer. The body of the request should be a json object with the following properties:
{
display_name: string!,
content: string!,
rating: number.min(0).max(5)!
}
Updates a review with the given id. The request must come from a logged in customer. Will not update if the logged in customer is not the customer who created the review. The body of the request should be a json object with the following properties:
{
display_name: string!,
content: string!,
rating: number.min(0).max(5)!
}
When a customer updates a review, the approved boolean is set back to false. It can then be re-reviewed and reapproved.
Returns a json object with an array of reviews for the product with the given id. The request must come from a logged in admin user.
Returns a json object with an array of reviews for the customer with the given customer id. The request must come from a logged in admin user.
Updates a review with the given id. The request must come from a logged in admin user. The body of the request should be a json object with the following properties:
{
display_name: string!,
content: string!,
rating: number.min(0).max(5)!,
approved: boolean!
}
Deletes the review with the given id. Not a soft delete. The request must come from a logged in admin user.