Checkout
The checkout context in a StoreOS Fluid theme, with its route, widgets, data, how to place an order from the browser, and an example widget.
The checkout context is where a shopper enters their details and places the order for the products in their bag.
Route
/checkout
Widgets
The widgets listed under pages.checkout in the theme document, or layout/checkout.fluid.
{ "pages": { "checkout": ["main-checkout"] } }Give your theme a checkout. StoreOS's built-in checkout belongs to the catalog themes, so a Fluid theme without pages.checkout or layout/checkout.fluid has no checkout page.
Data
| Object | Contents |
|---|---|
page_title | Checkout |
Plus the data on every page. The server renders the page the same for every shopper, and StoreOS never indexes it: its SEO tags say noindex, nofollow.
The bag and the order are handled in the browser with the Storefront REST API at shop.api_url. Send the store's x-tenant header (shop.uid) with every call, and Authorization: Bearer <accessToken> when the shopper is signed in.
| What | Request |
|---|---|
| Store settings (delivery areas, payment methods, checkout fields) | GET /api/v1/tenant |
| Check a coupon | POST /api/v1/orders/coupons/verify |
| Place the order | POST /api/v1/orders |
POST /api/v1/orders takes the bag and the shopper's details:
{
"lineItems": [{ "productId": "…", "variantId": "…", "quantity": 2 }],
"customer": { "name": "Rahim", "phoneNumber": "01XXXXXXXXX", "email": "rahim@example.com" },
"shippingAddress": { "caption": "House 12, Road 5, Dhanmondi" },
"paymentMethod": "COD",
"deliveryArea": "Inside Dhaka",
"notes": "Call before delivery",
"couponCode": "SAVE10"
}The response has order (with invoiceUID) and, for online payment, payment.url. Send the shopper to payment.url when it's there; otherwise send them to /order-confirmation/<invoiceUID>. Clear the bag once the order is placed.
Example
{% comment %} widgets/main-checkout.fluid {% endcomment %}
<section class="checkout">
<h1>{{ page_title }}</h1>
<form data-checkout>
<input name="name" placeholder="Name" required>
<input name="phoneNumber" type="tel" placeholder="01XXXXXXXXX" required>
<textarea name="address" placeholder="House, road, area" required></textarea>
<button type="submit">Place order</button>
</form>
</section>
<script>
document.querySelector("[data-checkout]").addEventListener("submit", async (event) => {
event.preventDefault();
const { tenant, api } = JSON.parse(document.getElementById("store").textContent);
const form = new FormData(event.target);
const bag = JSON.parse(localStorage.getItem(`my_theme_bag_${tenant}`) || "[]");
const res = await fetch(`${api}/api/v1/orders`, {
method: "POST",
headers: { "x-tenant": tenant, "content-type": "application/json" },
body: JSON.stringify({
lineItems: bag.map(({ productId, variantId, quantity }) => ({ productId, variantId, quantity })),
customer: { name: form.get("name"), phoneNumber: form.get("phoneNumber") },
shippingAddress: { caption: form.get("address") },
paymentMethod: "COD",
}),
});
const { order, payment } = await res.json();
localStorage.removeItem(`my_theme_bag_${tenant}`);
location.assign(payment?.url || `/order-confirmation/${order.invoiceUID}`);
});
</script>The store script tag is the one from the shopper pages example. Keep the bag however your theme likes; this example reads it from localStorage.