import { CodeTabs, CodeTab } from "docs-ui" export const metadata = { title: `Cart Module`, } # {metadata.title} 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: ```ts title="src/workflows/hello-world/step1.ts" import { createStep } from "@medusajs/framework/workflows-sdk" import { Modules } from "@medusajs/framework/utils" const step1 = createStep("step-1", async (_, { container }) => { const cartModuleService = container.resolve( Modules.CART ) const carts = await cartModuleService.listCarts() }) ``` ```ts title="src/api/store/custom/route.ts" import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" import { Modules } from "@medusajs/framework/utils" export async function GET( req: MedusaRequest, res: MedusaResponse ): Promise { const cartModuleService = req.scope.resolve( Modules.CART ) res.json({ carts: await cartModuleService.listCarts(), }) } ``` ```ts title="src/subscribers/custom-handler.ts" import { SubscriberArgs } from "@medusajs/framework" import { Modules } from "@medusajs/framework/utils" export default async function subscriberHandler({ container }: SubscriberArgs) { const cartModuleService = container.resolve( Modules.CART ) const carts = await cartModuleService.listCarts() } ``` --- ## Features ### Cart Management Store and manage carts, including their addresses, line items, shipping methods, and more. ```ts const cart = await cartModuleService.createCarts({ currency_code: "usd", shipping_address: { address_1: "1512 Barataria Blvd", country_code: "us", }, items: [ { title: "Shirt", unit_price: 1000, quantity: 1, }, ], }) ``` ### Apply Promotions Apply promotions or discounts to line items and shipping methods by adding adjustment lines that are factored into their subtotals. ```ts const lineAdjustments = await cartModuleService.addLineItemAdjustments({ item_id: "cali_123", code: "50OFF", amount: 500, }) const shippingAdjustments = await cartModuleService.addShippingMethodAdjustments({ shipping_method_id: "casm_123", code: "FREESHIPPING", amount: 1000, }) ``` ### 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.