Skip to content

k.commerce.wishlist ​

Wish list.

Execution ContextPrerequisitesTypical Use
KScript API (k.api.get / k.api.post), server-side <script env="server">Existing customer customerId and product variantIdRead, add, and remove saved product variants in a customer wishlist

k.commerce.wishlist manages saved customer product variants.

Note: At runtime add() and remove() return void; call k.commerce.wishlist.list(customerId) to inspect the updated wishlist.

Quick Start ​

js
k.api.get(() => {
    const customer = k.commerce.customer.getByEmail("test@kooboo.com")
    return customer ? k.commerce.wishlist.list(customer.id) : []
})

Quick Reference ​

Method / PropertyDescriptionReturns
list(customerId)Get wishlist items for a customerWishlistModel[]
add(customerId, variantId)Add a product variant to the customer wishlistvoid
remove(customerId, variantId)Remove a product variant from the customer wishlistvoid

list() ​

Gets a list of the specified customer's wish lists.

ParameterTypeRequiredDescription
customerIdstringYesCustomer ID

Returns: WishlistModel[]

js
k.api.get(() => {
    const customer = k.commerce.customer.getByEmail("test@kooboo.com")
    return k.commerce.wishlist.list(customer.id)
})

add() ​

Add an item to a specified customer's wish list.

ParameterTypeRequiredDescription
customerIdstringYesCustomer ID
variantIdstringYesProduct variant ID

Returns: void

js
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail("test@kooboo.com")
    const variantId = k.commerce.product.get("test-product").variants[0].id
    k.commerce.wishlist.add(customer.id, variantId)
    return { items: k.commerce.wishlist.list(customer.id) }
})

remove() ​

Removes an item from the specified customer's wish list.

ParameterTypeRequiredDescription
customerIdstringYesCustomer ID
variantIdstringYesProduct variant ID

Returns: void

js
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail("test@kooboo.com")
    const variantId = k.commerce.product.get("test-product").variants[0].id
    k.commerce.wishlist.remove(customer.id, variantId)
    return { items: k.commerce.wishlist.list(customer.id) }
})

Structure ​

WishlistModel Property ​

PropertyDescriptionType
customerIdCustomer IDstring
productIdProduct IDstring
variantIdVariant IDstring
getHashGuidHash identifier helper method() => any

TypeScript Definitions ​

Note: Kooboo's IDE type definitions declare add() and remove() as returning Customer (see Customer) due to [KDefineType(Return = typeof(Customer))], whereas both methods return void at runtime.

ts
interface KWishlist {
    add(customerId: string, variantId: string): Customer; // IDE d.ts declaration (returns void at runtime)
    remove(customerId: string, variantId: string): Customer; // IDE d.ts declaration (returns void at runtime)
    list(customerId: string): WishlistModel[];
}

interface WishlistModel {
    customerId: string;
    productId: string;
    variantId: string;
    getHashGuid(): any;
}