CartStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CartStore(
options):CartStore
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”CartStore
Properties
Section titled “Properties”currency
Section titled “currency”
readonlycurrency:string
storeKey
Section titled “storeKey”
readonlystoreKey:string
Methods
Section titled “Methods”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.
Parameters
Section titled “Parameters”string
quantity?
Section titled “quantity?”number = 1
Returns
Section titled “Returns”Promise<void>
clear()
Section titled “clear()”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.
Returns
Section titled “Returns”void
closeDrawer()
Section titled “closeDrawer()”closeDrawer():
void
Returns
Section titled “Returns”void
fetchEntitlements()
Section titled “fetchEntitlements()”fetchEntitlements(
entry):Promise<Entitlement[]>
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<Entitlement[]>
fetchOrder()
Section titled “fetchOrder()”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).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<"error" | Order | null>
getSnapshot()
Section titled “getSnapshot()”getSnapshot():
CartSnapshot
Returns
Section titled “Returns”markOrderPaid()
Section titled “markOrderPaid()”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.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
openDrawer()
Section titled “openDrawer()”openDrawer():
void
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”redirect?
Section titled “redirect?”(url) => void
Returns
Section titled “Returns”Promise<PayResult>
readPendingOrder()
Section titled “readPendingOrder()”readPendingOrder():
OrderEntry|null
The order a checkout started on this device, or null (none, expired, or seen paid more than a day ago).
Returns
Section titled “Returns”OrderEntry | null
registerHeader()
Section titled “registerHeader()”registerHeader(): () =>
void
A header cart button calls this while it is mounted: it speaks additions, so a buy button need not.
Returns
Section titled “Returns”() => void
remove()
Section titled “remove()”remove(
sku):Promise<void>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
setAddress()
Section titled “setAddress()”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.
Parameters
Section titled “Parameters”delivery
Section titled “delivery”Address
Returns
Section titled “Returns”Promise<ActionResult>
setQuantity()
Section titled “setQuantity()”setQuantity(
sku,quantity):Promise<void>
Sets a line’s quantity (0 removes it).
Parameters
Section titled “Parameters”string
quantity
Section titled “quantity”number
Returns
Section titled “Returns”Promise<void>
start()
Section titled “start()”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).
Returns
Section titled “Returns”() => void
subscribe()
Section titled “subscribe()”subscribe(
listener): () =>void
Parameters
Section titled “Parameters”listener
Section titled “listener”() => void
Returns
Section titled “Returns”() => void