Abdullah Afzal

Software Engineer

Back

medusa-product-reviews

A plugin that enables customer product reviews for your Medusa store.

Documentation

If you are not familiar with Medusa, you can learn more on the project web site.

Note: This plugin will be migrated to Medusa v2, when v2 will reach production readiness.

What is it?

A plugin that enables customer product reviews for your Medusa store.

Installation

  1. Install the package with yarn add medusa-product-reviews or npm i medusa-product-reviews
  2. In medusa-config.js, add the plugin to the plugins array and set enableUI
  3. const plugins = [
          // ... other plugins
          {
            resolve: `medusa-product-reviews`,
            options: {
              enableUI: true
            }
          }
        ]
        
  4. Run migrations, e.g. npx medusa migrations run (see: https://docs.medusajs.com/development/entities/migrations/overview) as the plugin uses new tables.
  5. Start project
    • After installation of the plugin, you will see a new option on the sidebar named Reviews.
    • You can check reviews for each product on the single product details page.
    • You can check reviews for an order on the order details page.

API Endpoints

Store API Endpoints

  1. GET /store/product-reviews
    • Description: Retrieves a list of product reviews based on the provided query parameters.
    • Query Parameters:
      • order_id: (Optional) Filters reviews by a specific order.
      • product_id: (Optional) Filters reviews by a specific product.
      • customer_id: (Optional) Filters reviews by a specific customer.
      • rating: (Optional) Filters reviews by a specific rating.
      • limit: (Optional) Number of reviews to return.
      • offset: (Optional) Number of reviews to skip before starting to return results.
    • Response: Returns a JSON object containing an array of review objects and the total count.
    • Sample Response:
      {
            "reviews": [
              {
                "id": "string",
                "product_id": "string",
                "customer_id": "string",
                "order_id": "string",
                "rating": 5,
                "content": "Great product!",
                "images": ["image1.jpg", "image2.jpg"],
                "created_at": "2023-08-24T12:34:56.789Z",
                "updated_at": "2023-08-24T12:34:56.789Z"
              }
            ],
            "count": 1
          }
  2. GET /store/product-reviews/stats
    • Description: Retrieves statistics for product reviews, including average rating and distribution by rating.
    • Query Parameters:
      • product_id: (Required) The product ID for which to retrieve statistics.
    • Response: Returns a JSON object containing review statistics.
    • Sample Response:
      {
            "stats": {
              "product_id": "string",
              "average": 4.5,
              "count": 10,
              "by_rating": [
                { "rating": 5, "count": 6 },
                { "rating": 4, "count": 3 },
                { "rating": 3, "count": 1 }
              ]
            }
          }
  3. POST /store/product-reviews
    • Description: Creates a new product review.
    • Request Body:
      • product_id: (Required) The ID of the product being reviewed.
      • order_id: (Required) The ID of the order associated with the review.
      • rating: (Required) The rating given to the product.
      • content: (Optional) The content of the review.
      • images: (Optional) An array of image URLs or files associated with the review.
    • Response: Returns a JSON object containing the newly created review.
    • Sample Response:
      {
            "review": {
              "id": "string",
              "product_id": "string",
              "customer_id": "string",
              "order_id": "string",
              "rating": 5,
              "content": "Great product!",
              "images": ["image1.jpg", "image2.jpg"],
              "created_at": "2023-08-24T12:34:56.789Z",
              "updated_at": "2023-08-24T12:34:56.789Z"
            }
          }
  4. POST /store/product-reviews/:product_review_id
    • Description: Updates an existing product review by ID.
    • Request Body:
      • product_id: (Required) The ID of the product being reviewed.
      • order_id: (Required) The ID of the order associated with the review.
      • rating: (Required) The rating given to the product.
      • content: (Optional) The updated content of the review.
      • images: (Optional) An array of updated image URLs or files associated with the review.
    • Response: Returns a JSON object containing the updated review.
    • Sample Response:
      {
            "review": {
              "id": "string",
              "product_id": "string",
              "customer_id": "string",
              "order_id": "string",
              "rating": 5,
              "content": "Updated review content.",
              "images": ["image1.jpg", "image2.jpg"],
              "created_at": "2023-08-24T12:34:56.789Z",
              "updated_at": "2023-08-24T12:34:56.789Z"
            }
          }

Admin API Endpoints

  1. GET /admin/product-reviews/stats
    • Description: Retrieves statistics for product reviews, including average rating and distribution by rating.
    • Query Parameters:
      • product_id: (Required) The product ID for which to retrieve statistics.
    • Response: Returns a JSON object containing review statistics (same format as store endpoint).
  2. GET /admin/product-reviews
    • Description: Retrieves a list of product reviews based on the provided query parameters.
    • Query Parameters: Same as the GET /store/product-reviews endpoint.
    • Response: Returns a JSON object containing an array of review objects and the total count.
  3. POST /admin/product-reviews/:product_review_id
    • Description: Updates the reply to an existing product review by ID.
    • Request Body:
      • reply: (Required) The updated reply to the review.
    • Response: Returns a JSON object containing the updated review with the new reply.
  4. DELETE /admin/product-reviews/:id
    • Description: Deletes an existing product review by ID.
    • Response: Returns a JSON object indicating success.
    • Sample Response:
      {
            "success": true
          }

Objects

product-reviews: {
      "id": "string",
      "product_id": "string",
      "customer_id": "string",
      "order_id": "string",
      "rating": 5,
      "content": "Great product!",
      "reply": "Thank you for your feedback!",
      "images": ["image1.jpg", "image2.jpg"],
      "created_at": "2023-08-24T12:34:56.789Z",
      "updated_at": "2023-08-24T12:34:56.789Z",
      "deleted_at": null
    }

Proposals, Bugs, Improvements

If you have an idea for what could be the next highest priority functionality, do not hesitate to raise an issue here: Github issues.

Pro Version

The Pro version of medusa-product-reviews expands on the features of the free version with more advanced capabilities such as:

The Pro version is available under a commercial license. Contact abdullah-afzal for more information.

Hide Pro Version Tab

We show what advanced features we offer in the "Pro version" tab. We try to keep it non-intrusive, but if you feel otherwise, you can always hide this tab by setting the following environment variable:

MEDUSA_ADMIN_PRODUCTS_REVIEWS_HIDE_PRO=true

After restarting your admin application, this tab will be hidden.

Contact