Overview
The Cart Module manages shopping carts and their associated data including line items, shipping methods, addresses, and real-time total calculations. It provides the foundation for the checkout process. Key Features:- Cart and line item management
- Real-time total calculations
- Tax line and adjustment tracking
- Shipping method integration
- Cart completion tracking
- Credit lines for store credit
- Multi-currency support
When to Use
Use the Cart Module when you need to:- Create and manage shopping carts
- Add/remove products to carts
- Calculate cart totals with taxes and discounts
- Track shipping methods and costs
- Store customer shipping and billing addresses
- Handle cart-to-order conversion
- Support guest and registered customer carts
Data Models
Cart
The core cart entity representing a shopping session.Unique cart identifier (prefix:
cart_)ID of the associated region
ID of the customer (null for guest carts)
ID of the sales channel
Customer email address
Three-letter ISO currency code
BCP 47 language tag (e.g., “en-US”)
Timestamp when cart was completed (converted to order)
Products added to the cart
Shipping address for the cart
Billing address for the cart
Selected shipping methods
Store credit applied to the cart
LineItem
Represents a product in the cart.Unique line item identifier
ID of the parent cart
Product title
Product subtitle or variant title
Product thumbnail URL
Item quantity
ID of the product
ID of the product variant
Price per unit before discounts
Whether discounts can be applied
Whether price includes tax
Tax lines applied to this item
Discount adjustments applied to this item
Additional custom data
ShippingMethod
Represents a shipping option for the cart.Unique shipping method identifier
ID of the parent cart
Shipping method name
Shipping cost before discounts
Whether amount includes tax
Reference to the fulfillment shipping option
Provider-specific data
Tax lines applied to shipping
Discount adjustments applied to shipping
Address
Shipping or billing address for the cart.Unique address identifier
Associated customer ID
First name
Last name
Phone number
Company name
Address line 1
Address line 2
City
Two-letter ISO country code
State or province
Postal/ZIP code
Calculated Totals
The Cart Module automatically calculates totals when specific fields are requested. These are not stored but computed on-demand:Final cart total after all adjustments and taxes
Sum of line item subtotals before shipping
Total tax amount
Total discount amount
Total shipping cost after discounts and taxes
Sum of all line item totals
Total tax on line items
Total tax on shipping
Service Interface
The Cart Module service is available at@medusajs/medusa/cart.
Retrieve Cart
Retrieve a single cart with totals.The ID of the cart to retrieve
The retrieved cart with calculated totals
List Carts
List carts with filtering.Create Carts
Create a new shopping cart.The created cart(s)
Update Carts
Update cart information.The ID of the cart to update
Cart data to update
Create Line Items
Add products to a cart.Update Line Items
Update cart line items (e.g., change quantity).Delete Line Items
Remove items from the cart.Create Shipping Methods
Add shipping method to cart.Add Addresses
Set shipping and billing addresses.Integration Examples
With Product Module
Add products to cart by retrieving product data.With Pricing Module
Calculate prices before adding to cart.With Promotion Module
Apply promotions as adjustments.With Tax Module
Calculate and apply tax lines.Converting to Order
Mark cart as completed and create order.Best Practices
-
Total Calculation: To calculate totals, you must include total fields in
selectand required relations (items,items.tax_lines,items.adjustments,shipping_methods, etc.). The module automatically includes needed relations when total fields are selected. - Currency Consistency: Ensure all prices (line items, shipping, adjustments) use the same currency as the cart.
-
Guest Carts: For guest carts, omit
customer_idbut always includeemailfor order conversion. -
Cart Completion: Set
completed_atwhen converting to an order to prevent reuse. - Adjustments: Use negative amounts for discounts in LineItemAdjustment and ShippingMethodAdjustment.
-
Tax-Inclusive Pricing: Use the
is_tax_inclusiveflag to indicate if prices already include tax.
Related Modules
- Product Module - Retrieve products for cart
- Pricing Module - Calculate product prices
- Promotion Module - Apply discounts
- Order Module - Convert carts to orders
- Region Module - Region-based cart configuration