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

Actions overview

ActionDescription
ProductRatingAddCreates a new product rating.
ProductRatingUpdateEdits an existing product rating.
ProductRatingDeleteDeletes 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
NameDescription
productIdThe ID of the product to be rated.
orderIdThe ID of the order to which the rating belongs.
pointsThe rating in points (e.g., 1-5 stars).
subjectThe title of the rating.
descriptionThe rating text.
anonymousIndicates whether the rating should be submitted anonymously.
Error codes
Error codeDescription
notLoggedInThe user is not logged in.
missingProductIdParameter productId is missing.
missingOrderIdParameter orderId is missing.
missingPointsParameter points is missing.
ratingAlreadyExistsA rating already exists for this product and this order.
Related modules, variables & methods Example showing how a logged-in customer can rate a product with star rating, title, and comment, including success output.
{{ 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
NameDescription
productIdThe ID of the product whose rating should be edited.
orderIdThe ID of the order to which the rating belongs.
pointsThe new rating in points.
subjectThe new title of the rating.
descriptionThe new rating text.
anonymousIndicates whether the rating should be submitted anonymously.
Error codes
Error codeDescription
notLoggedInThe user is not logged in.
missingProductIdParameter productId is missing.
missingOrderIdParameter orderId is missing.
invalidRatingThe rating does not exist or does not belong to this customer account.
Related modules, variables & methods Example showing how a customer can edit an existing rating with pre-filled fields.
{{ 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
NameDescription
productIdThe ID of the product whose rating should be deleted.
orderIdThe ID of the order to which the rating belongs.
Error codes
Error codeDescription
notLoggedInThe user is not logged in.
missingProductIdParameter productId is missing.
missingOrderIdParameter orderId is missing.
invalidRatingThe rating does not exist or does not belong to this customer account.
Related modules, variables & methods Example showing how a rating is deleted via a button.
{{ 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>