DashForDevsDocs
DocsNewsAPI v1
dashfordevs.comSign in

© 2026 DashForDevs

DocsNewsdashfordevs.comLegalStatus
DocsCartGet Cart
Introduction
Getting Started
Authentication
Products
Categories
Cart
Get CartAdd to CartUpdate Cart ItemRemove from CartApply Discount CodeSubscription Cart Lines
Checkout
Blog
Reviews
Webhooks
Customers
Orders
Inventory
Shipping
Discounts
Affiliates
Email
Media & Files
Analytics & Tracking
Locations
Tax
Global Data
SEO
Error Handling
Geography
Finance
Automations
Page Types
Surveys
Billing & Subscriptions
Storefront Payments
SDK Reference
REST API
Storefront Architecture
Notifications
Security
Team & Permissions
Migrations & Import
Calendar & Appointments
Contact Forms
AI Bots
Dashboard API
Deployment
Changelog
Troubleshooting
Recipes
CLI & Deployment
Image Pipeline
White-label Platforms
Records Engine
Platform Modules
Platform Security
Site Keys & Client Sites
Use Cases
Operations

Get Cart

Retrieve the current cart contents and totals.

Updated March 29, 2026

On this page
  • Overview
  • SDK Usage
  • Cart Properties
  • Load an Existing Cart
  • Authenticated User Cart
  • Cart Migration (Guest → User)
  • REST API
  • Cart Response
  • Next Steps

Overview

Retrieve the current cart contents. The SDK automatically tracks the cart ID in localStorage, so you don't need to manage it manually.

SDK Usage

typescript
import dash from "@/lib/dash"

const { cart_id, items, subtotal, item_count } = await dash.cart.get()

// items = [
//   {
//     size_id: "size_abc",
//     product_id: "prod_123",
//     product_name: "Blue Dream",
//     product_slug: "blue-dream",
//     variation_name: "Blue Dream",
//     size_label: "1g",
//     unit_price: "29.99",
//     quantity: 2,
//     subtotal: "59.98",
//     in_stock: true,
//     product_image: "https://...",
//   }
// ]

Cart Properties

The SDK also provides local getters for quick access without an API call:

typescript
// Local state (no API call)
const cartId = dash.cart.cartId         // "cart_xyz" or null
const items = dash.cart.items           // [] — local cache of items
const totals = dash.cart.getTotals()    // { itemCount: 3, subtotal: "89.97" }
const qty = dash.cart.getTotalQuantity() // 3

Load an Existing Cart

If you have a cart ID stored (e.g., in a cookie), load it explicitly:

typescript
const cart = await dash.cart.load("cart_xyz789")

Authenticated User Cart

For logged-in customers, load their persistent cart:

typescript
const cart = await dash.cart.loadUserCart()
// Returns the customer's saved cart

Cart Migration (Guest → User)

When a guest customer logs in, merge their guest cart with their account:

typescript
// After successful login/registration
await dash.cart.migrateToUser()
// Guest cart items are merged into the customer's persistent cart
Tip: Always call migrateToUser() after authentication. If the customer had no guest cart, this is a no-op.

REST API

shell
# Get cart by ID
GET /storefront/cart/{cart_id}
X-API-Key: pk_live_your_key

# Get authenticated user's cart
GET /storefront/cart/user
Authorization: Bearer {access_token}

Cart Response

json
{
  "cart_id": "cart_xyz789",
  "items": [
    {
      "size_id": "size_abc",
      "product_id": "prod_123",
      "product_name": "Blue Dream",
      "product_slug": "blue-dream",
      "variation_name": "Blue Dream",
      "variation_slug": "blue-dream",
      "size_label": "1g",
      "unit_price": "29.99",
      "quantity": 2,
      "subtotal": "59.98",
      "in_stock": true,
      "product_image": "https://cdn.dashfordevs.com/...",
      "lab_report": null
    }
  ],
  "subtotal": "59.98",
  "discount_code": null,
  "discount_amount": "0.00",
  "item_count": 2
}

Next Steps

  • Add to Cart — Adding items
  • Update Cart Item — Changing quantities
  • Apply Discount Code — Applying coupons
  • Create Order — Starting the checkout process
PreviousCategory FilesNextAdd to Cart

On this page

  • Overview
  • SDK Usage
  • Cart Properties
  • Load an Existing Cart
  • Authenticated User Cart
  • Cart Migration (Guest → User)
  • REST API
  • Cart Response
  • Next Steps