k.commerce.wishlist
Wish list.
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Existing customer customerId and product variantId | Read, add, and remove saved product variants in a customer wishlist |
k.commerce.wishlist manages saved customer product variants.
Note: At runtime
add()andremove()returnvoid; callk.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 / Property | Description | Returns |
|---|---|---|
list(customerId) | Get wishlist items for a customer | WishlistModel[] |
add(customerId, variantId) | Add a product variant to the customer wishlist | void |
remove(customerId, variantId) | Remove a product variant from the customer wishlist | void |
list()
Gets a list of the specified customer's wish lists.
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | Yes | Customer 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | Yes | Customer ID |
variantId | string | Yes | Product 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | string | Yes | Customer ID |
variantId | string | Yes | Product 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
| Property | Description | Type |
|---|---|---|
customerId | Customer ID | string |
productId | Product ID | string |
variantId | Variant ID | string |
getHashGuid | Hash identifier helper method | () => any |
TypeScript Definitions
Note: Kooboo's IDE type definitions declare
add()andremove()as returningCustomer(seeCustomer) due to[KDefineType(Return = typeof(Customer))], whereas both methods returnvoidat 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;
}Related Docs
- k.commerce - E-commerce module overview
- cart - Shopping Cart
- order - Order Management