Carts & Checkout
Create carts, add items, apply discounts, checkout flow
Carts & Checkout
Flow
Add items to cart → Update quantity → Apply discount code → Checkout (convert to order)Add Items
Use the SDK's Cart API to add items to the cart.
const item = await client.cart.addItem({
cartId: 'cart_id',
product: 'product_id',
variant: 'variant_id',
option: 'option_id',
quantity: 2,
})View Cart
const cart = await client.cart.getCart('cart_id')
// cart.itemsTotal → items subtotal (auto-calculated)
// cart.shippingFee → shipping fee
// cart.discountAmount → discount amount
// cart.totalAmount → final amount (auto-calculated)
// cart.items.docs → cart item listUpdate Quantity & Remove
// Update quantity
await client.cart.updateItem({
cartItemId: 'item_id',
quantity: 3,
})
// Remove item
await client.cart.removeItem({
cartItemId: 'item_id',
})
// Clear all items
await client.cart.clearCart({ cartId: 'cart_id' })Apply Discount Code
// 1. Validate discount code (optional)
const result = await serverClient.api.validateDiscount({
code: 'WELCOME10',
orderAmount: cart.itemsTotal,
customerId: 'customer_id', // for per-customer usage validation
})
// result.valid, result.discountAmount, result.freeShipping
// 2. Apply discount code to cart
const updatedCart = await client.cart.applyDiscount({
cartId: 'cart_id',
discountCode: 'WELCOME10',
})
// updatedCart.discountAmount → discount amount
// updatedCart.totalAmount → final amount after discount
// 3. Remove discount code
await client.cart.removeDiscount({ cartId: 'cart_id' })Discount types: percentage, fixed_amount, free_shipping, tiered
Calculate Shipping
const shipping = await serverClient.api.calculateShipping({
orderAmount: cart.itemsTotal,
postalCode: '63000', // Jeju surcharge auto-applied
})
// shipping.shippingFee, shipping.freeShippingCheckout (Cart → Order)
Use the Server API's checkout to convert a cart to an order.
import { generateOrderNumber } from '@01.software/sdk'
const order = await serverClient.api.checkout({
cartId: 'cart_id',
orderNumber: generateOrderNumber(),
customerSnapshot: {
email: 'customer@example.com',
name: 'John Doe',
phone: '010-1234-5678',
},
paymentId: 'payment_id', // omit for free orders
discountCode: 'WELCOME10', // code already applied to cart
})The server automatically handles during checkout:
- Cart's CartItems → OrderProducts copy
- Cart's customer, shippingAddress, shippingFee → Order
- Transaction created if paymentId is provided
- Free orders (
!paymentId && totalAmount === 0) auto-transition topaid+ stock adjustment - Cart status →
completed
Collection Reference
For detailed field specifications, see Cart Collections and Discount Collections.