GlassHouse Docs Support
Custom stores

Connect the cart

Let shoppers add a planting design using your existing cart and checkout.

Add the cart methods

Provide adapter.cart to enable cart actions. Implement these methods in your store’s cart service.

Required cart methods
import type {
  ShopperContext, CartLine, CartResult, CartMutation,
} from '@superseeded/glasshouse/types'

type CartConnection = {
  read(context: ShopperContext): Promise<CartLine[]>
  replay(key: string, context: ShopperContext): Promise<CartResult | null>
  apply(input: CartMutation, context: ShopperContext): Promise<CartResult>
}

read returns the shopper’s cart lines. replay returns a saved result, or null. apply commits the design and returns { success, lines }. context.shopperId comes from your verified store session. input contains designKey, idempotencyKey and lines.

Apply a design atomically

  1. Check for a saved result for this shopper and idempotencyKey.
  2. Validate current stock, quantities and prices in the cart transaction.
  3. Replace the lines belonging to designKey, preserving the shopper’s other cart items.
  4. Save the result with the cart update, then return the design’s final lines.

A retry must return the saved result instead of adding the plants again. success: true means every requested quantity was applied. Cart totals, discounts, tax and checkout remain your store’s responsibility.

Undo and remove

Add remove(id, designKey, idempotencyKey, context) to remove a product from a design. Add undo(token, designKey, idempotencyKey, context) to restore a previous design change, and return an undoToken with the original result.

Both methods return CartResult, enforce shopper and design ownership, and use the same saved-result mechanism. GlassHouse only shows these controls when the methods are supplied.

Refresh the store’s cart display

Browser callback
const glasshouse = await mountGlassHouse({
  target: '#plant-assistance',
  endpoint: '/api/glasshouse/',
  onCartChange: () => refreshCart(),
})

refreshCart() is your application’s existing cart refresh. The callback runs for successful changes and reported partial failures so the cart display stays current.

Check the complete journey

Add a design, change its quantities and apply it again. Confirm unrelated cart items remain. Retry a completed request and verify quantities stay the same. Repeat with a second shopper to check that each cart stays independent.

Tab to a result, then press Enter to open it.