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.

app/components/order/ReorderButton.tsx
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

MethodParametersDoes
cancelorderId?, { reasons?, reason_note? }?Cancels the order. reasons is a list of reason ids.
createCartFromOrderorderId?Puts the order's items in a new cart, then goes to the address in the response (the checkout)
reorderProductproductId?Orders one product again, then goes to the address in the response
sendInvoice{ id }?Emails the order's invoice to the customer
editOrderorderId, payloadSaves a change to an order the store lets customers edit
cancelEditSessionorderIdEnds 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

MethodParametersReturns
fetch{ status?, page?, ... }?The customer's orders
getDetailsorderId?One order
getShipmentsorderId?, signal?The order's shipments, with their products. Pass an AbortSignal to cancel.
getBranchDetailsorderId?The branch an order is picked up from

Events

EventFires whenArguments
order::canceled / order::not.canceledcancelresponse or error, order id
order::order.created / order::order.creation.failedcreateCartFromOrder, reorderProductresponse or error, id
order::invoice.sent / order::invoice.not.sentsendInvoiceresponse or error, order id
order::order.edited / order::order.not.editededitOrderresponse or error, order id
order::edit.session.canceled / order::edit.session.not.canceledcancelEditSessionresponse or error, order id
order::order.fetched / order::order.not.fetchedfetchresponse or error
order::details.fetched / order::details.not.fetchedgetDetailsresponse or error, order id
order::branch.details.fetched / order::branch.details.not.fetchedgetBranchDetailsresponse or error, order id

getShipments fires no events.

Gotchas

  • createCartFromOrder and reorderProduct leave the page when they succeed. createCartFromOrder also forgets the old cart in the browser first.
  • The event for fetch (the list) is order::order.fetched. The event for getDetails (one order) is order::details.fetched.
  • cancel sends only reasons that are not empty, and a note only when there are reasons.

See also

On this page