Skip to main content

openLeaveReviewModal

This method attempts to open the Leave Review modal.

sdk.reviews.methods.openLeaveReviewModal()
function
openLeaveReviewModal(params?: { productId?: number }): Promise<Success | ErrorResult>
Parameters
params?{ productId?: number }
(Optional) Parameters object
Returns
Promise<Success | ErrorResult>

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

Usage 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);
}