# order (https://docs.salla.dev/twilight/react/sdk/order)



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](https://docs.salla.dev/twilight/react/api/modules/order) in a loader.

```tsx title="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 [#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 [#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 [#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 [#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 [#see-also]

* [`order` API module](https://docs.salla.dev/twilight/react/api/modules/order)
* [Account orders route](https://docs.salla.dev/twilight/react/routes/account-orders)
* [Rating](https://docs.salla.dev/twilight/react/sdk/rating)
