Skip to main content

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.
string
required
Unique cart identifier (prefix: cart_)
string
ID of the associated region
string
ID of the customer (null for guest carts)
string
ID of the sales channel
string
Customer email address
string
required
Three-letter ISO currency code
string
BCP 47 language tag (e.g., “en-US”)
DateTime
Timestamp when cart was completed (converted to order)
LineItem[]
Products added to the cart
Address
Shipping address for the cart
Address
Billing address for the cart
ShippingMethod[]
Selected shipping methods
CreditLine[]
Store credit applied to the cart

LineItem

Represents a product in the cart.
string
required
Unique line item identifier
string
required
ID of the parent cart
string
required
Product title
string
Product subtitle or variant title
string
Product thumbnail URL
number
required
Item quantity
string
ID of the product
string
ID of the product variant
BigNumber
required
Price per unit before discounts
boolean
Whether discounts can be applied
boolean
Whether price includes tax
LineItemTaxLine[]
Tax lines applied to this item
LineItemAdjustment[]
Discount adjustments applied to this item
object
Additional custom data

ShippingMethod

Represents a shipping option for the cart.
string
required
Unique shipping method identifier
string
required
ID of the parent cart
string
required
Shipping method name
BigNumber
required
Shipping cost before discounts
boolean
Whether amount includes tax
string
Reference to the fulfillment shipping option
object
Provider-specific data
ShippingMethodTaxLine[]
Tax lines applied to shipping
ShippingMethodAdjustment[]
Discount adjustments applied to shipping

Address

Shipping or billing address for the cart.
string
required
Unique address identifier
string
Associated customer ID
string
First name
string
Last name
string
Phone number
string
Company name
string
Address line 1
string
Address line 2
string
City
string
Two-letter ISO country code
string
State or province
string
Postal/ZIP code

Calculated Totals

The Cart Module automatically calculates totals when specific fields are requested. These are not stored but computed on-demand:
BigNumber
Final cart total after all adjustments and taxes
BigNumber
Sum of line item subtotals before shipping
BigNumber
Total tax amount
BigNumber
Total discount amount
BigNumber
Total shipping cost after discounts and taxes
BigNumber
Sum of all line item totals
BigNumber
Total tax on line items
BigNumber
Total tax on shipping

Service Interface

The Cart Module service is available at @medusajs/medusa/cart.

Retrieve Cart

Retrieve a single cart with totals.
string
required
The ID of the cart to retrieve
FindConfig
Configuration for the query
string[]
Fields to select (include total fields to calculate them)
string[]
Relations to load. Required relations for totals: items, items.tax_lines, items.adjustments, shipping_methods, shipping_methods.tax_lines, shipping_methods.adjustments
CartDTO
The retrieved cart with calculated totals

List Carts

List carts with filtering.
FilterableCartProps
Filters to apply
string | string[]
Filter by cart IDs
string | string[]
Filter by customer IDs
string | string[]
Filter by sales channel IDs
string
Filter by email
null | object
Filter by completion status (null for active carts)

Create Carts

Create a new shopping cart.
CreateCartDTO | CreateCartDTO[]
required
Cart data to create
string
ID of the region
string
ID of the customer (omit for guest cart)
string
Customer email
string
required
Three-letter ISO currency code
string
ID of the sales channel
CreateLineItemDTO[]
Initial line items
CartDTO | CartDTO[]
The created cart(s)

Update Carts

Update cart information.
string
required
The ID of the cart to update
UpdateCartDTO
required
Cart data to update

Create Line Items

Add products to a cart.
CreateLineItemDTO | CreateLineItemDTO[]
required
Line item data
string
required
ID of the cart
string
required
Product title
string
ID of the product
string
ID of the product variant
number
required
Item quantity
number
required
Price per unit

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.
CreateShippingMethodDTO | CreateShippingMethodDTO[]
required
Shipping method data
string
required
ID of the cart
string
required
Shipping method name
number
required
Shipping cost
string
Reference to fulfillment shipping option

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

  1. Total Calculation: To calculate totals, you must include total fields in select and required relations (items, items.tax_lines, items.adjustments, shipping_methods, etc.). The module automatically includes needed relations when total fields are selected.
  2. Currency Consistency: Ensure all prices (line items, shipping, adjustments) use the same currency as the cart.
  3. Guest Carts: For guest carts, omit customer_id but always include email for order conversion.
  4. Cart Completion: Set completed_at when converting to an order to prevent reuse.
  5. Adjustments: Use negative amounts for discounts in LineItemAdjustment and ShippingMethodAdjustment.
  6. Tax-Inclusive Pricing: Use the is_tax_inclusive flag to indicate if prices already include tax.