What problem does it solve?
Cart logic ensures shoppers' intended purchases are tracked reliably across page loads, devices, and authentication events so items are not lost, duplicated, or mispriced at checkout. It addresses missing persistence, guest carts disappearing after login, inconsistent totals caused by client-side calculations, and the need for platform-specific versus headless implementations.
Core Features & Use Cases
- Add / Remove / Update: Correct upsert semantics for line items so adding the same variant increments quantity instead of creating duplicates.
- Persistence & Session Management: Persist guest carts across sessions (recommended as an httpOnly guest token cookie) and support server-side cart storage for logged-in users.
- Guest → User Merge: Merge guest carts into a user's account on login while preserving audit history for guest carts and resolving conflicts sensibly.
- Server-side Totals & Validation: Capture unit price at add time, validate stock on add, and always recalculate subtotal, discounts, and totals server-side.
- Platform Coverage: Practical guidance for Shopify, WooCommerce, BigCommerce, and headless Storefront API implementations.
Quick Start
Create a persistent cart, add variant variantGid with quantity 1, and merge the guest cart into the user's account on login.