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.
sdk.wishlists.methods.getWishlistsSharedStateKit()getWishlistsSharedStateKit(): Promise<ErrorResult | SuccessResult<WishlistsSharedStateKit>>Returns
Promise<ErrorResult | SuccessResult<WishlistsSharedStateKit>>Promise that resolves to a success result with a state kit object containing query and service methods
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
WishlistsSharedStateKitProperties
readonly queryWishlistsSharedStateKitQueryWrapper- Query methods for accessing wishlist state (read-only)
readonly serviceWishlistsSharedStateKitServiceWrapper- Service methods for modifying wishlists
WishlistsSharedStateKitQueryWrapper
WishlistsSharedStateKitQueryWrapperMethods
selectDefault()Observable<WishlistSdkDto | undefined>- Select the default wishlist from the state. If no default wishlist exists, falls back to the first wishlist.
selectEntity(id)Observable<WishlistSdkDto | undefined>- Select a specific wishlist by ID
selectFirst()Observable<WishlistSdkDto | undefined>- Select the first wishlist from the state
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the default wishlist or undefined if none exist
Parameters
| Name | Type | Description |
|---|---|---|
| id | number | The wishlist ID |
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the wishlist or undefined if not found
Returns:
Observable<WishlistSdkDto | undefined>
Observable that emits the first wishlist or undefined if none exist
WishlistsSharedStateKitServiceWrapper
WishlistsSharedStateKitServiceWrapperMethods
addItem(params)Observable<WishlistItemSdkDto>- Add an item to a wishlist
deleteItem(params)Observable<WishlistItemSdkDto[]>- Delete an item from a wishlist
getWishlists()Observable<WishlistSdkDto[]>- Fetch all wishlists from the server and return them from state
Parameters
| Name | Type | Description |
|---|---|---|
| params | { productId: number; variantId: number; wishlistId: number | null } | Parameters for adding item |
Parameters
| Name | Type | Description |
|---|---|---|
| params | { productId: number; variantId?: number; wishlistId?: number } | Parameters for deleting item |
WishlistSdkDto
WishlistSdkDtoProperties
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
WishlistItemSdkDtoProperties
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