Skip to content

CartStore

new CartStore(options): CartStore

CartStoreOptions

CartStore

readonly currency: string


readonly storeKey: string

add(sku, quantity?): Promise<void>

Adds quantity of a SKU. The count moves at once; a refusal puts it back and says why in fault.

string

number = 1

Promise<void>


clear(): void

Removes both entries from this device and empties the snapshot. What “forget this device” calls: the entries hold the only copy of the cart token.

void


closeDrawer(): void

void


fetchEntitlements(entry): Promise<Entitlement[]>

OrderEntry

Promise<Entitlement[]>


fetchOrder(entry): Promise<"error" | Order | null>

Reads the pending order from Commerce with the cart token that placed it. null: Commerce has no such order for this token. 'error': the read failed (try again).

OrderEntry

Promise<"error" | Order | null>


getSnapshot(): CartSnapshot

CartSnapshot


markOrderPaid(entry): void

The confirmation saw the order paid: keep the pending order for a day (a reload still works), and drop the cart, so the next add starts a new one.

OrderEntry

void


openDrawer(): void

void


pay(input, redirect?): Promise<PayResult>

Sets the address, starts the checkout, writes the pending order and only then hands the provider’s address to redirect (location.assign by default). A second call while one is under way answers busy and sends nothing: one submit, one checkout. The cart stays in storage until the confirmation has seen the order paid, so a declined or abandoned payment finds it intact.

PayInput

(url) => void

Promise<PayResult>


readPendingOrder(): OrderEntry | null

The order a checkout started on this device, or null (none, expired, or seen paid more than a day ago).

OrderEntry | null


registerHeader(): () => void

A header cart button calls this while it is mounted: it speaks additions, so a buy button need not.

() => void


remove(sku): Promise<void>

string

Promise<void>


setAddress(delivery): Promise<ActionResult>

Gives the cart the shopper’s country (and what a parcel needs), so shipping and tax can be worked out. Resolves with the outcome instead of setting fault: the form says what is wrong.

Address

Promise<ActionResult>


setQuantity(sku, quantity): Promise<void>

Sets a line’s quantity (0 removes it).

string

number

Promise<void>


start(): () => void

Starts listening for another tab’s changes and, when this device already holds a cart, reads it once (the header’s count). A device that holds none does nothing at all. Calls nest: the returned function stops this caller, and the listeners go when the last caller stops (React’s strict mode starts, stops and starts again).

() => void


subscribe(listener): () => void

() => void

() => void