Skip to main content

openLeaveReviewModal()

openLeaveReviewModal(params?): Promise<Success | ErrorResult>

This method attempts to open the Leave Review modal.

Parameters​

ParameterTypeDescription
params?{ productId?: number; }(Optional) Parameters object
params.productId?number(Optional) ID of the product to leave a review for. If not provided, opens modal for shop review.

Returns​

Promise<Success | ErrorResult>

Promise that either resolves to a success result or rejects with an error

Example​

Ensure the SDK and the Reviews module are ready (the form modal is registered automatically inside the Reviews application, so waiting for a specific widget injection event is not required):

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;

window.gw.sdk.runIfModuleReady(moduleName, () => {
// Open modal for a specific product
window.gw.sdk.reviews.methods.openLeaveReviewModal({
productId: 123
})
.then(console.log)
.catch(console.error);

// Open modal for shop review (no productId)
window.gw.sdk.reviews.methods.openLeaveReviewModal()
.then(console.log)
.catch(console.error);
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}