> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# ProductRating

> Reference for WEBSALE product rating actions used to create, edit and delete customer ratings on product detail pages in the frontend.

This section describes the available actions in the product ratings area. With these actions, ratings can be created, edited, and deleted.

***

## Actions overview

| **Action**            | **Description**                     |
| --------------------- | ----------------------------------- |
| `ProductRatingAdd`    | Creates a new product rating.       |
| `ProductRatingUpdate` | Edits an existing product rating.   |
| `ProductRatingDelete` | Deletes an existing product rating. |

***

## Actions

### ProductRatingAdd

This action creates a new rating for a product. The customer must be logged in for this.

**Usage example**\
Can be used on the product detail page or in the order history to give logged-in customers the option to rate a purchased product.

**Parameters**

| **Name**      | **Description**                                               |
| ------------- | ------------------------------------------------------------- |
| `productId`   | The ID of the product to be rated.                            |
| `orderId`     | The ID of the order to which the rating belongs.              |
| `points`      | The rating in points (e.g., 1-5 stars).                       |
| `subject`     | The title of the rating.                                      |
| `description` | The rating text.                                              |
| `anonymous`   | Indicates whether the rating should be submitted anonymously. |

**Error codes**

| **Error code**        | **Description**                                          |
| --------------------- | -------------------------------------------------------- |
| `notLoggedIn`         | The user is not logged in.                               |
| `missingProductId`    | Parameter `productId` is missing.                        |
| `missingOrderId`      | Parameter `orderId` is missing.                          |
| `missingPoints`       | Parameter `points` is missing.                           |
| `ratingAlreadyExists` | A rating already exists for this product and this order. |

**Related modules, variables & methods**

* [\$wsProductRating](/en/frontend/referenz/module/wsproductrating)
* [\$wsProductRating.checkRatingExistence()](/en/frontend/referenz/module/wsproductrating#\$wsproductrating-checkratingexistence)
* [\$wsProductRating.loadAllProductRatings()](/en/frontend/referenz/module/wsproductrating#\$wsproductrating-loadallproductratings)
* [\$wsAccount.isLoggedIn](/en/frontend/referenz/module/wsAccount#\$wsaccount-isloggedin)

**Example** showing how a logged-in customer can rate a product with star rating, title, and comment, including success output.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionProductRatingAdd = $wsActions.create("ProductRatingAdd") }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionProductRatingAdd.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionProductRatingAdd.id }}">
    <input type="hidden" name="productId" value="{{= $myProduct.id }}">
    <input type="hidden" name="orderId" value="{{= $myOrderId }}">
    <input type="hidden" name="points" value="{{= $myActionProductRatingAdd.fields.points | ifNull(1) }}">
    <input type="text" name="subject">
    <textarea name="description"></textarea>
    <button type="submit">Submit rating.</button>
</form>
```

***

### ProductRatingUpdate

This action edits an existing product rating of the logged-in customer.

**Usage example**\
Can be used on the product detail page or in the customer account when a customer wants to subsequently adjust the rating they have submitted.

**Parameters**

| **Name**      | **Description**                                               |
| ------------- | ------------------------------------------------------------- |
| `productId`   | The ID of the product whose rating should be edited.          |
| `orderId`     | The ID of the order to which the rating belongs.              |
| `points`      | The new rating in points.                                     |
| `subject`     | The new title of the rating.                                  |
| `description` | The new rating text.                                          |
| `anonymous`   | Indicates whether the rating should be submitted anonymously. |

**Error codes**

| **Error code**     | **Description**                                                        |
| ------------------ | ---------------------------------------------------------------------- |
| `notLoggedIn`      | The user is not logged in.                                             |
| `missingProductId` | Parameter `productId` is missing.                                      |
| `missingOrderId`   | Parameter `orderId` is missing.                                        |
| `invalidRating`    | The rating does not exist or does not belong to this customer account. |

**Related modules, variables & methods**

* [\$wsProductRating](/en/frontend/referenz/aktionen/productrating)
* [\$wsProductRating.loadSingleRating()](/en/frontend/referenz/module/wsproductrating#\$wsproductrating-loadsinglerating)
* [\$wsProductRating.loadRatingByAccount()](/en/frontend/referenz/module/wsproductrating#\$wsproductrating-loadratingbyaccount)
* [\$wsAccount.isLoggedIn](/en/frontend/referenz/module/wsAccount#\$wsaccount-isloggedin)

**Example** showing how a customer can edit an existing rating with pre-filled fields.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionProductRatingUpdate = $wsActions.create("ProductRatingUpdate") }}
{{ var $myRating = $wsProductRating.loadSingleRating($myProduct, $myOrderId) }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionProductRatingUpdate.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionProductRatingUpdate.id }}">
    <input type="hidden" name="productId" value="{{= $myProduct }}">
    <input type="hidden" name="orderId" value="{{= $myOrderId }}">
    <input type="hidden" name="points" value="{{= $myRating.points | ifNull(1) }}">
    <input type="text" name="subject" value="{{= $myRating.subject | ifNull('') }}">
    <textarea name="description">{{= $myRating.description | ifNull('') }}</textarea>
    <button type="submit">Update rating.</button>
</form>
```

***

### ProductRatingDelete

This action deletes an existing product rating of the logged-in customer.

**Usage example**\
Can be used on the product detail page or in the customer account when a customer wants to remove the rating they have submitted.

**Parameters**

| **Name**    | **Description**                                       |
| ----------- | ----------------------------------------------------- |
| `productId` | The ID of the product whose rating should be deleted. |
| `orderId`   | The ID of the order to which the rating belongs.      |

**Error codes**

| **Error code**     | **Description**                                                        |
| ------------------ | ---------------------------------------------------------------------- |
| `notLoggedIn`      | The user is not logged in.                                             |
| `missingProductId` | Parameter `productId` is missing.                                      |
| `missingOrderId`   | Parameter `orderId` is missing.                                        |
| `invalidRating`    | The rating does not exist or does not belong to this customer account. |

**Related modules, variables & methods**

* [\$wsProductRating](/en/frontend/referenz/aktionen/productrating)
* [\$wsProductRating.loadRatingByAccount()](/en/frontend/referenz/module/wsproductrating#\$wsproductrating-loadratingbyaccount)
* [\$wsAccount.isLoggedIn](/en/frontend/referenz/module/wsAccount#\$wsaccount-isloggedin)

**Example** showing how a rating is deleted via a button.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ var $myActionProductRatingDelete = $wsActions.create("ProductRatingDelete") }}
<form method="post" action="{{= $wsViews.current.url() }}">
    <input type="hidden" name="wscsrf" value="{{= $myActionProductRatingDelete.csrf }}">
    <input type="hidden" name="wsact" value="{{= $myActionProductRatingDelete.id }}">
    <input type="hidden" name="productId" value="{{= $myProduct.id }}">
    <input type="hidden" name="orderId" value="{{= $myOrderId }}">
    <button type="submit">Delete rating.</button>
</form>
```
