getReviews
Retrieves reviews for a specific product or all shop reviews with filtering and pagination options.
sdk.reviews.methods.getReviews()getReviews(params?: GetReviewsParamsSdkDto): Promise<ErrorResult | SuccessResult<ReviewsSdkDto>>Parameters
params?GetReviewsParamsSdkDto- (Optional) Parameters object for filtering and pagination
Returns
Promise<ErrorResult | SuccessResult<ReviewsSdkDto>>Promise that resolves to a success result with an array of reviews or rejects with an error
Usage example
Ensure the SDK and the ReviewsSdk module are ready.
function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
// Get reviews for a specific product with pagination
window.gw.sdk.reviews.methods.getReviews({
productId: 123,
perPage: 10,
offset: 0
})
.then((response) => {
console.log('Product reviews:', response.result);
})
.catch(console.error);
// Get shop reviews with filters
window.gw.sdk.reviews.methods.getReviews({
onlyShopReviews: true,
onlyWithPhotos: true,
lowestRating: 4
})
.then((response) => {
console.log('Filtered shop reviews:', response.result);
})
.catch(console.error);
// Get reviews with no filters
window.gw.sdk.reviews.methods.getReviews()
.then((response) => {
console.log('Reviews:', response.result.items);
console.log('Total:', response.result.totalCount);
})
.catch(console.error);
});
}
if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}