1 ---
2 tags:
3 - order
4 - storefront
5 products:
6 - order
7 ---
8
9 import { CodeTabs, CodeTab, Table, Prerequisites } from "docs-ui"
10
11 export const metadata = {
12 title: `Order Confirmation in Storefront`,
13 }
14
15 # {metadata.title}
16
17 In this guide, you'll learn how to show the different order details on the order confirmation page.
18
19 After the customer completes the checkout process and places an order, you can show an order confirmation page to display the order details.
20
21 <Note>
22
23 The [Get an Order API route](!api!/store/orders/get-an-order) doesn't require customer authentication, so that guest customers can view their order confirmation page. To add access rules to the route, refer to the [Restrict Order Retrieval guide](../../../commerce-modules/order/secure-order-retrieval/page.mdx).
24
25 </Note>
26
27 ## Retrieve Order Details
28
29 To show the order details, you need to retrieve the order by sending a request to the [Get an Order API route](!api!/store/orders/get-an-order).
30
31 You need the order's ID to retrieve the order. You can pass it from the [complete cart step](../complete-cart/page.mdx) or store it in the `localStorage`.
32
33 The following example assumes you already have the order ID:
34
35 <Note title="Tip">
36
37 Learn how to install and configure the JS SDK in the [JS SDK documentation](../../../js-sdk/page.mdx).
38
39 </Note>
40
41 <CodeTabs group="store-request">
42 <CodeTab label="React" value="react">
43
44 ```tsx
45 "use client" // include with Next.js 13+
46
47 import { HttpTypes } from "@medusajs/types"
48 import { useEffect } from "react"
49 import { useState } from "react"
50
51 export function OrderConfirmation({ id }: { id: string }) {
52 const [order, setOrder] = useState<HttpTypes.StoreOrder | undefined>()
53 const [loading, setLoading] = useState(true)
54
55 useEffect(() => {
56 sdk.store.order.retrieve(id)
57 .then(({ order: dataOrder }) => {
58 setOrder(dataOrder)
59 setLoading(false)
60 })
61 }, [id])
62
63 return (
64 <div>
65 {loading && <span>Loading...</span>}
66 {!loading && order && (
67 <div>
68 <h1>Order Confirmation</h1>
69 <p>Order ID: {order.id}</p>
70 <p>Order Date: {order.created_at.toLocaleString()}</p>
71 <p>Order Customer: {order.email}</p>
72 {/* TODO show more info */}
73 </div>
74 )}
75 </div>
76 )
77 }
78 ```
79
80 </CodeTab>
81 <CodeTab label="JS SDK" value="js-sdk">
82
83 ```ts
84 // orderId is the order ID which you can get from the complete cart step
85 sdk.store.order.retrieve(orderId)
86 .then(({ order }) => {
87 // use order...
88 console.log(order)
89 })
90 ```
91
92 </CodeTab>
93 </CodeTabs>
94
95 In the above example, you retrieve the order's details from the [Get an Order API route](!api!/store/orders/get-an-order). Then, in the React example, you show the order details like the order ID, order date, and customer email.
96
97 The rest of this guide will expand on the React example to show more order details.
98
99 <Note title="Tip">
100
101 Refer to the [Order schema in the API reference](!api!/store/orders/schema) for all the available order fields.
102
103 </Note>
104
105 ---
106
107 ## Show Order Items
108
109 An order has an `items` field that contains the order items. You can show the order items on the order confirmation page.
110
111 For example, add to the React component a `formatPrice` function to format prices with the order's currency:
112
113 ```tsx
114 const formatPrice = (amount: number): string => {
115 return new Intl.NumberFormat("en-US", {
116 style: "currency",
117 currency: order?.currency_code,
118 })
119 .format(amount)
120 }
121 ```
122
123 Since this is the same function used to format the prices of products and cart totals, you can define the function in one place and re-use it where necessary. In that case, make sure to pass the currency code as a parameter.
124
125 Then, you can show the order items in a list:
126
127 ```tsx
128 return (
129 <div>
130 {loading && <span>Loading...</span>}
131 {!loading && order && (
132 <div>
133 {/* ... */}
134 <p>
135 <span>Order Items</span>
136 <ul>
137 {order.items?.map((item) => (
138 <li key={item.id}>
139 {item.title} - {item.quantity} x {formatPrice(item.unit_price)}
140 </li>
141 ))}
142 </ul>
143 </p>
144 {/* TODO show more details */}
145 </div>
146 )}
147 </div>
148 )
149 ```
150
151 In the above example, you show the order items in a list, displaying the item's title, quantity, and unit price formatted with the `formatPrice` function.
152
153 ### Locale of Order Items
154
155 <Prerequisites
156 items={[
157 {
158 text: "Translation Module Configured",
159 link: "/commerce-modules/translation#configure-translation-module",
160 }
161 ]}
162 />
163
164 When you complete the cart, items in the order will be in the locale that was set for the cart. This ensures that the customer sees the order details in their preferred language.
165
166 If no locale was set for the cart, then the order's items will be in the original product content.
167
168 ---
169
170 ## Show Order Totals
171
172 An order has various fields for the order totals, which you can check out in the [Order schema in the Store API reference](https://docs.medusajs.com/api/store/orders/schema). The most commonly used fields are:
173
174 <Table>
175 <Table.Header>
176 <Table.Row>
177 <Table.HeaderCell>
178 Field
179 </Table.HeaderCell>
180 <Table.HeaderCell>
181 Description
182 </Table.HeaderCell>
183 </Table.Row>
184 </Table.Header>
185 <Table.Body>
186 <Table.Row>
187 <Table.Cell>
188 `subtotal`
189 </Table.Cell>
190 <Table.Cell>
191 The order's subtotal before discounts, excluding taxes. Calculated as the sum of `item_subtotal` and `shipping_subtotal`.
192 </Table.Cell>
193 </Table.Row>
194 <Table.Row>
195 <Table.Cell>
196 `discount_total`
197 </Table.Cell>
198 <Table.Cell>
199 The total amount of discounts applied to the order, including the tax portion of discounts.
200 </Table.Cell>
201 </Table.Row>
202 <Table.Row>
203 <Table.Cell>
204 `shipping_total`
205 </Table.Cell>
206 <Table.Cell>
207 The sum of all shipping methods' totals after discounts, including taxes.
208 </Table.Cell>
209 </Table.Row>
210 <Table.Row>
211 <Table.Cell>
212 `tax_total`
213 </Table.Cell>
214 <Table.Cell>
215 The order's tax total after discounts. Calculated as the sum of `item_tax_total` and `shipping_tax_total`.
216 </Table.Cell>
217 </Table.Row>
218 <Table.Row>
219 <Table.Cell>
220 `total`
221 </Table.Cell>
222 <Table.Cell>
223 The order's final total after discounts and credit lines, including taxes.
224 </Table.Cell>
225 </Table.Row>
226 </Table.Body>
227 </Table>
228
229 You can show these totals on the order confirmation page. For example:
230
231 ```tsx
232 return (
233 <div>
234 {loading && <span>Loading...</span>}
235 {!loading && order && (
236 <div>
237 {/* ... */}
238 <div>
239 <span>Order Totals</span>
240 <ul>
241 <li>
242 <span>Subtotal (excl. taxes)</span>
243 <span>{formatPrice(order.subtotal ?? 0)}</span>
244 </li>
245 <li>
246 <span>Discounts</span>
247 <span>{formatPrice(order.discount_total ?? 0)}</span>
248 </li>
249 <li>
250 <span>Shipping</span>
251 <span>{formatPrice(order.shipping_total ?? 0)}</span>
252 </li>
253 <li>
254 <span>Taxes</span>
255 <span>{formatPrice(order.tax_total ?? 0)}</span>
256 </li>
257 <li>
258 <span>Total</span>
259 <span>{formatPrice(order.total ?? 0)}</span>
260 </li>
261 </ul>
262 </div>
263 </div>
264 )}
265 </div>
266 )
267 ```
268
269 In the above example, you show the order totals in a list, displaying the subtotal, discounts, shipping, taxes, and total amount formatted with the [formatPrice function](#show-order-items).