Discounts module
The Discounts module may initialize at any point, depending on the setup. To ensure your code runs when the Discounts module is ready, use the runIfModuleReady method available immediately after the gwSdkReady event is triggered.
This code ensures the callback runs immediately if the Discounts module is already initialized; if not, it runs once the module is ready.
function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.DISCOUNTS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
// The Discounts module is ready for use and available at `window.gw.sdk.discounts`
});
}
if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}