Skip to main content
With the $wsProductRating module, you can load, check, and display product ratings in the frontend. Product ratings are an important element for purchasing decisions. They show customers the experiences of other buyers and increase trust in products.

Module overview

Example / excerpt of $wsProductRating
JSON output
Note: "ƒ()" denotes a function. Methods overview

Templates

Product ratings are typically displayed on the product detail page (product.htm). They can also be included on category pages or in the order history to prompt customers to leave a rating.

Variables

No variables are available for $wsProductRating.

Methods

$wsProductRating.checkRatingExistence()

Checks whether a rating already exists for a product in connection with an order. Signature
$wsProductRating.checkRatingExistence(productId, orderId)
Return value
bool - true if a rating exists, otherwise false.
Parameters Example that checks whether a rating exists.

$wsProductRating.loadAllProductRatings()

Loads all ratings of a product. Signature
$wsProductRating.loadAllProductRatings(productId)
Return value
array - List with all ratings of the product.
Parameters Example that loads all ratings of a product.

$wsProductRating.loadRatingStatistics()

Loads statistics for the ratings of a product. Signature
$wsProductRating.loadRatingStatistics(productId)
Return value
map - Map with rating statistics (e.g. average, count).
Parameters Example that loads the statistics of a product.

$wsProductRating.loadSingleRating()

Loads a single rating based on product and order ID. Signature
$wsProductRating.loadSingleRating(productId, orderId)
Return value
map - Map with the rating data.
Parameters Example that loads a single rating.

$wsProductRating.loadLatestRatingForAccount()

Loads the latest rating of the currently logged-in customer. Signature
$wsProductRating.loadLatestRatingForAccount()
Return value
map - Map with the rating data.
Example that loads the customer’s latest rating.

$wsProductRating.loadRatingByAccount()

Loads a product rating of the currently logged-in customer. Signature
$wsProductRating.loadRatingByAccount(productId)
Return value
map - Map with the customer’s rating data.
Parameters Example that loads the customer’s rating for a product.

Actions

No actions are available for $wsProductRating.

Examples

Display average rating

This example displays the average rating and the number of ratings of a product.

List all ratings of a product

This example loads and displays all ratings of a product.

Check whether the customer has already rated

This example checks whether the customer has already rated a product before the rating form is displayed.