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
CartDTO
The retrieved cart with calculated totals
List Carts
List carts with filtering.FilterableCartProps
Create Carts
Create a new shopping cart.CreateCartDTO | CreateCartDTO[]
required
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
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
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