Cart Module

The Cart Module provides cart-related features in your Medusa and Node.js applications.

How to Use Cart Module's Service#

You can use the Cart Module's main service by resolving from the Medusa container the resource Modules.CART imported from @medusajs/framework/utils.

For example:


Features#

Cart Management#

Store and manage carts, including their addresses, line items, shipping methods, and more.

Code
1const cart = await cartModuleService.createCarts({2  currency_code: "usd",3  shipping_address: {4    address_1: "1512 Barataria Blvd",5    country_code: "us",6  },7  items: [8    {9      title: "Shirt",10      unit_price: 1000,11      quantity: 1,12    },13  ],14})

Apply Promotions#

Apply promotions or discounts to line items and shipping methods by adding adjustment lines that are factored into their subtotals.

Code
1const lineAdjustments = await cartModuleService.addLineItemAdjustments({2  item_id: "cali_123",3  code: "50OFF",4  amount: 500,5})6
7const shippingAdjustments =8  await cartModuleService.addShippingMethodAdjustments({9    shipping_method_id: "casm_123",10    code: "FREESHIPPING",11    amount: 1000,12  })

Cart Context and Scoping#

A cart is scoped to a sales channel, region, and a customer.

The Medusa application links the Cart Module to each of their respective modules, providing features like:

  • Checking product availability in a sales channel.
  • Retrieving pricing per region.
  • Applying promotions based on the customer's group.
Was this page helpful?
Edit this page