Skip to main content

createWishlistItem()

createWishlistItem(productId, variantId, wishlistId?): Promise<Success | ErrorResult>

Creates a wishlist item using productId, variantId and wishlistId parameters.

Parameters​

ParameterTypeDescription
productIdnumberID of the product to be added to the wishlist
variantIdnumberVariant ID of the product
wishlistId?number(Optional) ID of the wishlist where the item will be added. If not provided, the item is created in the latest wishlist.

Returns​

Promise<Success | ErrorResult>

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

Example​

Ensure the SDK and the WishlistsSdk module are ready.

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.WISHLISTS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
window.gw.sdk.wishlists.methods.createWishlistItem(123, 456, 789)
.then(console.log)
.catch(console.error);
});
}

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