Cartesiandocs

Integrate with your app

Cart and wishlist

Keep your own cart and checkout. Cartesian sends add, open and checkout actions to your code.

Most partners already have a cart and a checkout, and they should keep them. Set the cart (and the wishlist, if you have one) to FeatureMode.Host. Cartesian then asks your code instead of changing its own cart.

CartesianFeatures.Builder()
    .cart(FeatureMode.Host)
    .wishlist(FeatureMode.Host)   // or Off if you don't have one
    .build()

Handle the actions

Cartesian.listener = object : CartesianListener {
    override fun onAddToCart(product: Product, quantity: Int) {
        myCart.add(product.sku ?: product.id, quantity)
    }
    override fun onOpenCart() = navigator.openCart()
    override fun onToggleSaved(product: Product, saved: Boolean) = myWishlist.set(product.id, saved)
    override fun onOpenWishlist() = navigator.openWishlist()
    override fun onProductSelected(product: Product) = navigator.openProduct(product.id)
}

onAddToCart is called both when the shopper taps Add on a card and when the assistant itself adds items while answering ("add the cheapest gallon to my cart").

9:41

FreshMart

Delivering to Home · 94107 · in 45 min

🥛Dairy
🥦Produce
🍞Bakery
🥩Meat
🍿Snacks

Lucerne Farms Eggs Large

$1.29

Wilcox Family Farm Organic Brown Eggs

$1.29

O Organics Sharp Cheddar Sliced

$2.99

Horizon Organic String Cheese

$5.99

FreshMart Assistant

What's on your grocery list?

Tell me what you're cooking or who you're feeding. I'll find the products, compare prices, plan meals around your diet and allergies, and fill your cart.

FreshMart Assistant can make mistakes. Please check prices and ingredients before you buy.

Powered byCogitX Cartesian
Host cart: 0
Host mode: the answer adds eggs to the FreshMart cart (badge in the host app and under the phone), not to a Cartesian cart.

Known issue in the preview: when the assistant adds a product that is already in the backend cart, the backend sets the quantity instead of increasing it, so onAddToCart may not fire for that item. A fix that reads the changed lines from the cart frame is planned before 0.1.0.

Keep the UI in sync

The product cards show quantity steppers and filled hearts. Tell Cartesian what your cart contains so they stay correct:

myCart.lines.collect { lines ->
    Cartesian.host.setCart(lines.associate { it.productId to it.quantity })
}
myWishlist.ids.collect { ids -> Cartesian.host.setSaved(ids) }

The header counts and the in-card quantities read from these values in Host mode.

Checkout with the built-in cart

If you use FeatureMode.BuiltIn for the cart, the drawer's Checkout button calls onCheckout. Return true when you've taken over, for example by navigating to your checkout. Return false (the default) and the shopper sees "Checkout isn't connected in this app yet."

override fun onCheckout(cart: Cart): Boolean {
    navigator.checkout(cart.lines.map { it.product.id to it.quantity })
    return true
}

Products

Product wraps the backend's JSON. The typed getters cover the common fields: id, name, brand, price, regularPrice, isOnSale, imageUrl, size, sku and more. toJson() gives you the whole raw object, so you can map it to your own catalog IDs. See Models.