---
schema_version: "1"
id: 68eab39feac912619a40527114cc56a22849f18c86e1cf5fa04a00ef3f801171
title: Cart
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/salesforce-commerce/guides/d2c-commerce/b2b-comm-headless-cart.md
canonical_url: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-comm-headless-cart.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4272838e283582863d451992901e7442530444a86735c3dc6a61959f54209ca9
products:
  - B2B Commerce Developer Guide
  - Salesforce APIs
---
# Cart

### Overview

The Cart page shows all the items in the cart. Buyers can change the number of items or remove items, calculate the total amount of items in the cart, and add items to the cart to continue shopping.

Each buyer action on this page links to a specific Salesforce Commerce Cart REST API operation. This keeps the cart state in sync between the storefront and the commerce backend.

This flow demonstrates how a headless storefront can render cart experiences, including cart item management, pricing, and checkout actions, using B2B Commerce Cart APIs.

![Cart Overview Flow](https://developer.salesforce.com/media/d2c-commerce/b2b-headless-b2b-commerce-headless-flow-orchestration-cart-overview-14-1.png '{"class": "image-lg", "title": "Cart Overview Flow"}')

### B2B Commerce APIs Used in the Flow

| Purpose              | HTTP Method | Endpoint                                                                                                                                                                                    |
| -------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Load cart items      | GET         | [`/commerce/webstores/{webstoreId}/carts/current/cart-items`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=getCartItemCollection)       |
| Update line quantity | PATCH       | [`/commerce/webstores/{webstoreId}/carts/current/cart-items/{cartItemId}`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=patchCartItem)  |
| Remove line items    | DELETE      | [`/commerce/webstores/{webstoreId}/carts/current/cart-items/{cartItemId}`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=deleteCartItem) |
| Cart summary         | GET         | [`/commerce/webstores/{webstoreId}/carts/compact-summary`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=getCartBadge)                   |

### Buyer Journey

**Render the Cart Page**

1. Load the active cart.

2. Call the following endpoint to retrieve cart items and cart summary details:

   GET [`/commerce/webstores/{webstoreId}/carts/current/cart-items?includePromotions=true&includeCoupons=true&productFields=*`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=getCartItemCollection)

3. Pass the following query parameters:

   - `includePromotions`=`true`
   - `includeCoupons`=`true`
   - `productFields`=`\*`

4. The `productFields=\*` parameter is required to hydrate product information for each cart line item. Without this parameter, the response includes only product IDs and pricing data.

5. Use the response to render:

   - Cart line items
   - Product names
   - Product SKUs
   - Pricing information
   - Promotions
   - Applied coupons
   - Cart totals

6. Store both the `cartSummary` and cart item collection in client-side state so other storefront surfaces, such as the cart badge and checkout summary, can reuse the data without additional API requests.

**Update Item Quantity**

1. Change the quantity using the line-item quantity selector.

2. Call the following endpoint to update the cart item quantity:

   PATCH [`/commerce/webstores/{webstoreId}/carts/current/cart-items/{cartItemId}`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=patchCartItem)

   Example request body:

   ```json
   { "quantity": 2 }
   ```

3. After the request succeeds, refresh the cart summary and cart items to ensure totals and line-item data remain synchronized.

**Remove a Cart Item**

1. Select the remove or delete action for a cart line item.

2. Call the following endpoint to remove the item from the cart:

   DELETE [`/commerce/webstores/{webstoreId}/carts/current/cart-items/{cartItemId}`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=deleteCartItem)

   A successful request returns `204 No Content`.

3. Refresh the cart summary and cart item collection after the item is removed.

4. Re-render the cart page to remove the deleted line item from the UI.

5. Display a confirmation message or toast notification indicating that the item was removed successfully.

**Proceed to Checkout**

1. Select Proceed to Checkout to continue to the checkout flow.

2. No API request is required during this action. The checkout page initializes its required data when the page loads.

### Extend the Flow

<!--
- Add a Clear Cart action by sending:

  POST `/commerce/webstores/{webstoreId}/carts/{cartId}/actions/clear`

  This removes all line items from the active cart in a single operation.
-->

- Add coupon and promotion support using the following APIs:

  - Apply a coupon: POST [`/commerce/webstores/{webstoreId}/carts/current/cart-coupons`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=postCartCouponCollection)
  - Remove a coupon: DELETE [`/commerce/webstores/{webstoreId}/carts/current/cart-coupons/{cartCouponId}`](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-cart-ref?meta=deleteCartCoupon)

  These APIs enable buyers to apply and manage promotional discounts directly from the cart experience.

## See Also

- [_B2B Commerce Developer Guide_: Cart and Checkout Features](https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-d2c-comm-cart-checkout.html)
- [_B2B Commerce Developer Guide_: B2B Commerce Cart APIs](https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-d2c-comm-cart-apis.html)
- [_B2B Commerce Developer Guide_: B2B Commerce Checkout APIs](https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-d2c-comm-checkout-apis.html)
