Skip to main content

Wishlist item created

This event is triggered when an item is created in a wishlist. It provides details about the wishlist and the item that was added.

Event details​

WishlistItemCreatedSdkEvent
event
Properties
readonly productIdnumber
ID of the product that was added to the wishlist
readonly typeWISHLIST_ITEM_CREATED
Event type, which is "wishlistItemCreated"
readonly variantIdnumber
ID of the product variant that was added
readonly wishlistIdnumber
ID of the wishlist where the item was created

Usage example​

Before listening for the wishlistItemCreated event, ensure the SDK and the Wishlists module are ready:

function subscribeToWishlistItemCreated() {
const wishlistItemCreatedEventType =
window.gw.sdk.wishlists.events.WISHLIST_ITEM_CREATED;

window.gw.sdk.on(wishlistItemCreatedEventType, (event) => {
console.log(event.detail);
});
}

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

window.gw.sdk.runIfModuleReady(moduleName, () => {
subscribeToWishlistItemCreated();
});
}

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

// Example output:
// {type: 'wishlistItemCreated', wishlistId: 123, productId: 456, variantId: 789}

This code ensures the SDK and the Wishlists module are ready before setting up the event listener, allowing you to respond when an item is created in a wishlist and access the relevant details.