Skip to main content

getWishlistsSharedStateKit

Retrieves a reactive state kit object that provides access to wishlists query and service methods with Observable streams. This allows you to subscribe to wishlist changes and interact with the wishlist store reactively.

info

Learn more about the StateKit guide for working with reactive state management.

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.getWishlistsSharedStateKit()
.then((response) => {
const stateKit = response.result;

// Subscribe to all wishlists changes (reactive)
stateKit.query.selectAll().subscribe((wishlists) => {
console.log('Wishlists:', wishlists);
});

// Subscribe to a specific wishlist
stateKit.query.selectEntity(123).subscribe((wishlist) => {
console.log('Wishlist 123:', wishlist);
});

// Add item using state kit service
stateKit.service.addItem({
productId: 456,
variantId: 789,
wishlistId: null
}).subscribe();
})
.catch(console.error);
});
}

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

Types​

WishlistsSharedStateKit​

WishlistsSharedStateKitQueryWrapper​

WishlistsSharedStateKitQueryWrapper
interface
Methods
selectAll()Observable<WishlistSdkDto[]>
Select all wishlists from the state
Returns:
Observable<WishlistSdkDto[]>
Observable that emits array of all wishlists
selectDefault()Observable<WishlistSdkDto | undefined>
Select the default wishlist from the state. If no default wishlist exists, falls back to the first wishlist.
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the default wishlist or undefined if none exist
selectEntity(id)Observable<WishlistSdkDto | undefined>
Select a specific wishlist by ID
Parameters
NameTypeDescription
idnumberThe wishlist ID
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the wishlist or undefined if not found
selectFirst()Observable<WishlistSdkDto | undefined>
Select the first wishlist from the state
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the first wishlist or undefined if none exist

WishlistsSharedStateKitServiceWrapper​

WishlistsSharedStateKitServiceWrapper
interface
Methods
addItem(params)Observable<WishlistItemSdkDto>
Add an item to a wishlist
Parameters
NameTypeDescription
params{ productId: number; variantId: number; wishlistId: number | null }Parameters for adding item
Returns:
Observable<WishlistItemSdkDto>
Observable that emits the added wishlist item
deleteItem(params)Observable<WishlistItemSdkDto[]>
Delete an item from a wishlist
Parameters
NameTypeDescription
params{ productId: number; variantId?: number; wishlistId?: number }Parameters for deleting item
Returns:
Observable<WishlistItemSdkDto[]>
Observable that emits array of deleted wishlist items
getWishlists()Observable<WishlistSdkDto[]>
Fetch all wishlists from the server and return them from state
Returns:
Observable<WishlistSdkDto[]>
Observable that emits array of all wishlists

WishlistSdkDto​

WishlistSdkDto
interface
Properties
customerIdnumber
ID of the customer who owns this wishlist
idnumber
Unique wishlist ID
isDefaultboolean
Whether this is the default wishlist
isPrivateboolean
Whether wishlist is private
itemsWishlistItemSdkDto[]
Array of items in the wishlist
titlestring
Wishlist title/name
totalCountnumber
Total count of items

WishlistItemSdkDto​

WishlistItemSdkDto
interface
Properties
customerIdnumber
ID of the customer who owns this wishlist item
datestring
ISO date string when item was added
productIdnumber
Shopify product ID
quantitynumber
Quantity of this item
variantIdnumber
Shopify variant ID
wishlistIdnumber
ID of the wishlist this item belongs to