Skip to content

Class: CartSession ​

Persistent, serialized cart state for one storefront instance.

Constructors ​

Constructor ​

new CartSession(options): CartSession

Parameters ​

options ​
client ​

ZynoSalesClient

storage ​

ZynoSalesStorage

storageKey ​

string

Returns ​

CartSession

Methods ​

abandon() ​

abandon(): Promise<void>

Abandons the current cart and removes its local capability.

Returns ​

Promise<void>


add() ​

add(item): Promise<CartSnapshot>

Adds a product to the cart, merging the same product/notes combination when possible.

Parameters ​

item ​

ISalesEcommCartItemInput

Returns ​

Promise<CartSnapshot>


clear() ​

clear(): void

Clears local cart state without issuing an API call.

Returns ​

void


getSnapshot() ​

getSnapshot(): CartSnapshot

Returns the latest render-safe cart snapshot.

Returns ​

CartSnapshot


refresh() ​

refresh(): Promise<CartSnapshot>

Reads the cart from Sales without creating a new cart.

Returns ​

Promise<CartSnapshot>


remove() ​

remove(input): Promise<CartSnapshot>

Removes an existing server cart item.

Parameters ​

input ​
cartItemId ​

string

Returns ​

Promise<CartSnapshot>


restore() ​

restore(): Promise<CartSnapshot>

Restores the persisted cart, clearing it when its capability is stale.

Returns ​

Promise<CartSnapshot>


setItems() ​

setItems(items): Promise<CartSnapshot>

Replaces all cart line inputs. An empty list abandons the open cart.

Parameters ​

items ​

ISalesEcommCartItemInput[]

Returns ​

Promise<CartSnapshot>


setQuantity() ​

setQuantity(input): Promise<CartSnapshot>

Updates an existing server cart item's quantity. A zero quantity removes it.

Parameters ​

input ​
cartItemId ​

string

qty ​

number

Returns ​

Promise<CartSnapshot>


subscribe() ​

subscribe(listener): () => void

Subscribes to render-safe cart changes. Capability values are never included.

Parameters ​

listener ​

(snapshot) => void

Returns ​

() => void


withServerAccess() ​

withServerAccess<T>(callback): Promise<T>

Provides cart capability access for one trusted merchant-server call. Treat the returned key as a secret and refresh the cart after server mutations.

Type Parameters ​

T ​

T

Parameters ​

callback ​

(access) => T | Promise<T>

Returns ​

Promise<T>

MIT Licensed