FleetbaseFleetbase

Cart

Persistent cart sessions, item structure, multi-store cart behavior, and the Cart API endpoints.

Cart

The Cart is a persistent shopping session. Cart state is stored in the database, so customers can abandon and return without losing their selections. A cart's expires_at is set 7 days after creation and is not extended on subsequent updates.

Cart Sessions

Carts are tied to one of:

  • An authenticated customer — retrieved automatically when the customer logs in (the Customer-Token is read by the middleware to find the customer's cart)
  • A guest session — a unique identifier your app generates and stores locally (e.g., in AsyncStorage). Pass it as the URL path parameter when retrieving the cart
GET /storefront/v1/carts/{uniqueIdentifier}
Authorization: Bearer store_your_store_key

Cart Item Structure

Each item in the cart records:

FieldDescription
idCart item ID (used for update/delete)
product_idProduct public_id
nameProduct name at time of add
descriptionProduct description at time of add
product_image_urlImage URL
store_idStore public_id
store_location_idPickup location
food_truck_idOptional — when the item was added in the context of a food truck
quantityHow many units
priceUnit price at time of add
subtotalComputed line total
variantsArray of selected variant options (with additional_cost)
addonsArray of selected addons (with price and is_on_sale / sale_price)
scheduled_atOptional future scheduling timestamp
metaMirrors the product's metadata at time of add
created_at, updated_atUnix timestamps

The cart object itself exposes accessors for total_items, total_unique_items, subtotal, and is_multi_cart (true when items span more than one store).

Adding Items

POST /storefront/v1/carts/{cartId}/{productId}
Authorization: Bearer store_your_store_key

{
  "quantity": 2,
  "variants": [{ "id": "variant_option_id", "additional_cost": 200 }],
  "addons": [{ "id": "addon_id", "price": 100 }],
  "store_location": "store_location_public_id"
}

store_location is optional — if omitted, the cart picks the store's first location. Variants and addons are stored as full objects (their additional_cost and price are read by the cart subtotal calculator).

Updating Items

PUT /storefront/v1/carts/{cartId}/{lineItemId}
Authorization: Bearer store_your_store_key

Pass updated quantity, variants, or addons.

Removing Items

DELETE /storefront/v1/carts/{cartId}/{lineItemId}
Authorization: Bearer store_your_store_key

Cart Calculations

Cart totals are recalculated after every modification:

Item Subtotal = (Base Price
                 + Sum of selected variant additional costs
                 + Sum of addon prices (sale_price when is_on_sale, otherwise price))
                × Quantity

Cart Subtotal = Sum of all item subtotals

The delivery fee is not included in the cart subtotal. It is calculated separately via a Service Quote once the customer provides a delivery address, and applied during Checkout.

Cart Events

Cart mutations are logged on the cart's events array — cart.item_added, cart.item_updated, cart.item_removed, cart.emptied. This is useful for audit trails and for analyzing cart abandonment patterns.

Multi-Store Cart Behavior

A cart can hold items from a single store or from multiple stores within a Network — the behavior is controlled by the network's Enable multi-cart checkout setting (options.multi_cart_enabled).

Single-store carts (default)

When multi-cart is disabled (or the customer is shopping a standalone store), the cart's items are tied to a single store at a time. Your frontend should prompt the customer to clear the cart if they try to add an item from a different store.

Multi-store carts (network-level)

When Enable multi-cart checkout is toggled on for a Network:

  • Customers can add items from any store in the network to a single cart
  • The cart's is_multi_cart accessor returns true when items span more than one store
  • Storefront groups cart items by store internally
  • One checkout session is created for the combined total
  • On successful capture, Storefront produces one Fleet-Ops order per store, each with its own pickup location, store-specific dispatch, and proof-of-delivery
  • The customer pays once but receives multiple deliveries

Toggle this from Storefront → Networks → [Network] → General Settings → Enable multi-cart checkout.

Multi-cart only applies inside a network. Standalone stores accessed by their own store_* API key are always single-store.

Discount Codes

The cart has a discount_code field that can be set via the API. There is no built-in promotion engine yet — applying real discount logic is the responsibility of the implementer (custom code or a future Storefront promotions feature).

Cart | Fleetbase