order
Cancel an order, order it again, send its invoice, and read orders, shipments and pickup branches in the browser.
Use Salla.order for actions on the customer's orders, such as the buttons on an order page. To load orders for a page, use the order API module in a loader.
export function ReorderButton({ orderId }: { orderId: number }) {
return <button onClick={() => window.salla?.order.createCartFromOrder(orderId)}>Order again</button>;
}On an order page you can leave the id out: the SDK uses the page's id (Salla.config.get('page.id')).
Actions
| Method | Parameters | Does |
|---|---|---|
cancel | orderId?, { reasons?, reason_note? }? | Cancels the order. reasons is a list of reason ids. |
createCartFromOrder | orderId? | Puts the order's items in a new cart, then goes to the address in the response (the checkout) |
reorderProduct | productId? | Orders one product again, then goes to the address in the response |
sendInvoice | { id }? | Emails the order's invoice to the customer |
editOrder | orderId, payload | Saves a change to an order the store lets customers edit |
cancelEditSession | orderId | Ends an order edit without saving |
show | { id, url } | Goes to url after an order is placed, and tells the Salla app when the page runs inside it |
Read
| Method | Parameters | Returns |
|---|---|---|
fetch | { status?, page?, ... }? | The customer's orders |
getDetails | orderId? | One order |
getShipments | orderId?, signal? | The order's shipments, with their products. Pass an AbortSignal to cancel. |
getBranchDetails | orderId? | The branch an order is picked up from |
Events
| Event | Fires when | Arguments |
|---|---|---|
order::canceled / order::not.canceled | cancel | response or error, order id |
order::order.created / order::order.creation.failed | createCartFromOrder, reorderProduct | response or error, id |
order::invoice.sent / order::invoice.not.sent | sendInvoice | response or error, order id |
order::order.edited / order::order.not.edited | editOrder | response or error, order id |
order::edit.session.canceled / order::edit.session.not.canceled | cancelEditSession | response or error, order id |
order::order.fetched / order::order.not.fetched | fetch | response or error |
order::details.fetched / order::details.not.fetched | getDetails | response or error, order id |
order::branch.details.fetched / order::branch.details.not.fetched | getBranchDetails | response or error, order id |
getShipments fires no events.
Gotchas
createCartFromOrderandreorderProductleave the page when they succeed.createCartFromOrderalso forgets the old cart in the browser first.- The event for
fetch(the list) isorder::order.fetched. The event forgetDetails(one order) isorder::details.fetched. cancelsends only reasons that are not empty, and a note only when there are reasons.