Skip to main content

Cart Basics

This document explains the fundamental concepts of cart management in Elastic Path Commerce Cloud.

Cart Data Model

The cart system consists of two primary entities:

  • Cart - The parent container for all items a customer wants to purchase
  • Cart Line - Individual product items within the cart, represented as cart_item objects

Each cart has the following key attributes:

  • Unique ID for identification
  • Relationships to items (products)
  • Optional customer association
  • Currency and pricing information
  • Meta data including display pricing

ID Conventions

Cart IDs are unique identifiers that are used to retrieve and manipulate cart data:

// Example cart ID structure
"cart_id": "12345678-1234-1234-1234-123456789012"

Cart IDs are typically stored in localStorage or cookies for persistence across page reloads and sessions.

Anonymous Carts

Anonymous carts allow visitors to shop before signing in. Key features include:

  • Created without requiring user authentication
  • Can be merged with a user's cart upon login
  • Persist based on browser storage mechanisms
  • Retrieved using the getCart SDK method with the cart ID

Merge Rules

When a user logs in with an existing anonymous cart, the following merge rules apply:

  • Carts must share the same currency and store to be eligible for merging
  • When currencies match, items from the anonymous cart are added to the user's cart
  • Line items with the same product are typically combined and quantities summed
  • Promotions are re-evaluated after merging

Key Considerations for Architects

  • Design your cart state management to persist cart IDs between sessions
  • Implement cart recovery strategies for abandoned carts
  • Create intuitive cart merge behaviors for a seamless shopping experience
  • Plan for inventory validation at key cart touchpoints
tip

For a complete implementation example demonstrating these cart concepts, check out the SPA Cart Example on GitHub.