SDK
Order
Fetch order details for confirmation pages and order tracking
Overview
The order resource provides access to order details for:
- Order confirmation pages - Display order summary after successful payment
- Order tracking - Show shipment status and tracking information
- Order detail views - Display full order information to customers
This resource returns the raw order data as stored in the database, including line items, customer delivery info, and shipment tracking.
Note: For customer order history in account pages, use customer.getOrders() instead, which returns orders with enhanced product information.
Methods
order.get(orderId, options?)
Fetch complete order details by order ID.
const order = await storefront.order.get(orderId);
console.log(`Order #${order.orderNumber}: ${order.status}`);
console.log(`Total: ${order.totalAmount / 100} EUR`);Parameters:
| Param | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | Order ID |
options | FetchOptions | No | Fetch options (caching, etc.) |
Returns: Promise<Order>
Throws:
NotFoundError- Order not found or belongs to different store
Usage Examples
Order Confirmation Page
// app/payment/success/[orderId]/page.tsx
import { storefront } from '@/lib/storefront';
import type { Order } from '@putiikkipalvelu/storefront-sdk';
export default async function OrderConfirmationPage({
params,
}: {
params: Promise<{ orderId: string }>;
}) {
const { orderId } = await params;
let order: Order | null = null;
try {
order = await storefront.order.get(orderId);
} catch {
order = null;
}
if (!order) {
return <div>Order not found</div>;
}
return (
<div>
<h1>Thank you for your order!</h1>
<p>Order #{order.orderNumber}</p>
<p>Status: {order.status}</p>
<p>Total: {order.totalAmount / 100} EUR</p>
<h2>Order Items</h2>
{order.OrderLineItems
.filter(item => item.itemType !== 'SHIPPING')
.map(item => (
<div key={item.id}>
<p>{item.name} x{item.quantity}</p>
<p>{item.totalAmount / 100} EUR</p>
</div>
))}
</div>
);
}Display Tracking Information
const order = await storefront.order.get(orderId);
if (order.orderShipmentMethod?.trackingNumber) {
console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);
order.orderShipmentMethod.trackingUrls?.forEach(url => {
console.log(`Track at: ${url}`);
});
}Display Customer Delivery Info
const order = await storefront.order.get(orderId);
if (order.orderCustomerData) {
const customer = order.orderCustomerData;
console.log(`Delivering to: ${customer.firstName} ${customer.lastName}`);
console.log(`Address: ${customer.address}`);
console.log(`${customer.postalCode} ${customer.city}`);
}Next.js Caching
// Cache for 1 minute
const order = await storefront.order.get(orderId, {
next: { revalidate: 60, tags: ['order', orderId] }
});
// No caching (always fresh)
const order = await storefront.order.get(orderId, {
cache: 'no-store'
});Error Handling
import { NotFoundError } from '@putiikkipalvelu/storefront-sdk';
import { notFound } from 'next/navigation';
try {
const order = await storefront.order.get(orderId);
// Display order...
} catch (error) {
if (error instanceof NotFoundError) {
notFound();
}
throw error;
}TypeScript Types
// Order status values
type ConfirmationOrderStatus =
| 'PENDING'
| 'PAID'
| 'SHIPPED'
| 'DELIVERED'
| 'CANCELLED'
| 'REFUNDED';
// Line item type
type ConfirmationItemType = 'PRODUCT' | 'VARIATION' | 'SHIPPING';
// Order line item
interface ConfirmationOrderLineItem {
id: string;
orderId: string;
itemType: ConfirmationItemType;
quantity: number;
price: number; // Price per unit in cents
totalAmount: number; // Total in cents
productCode: string;
name: string;
vatRate: number;
images: string[];
}
// Customer delivery info
interface ConfirmationOrderCustomerData {
id: string;
firstName: string;
lastName: string;
email: string;
phone: string | null;
address: string;
city: string;
postalCode: string;
}
// Shipment method with tracking
interface ConfirmationOrderShipmentMethod {
id: string;
serviceId: string | null;
name: string;
description: string | null;
logo: string | null;
price: number; // In cents
orderId: string;
vatRate: number | null;
trackingNumber: string | null;
trackingUrls: string[];
shipmentNumber: string | null;
freightDoc: string[];
}
// Complete order
interface Order {
id: string;
storeId: string;
createdAt: string;
totalAmount: number; // Total in cents
status: ConfirmationOrderStatus;
orderNumber: number;
OrderLineItems: ConfirmationOrderLineItem[];
orderCustomerData: ConfirmationOrderCustomerData | null;
orderShipmentMethod: ConfirmationOrderShipmentMethod | null;
}Order vs CustomerOrder
The SDK has two different order types for different use cases:
| Type | Use Case | Source |
|---|---|---|
Order | Order confirmation, order detail pages | order.get(orderId) |
CustomerOrder | Customer order history in account pages | customer.getOrders() |
Key differences:
Orderhas raw line items withimagesarray directlyCustomerOrderhas line items with nestedproductobject containing enhanced info (slug, variation options)Order.orderNumberis a number,CustomerOrder.orderNumberis a stringOrderincludes more shipment details (trackingNumber, trackingUrls)