Behio Storefront SDK
Cart & Checkout

Cart Management

Add, update, and remove items from the shopping cart

Get Cart

const cart = await client.cart.get();
// { items, bundleLines, subtotal, discountTotal, grandTotal, currency }

Add Item

const cart = await client.cart.addItem({
  productId: 'warehouse-item-id',
  quantity: 2,
});

// Cart session token is auto-saved internally

Update Quantity

const cart = await client.cart.updateQuantity('cart-item-id', 3);

Remove Item

const cart = await client.cart.removeItem('cart-item-id');

Clear Cart

await client.cart.clear();

Bundles in Cart

// Add
const cart = await client.cart.addBundle('bundle-id', 1);

// Update quantity
const cart = await client.cart.updateBundleQuantity('bundle-id', 2);

// Remove
const cart = await client.cart.removeBundle('bundle-id');

Cart Merge

After login, merge the anonymous cart into the customer cart:

await client.auth.login({ email, password });
const mergedCart = await client.cart.merge();

Session Persistence

// Save to cookie / localStorage
const token = client.getCartSession();

// Restore on page load
client.setCartSession(savedToken);

Events

client.on('cart:updated', (cart) => {
  updateCartBadge(cart.items.length);
});

client.on('cart:cleared', () => {
  updateCartBadge(0);
});

On this page