Skip to main content

createWishlistItem

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

sdk.wishlists.methods.createWishlistItem()
function
createWishlistItem(productId: number, variantId: number, wishlistId?: number): Promise<Success | ErrorResult>
Parameters
productIdnumber
ID of the product to be added to the wishlist
variantIdnumber
Variant 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

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