# 购物车

> 购物车相关的 Ajax API 接口：读取购物车，单个或批量加购规格，改行项目数量，移除行项目，选择参与结账的行项目，保存备注。

Cart API 用于在客户会话期间与购物车进行交互。本指南介绍如何使用 Cart API 来添加、更新、删除购物车行项目，以及更新购物车备注。

## 获取购物车

```text
GET /{locale}/api/cart
```

使用 `GET /{locale}/api/cart` endpoint 以 JSON 格式获取购物车。

所有货币属性均以客户的展示货币返回。若您已添加其他市场，可在 response 中使用 currency 字段来查看客户的展示货币。

以下是使用 `fetch` API 的简化 `GET` 请求示例。headers 中的 `Content-Type` 应设置为 `application/json`。Response 为关联行项目的 JSON 格式。

### 请求示例

**请求示例**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/cart', {
  headers: {
    'Content-Type': 'application/json'
  }
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 响应

**数据结构 | 示例**

- `cart` object

  - `line_items` object[]

    行项目列表。

    *   Array [

    - `id` string

      行项目的 ID。
    - `item_id` string
    - `product_id` string

      商品 ID。
    - `variant_id` string

      款式 ID。
    - `quantity` string

      商品数量。
    - `note` string

      行项目的备注。
    - `properties` string

      行项目的自定义属性，返回的是 JSON 字符串，使用前需要自行解析。
    - `custom` boolean

      该行项目是否为自定义商品。
    - `product_title` string

      商品名称。
    - `product_handle` string

      商品的 handle。
    - `product_url` string

      商品页的相对地址。
    - `variant_title` string

      款式标题，例如 `Blue, Size M`。
    - `product_type` string

      商品类型。
    - `price` string

      行项目单件商品的价格。
    - `compare_at_price` string

      划线价。
    - `origin_price` string
    - `line_price` string

      应用折扣前，该行项目所有商品的合计价格。
    - `original_line_price` number

      折扣前该行项目的原始价格。
    - `saved_price` number

      该行项目节省的金额。
    - `final_line_price` string

      应用行级折扣后，该行项目所有商品的合计价格。
    - `final_price` string

      应用行级折扣后，该行项目单件商品的价格。
    - `discount_applications` undefined[]

      该对象已应用的折扣。
    - `fixed_discount_total` string
    - `discount_total` string

      折扣总额。
    - `discount_id` string

      所应用折扣的 ID。
    - `available` boolean

      是否可购买。
    - `available_quantity` number

      仍可购买的数量。
    - `can_buy` boolean

      行项目所属款式是否可售。
    - `weight` string

      款式的重量。
    - `weight_unit` string

      重量单位，例如 `kg`。
    - `sku` string

      款式的 SKU，用于库存管理。
    - `spu` string

      商品的 SPU（标准产品单元）。
    - `requires_shipping` boolean

      是否需要物流配送。
    - `taxable` boolean

      是否需要计税。
    - `image` object

      行项目所属款式的图片。

      - `src` string

        图片的地址。
      - `path` string

        图片文件在图床上的路径。
      - `width` number

        图片宽度（像素）。
      - `height` number

        图片高度（像素）。
      - `alt` string

        图片的替代文本。
    - `options` object[]

      行项目所属款式的属性取值。

      *   Array [

      - `name` string

        商品属性名称，例如 `Color`。
      - `value` string

        该商品属性被选中的取值。
      *   ]
    - `wholesale_price` object[]

      批发价梯度列表。

      *   Array [

      - `min_quantity` number

        该批发价梯度要求的最小数量。
      - `price` string

        该批发价梯度的单价。
      *   ]
    - `parts_price` string
    - `product_tags` undefined[]

      商品的标签。
    - `published` boolean

      资源是否已发布。
    - `published_at` string

      发布时间（ISO-8601 格式）。
    - `inventory_quantity` number

      库存数量。
    - `inventory_policy` string

      商品缺货时是否继续销售。
    - `inventory_tracking` boolean

      是否启用库存追踪。
    - `cost_price` string

      款式的成本价。
    - `vendor` string

      商品的供应商。
    - `vendor_url` string

      商品供应商的链接。
    - `barcode` string

      款式的条形码。
    - `mixed_wholesale` boolean

      是否支持混批。
    - `tax_code` string
    - `retail_price` string

      以店铺主货币单位表示的零售价。
    - `item_text` string
    - `disabled` boolean
    - `is_free_gift` boolean

      该商品是否为赠品。
    - `custom_discounts` undefined[]
    *   ]
  - `ineffectives` undefined[]

    购物车中已不可购买的行项目。
  - `discount_applications` undefined[]

    该对象已应用的折扣。
  - `attributes` undefined[]
  - `total_discount` string

    购物车所有折扣节省的总金额。
  - `discount_line_item_price` string

    已应用折扣的折后总价。
  - `currency` string

    购物车使用的货币，例如 `USD`。
  - `original_line_price` string

    折扣前该行项目的原始价格。
  - `original_total_price` string

    应用折扣前购物车的总价。
  - `line_price` string

    应用折扣前，该行项目所有商品的合计价格。
  - `total_price` string

    应用折扣后购物车的总价。
  - `note` string

    对象上的备注。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  - `item_count` number

    购物车中的商品数量。
  - `total_weight` number

    购物车中所有商品的总重量。
  - `invalid_msg` string
  - `identity_cart_id` string

    购物车标识，用于把购物车与它生成的订单关联起来。
  - `user_id` string

    已登录顾客的 ID，游客状态下没有这个值。

```json
{
  "cart": {
    "line_items": [
      {
        "id": "684953787470717063_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684953787470717063",
        "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
        "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
        "quantity": "1",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "sample-product",
        "product_handle": "sample-product",
        "product_url": "/products/sample-product",
        "variant_title": "01",
        "product_type": "default",
        "price": "1.00",
        "compare_at_price": "1.00",
        "origin_price": "1.00",
        "line_price": "1.00",
        "original_line_price": 1,
        "saved_price": 0,
        "final_line_price": "1.00",
        "final_price": "1.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 999999999,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "",
        "spu": "",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "width": 3000,
          "height": 1500,
          "alt": ""
        },
        "options": [
          {
            "name": "Size",
            "value": "01"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "1.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-08-10T07:28:24Z",
        "inventory_quantity": 0,
        "inventory_policy": "",
        "inventory_tracking": false,
        "cost_price": "1.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      }
    ],
    "ineffectives": [],
    "discount_applications": [],
    "attributes": [],
    "total_discount": "0.00",
    "discount_line_item_price": "0.00",
    "currency": "USD",
    "original_line_price": "1.00",
    "original_total_price": "1.00",
    "line_price": "1.00",
    "total_price": "1.00",
    "note": "",
    "created_at": "2026-09-03T01:03:36Z",
    "updated_at": "2026-09-03T02:41:50Z",
    "item_count": 1,
    "total_weight": 0,
    "invalid_msg": "",
    "identity_cart_id": "879f8b8f-c3a0-483c-baf6-f5a55a7ff5b4",
    "user_id": "9fe44049-abab-4fed-ab3d-1bf4ffee8ef5"
  }
}
```

## 添加单个规格到购物车

```text
POST /{locale}/api/cart
```

使用 `POST /{locale}/api/cart` endpoint 将单个 variant 添加到购物车。

### 请求示例

如果该商品已在购物车中，则 `quantity` 会累加到该商品的当前数量上。

**请求示例**

```javascript
const data = {
  product_id: "b1ab6324-ae4f-4cca-907e-18af16839447",
  variant_id: "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
  quantity: 1,
  refer_info: {
    source: "add_to_cart"
  },
  properties: {
    Engraving: "Happy Birthday",
    _design_id: "dsg_8f21c"
  }
};

fetch(window.SHOPLAZZA.routes.root + '/api/cart', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  })
	.catch((error) => {
    console.error('Error: ', error);
  });
```

### 请求参数

**数据结构 | 示例**

- `product_id` string

  variant 所属商品的 id。
- `quantity` number

  需要添加到购物车的数量。
- `variant_id` string

  variant 的 id。
- `refer_info` object

  请求来源的引用信息。它包含一个 `source` 属性，可能的取值为：`add_to_cart`、`buy_now` 或 `cart`。

  - `source` string
- `properties` object

  挂在行项目上的自定义属性，例如定制选项。属性会随行项目一直带到订单。

```json
{
  "product_id": "b1ab6324-ae4f-4cca-907e-18af16839447",
  "variant_id": "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
  "quantity": 1,
  "refer_info": {
    "source": "add_to_cart"
  },
  "properties": {
    "Engraving": "Happy Birthday",
    "_design_id": "dsg_8f21c"
  }
}
```

**备注**

行项目由款式和属性共同决定。同一个款式配不同属性再次加购，会新增一个行项目，而不是给原来那行加数量。

响应里的 `properties` 是 JSON 字符串，读键之前要先解析。加购时没有传属性的行返回空字符串，所以要先判空，并且对解析结果不是普通对象的情况做兜底。

键以下划线开头的属性仍会由本接口返回，但不会展示给顾客，后台订单页也不显示。从商品页写入属性到从订单读回的完整流程，见[给购物车和订单添加自定义属性](/zh-CN/docs/app/use-cases/product-merchandising/add-custom-properties)。

### 响应

**数据结构 | 示例**

- `state` string

  请求结果标识，`success` 或 `0` 表示请求成功。
- `message` string

  响应返回的结果说明。
- `errors` undefined[]

  请求失败时返回的错误列表。
- `data` object

  响应数据主体。

  - `items` object[]

    购物车中的行项目列表。

    *   Array [

    - `id` string

      行项目的 ID。
    - `item_id` string
    - `product_id` string

      商品 ID。
    - `variant_id` string

      款式 ID。
    - `quantity` number

      商品数量。
    - `note` string

      行项目的备注。
    - `properties` string

      行项目的自定义属性，返回的是 JSON 字符串，使用前需要自行解析。
    - `custom` boolean

      该行项目是否为自定义商品。
    - `product_title` string

      商品名称。
    - `product_handle` string

      商品的 handle。
    - `product_url` string

      商品页的相对地址。
    - `variant_title` string

      款式标题，例如 `Blue, Size M`。
    - `product_type` string

      商品类型。
    - `price` string

      行项目单件商品的价格。
    - `compare_at_price` string

      划线价。
    - `origin_price` string
    - `available` boolean

      是否可购买。
    - `available_quantity` number

      仍可购买的数量。
    - `weight` string

      款式的重量。
    - `weight_unit` string

      重量单位，例如 `kg`。
    - `sku` string

      款式的 SKU，用于库存管理。
    - `spu` string

      商品的 SPU（标准产品单元）。
    - `requires_shipping` boolean

      是否需要物流配送。
    - `taxable` boolean

      是否需要计税。
    - `image` object

      行项目所属款式的图片。

      - `src` string

        图片的地址。
      - `path` string

        图片文件在图床上的路径。
      - `width` number

        图片宽度（像素）。
      - `height` number

        图片高度（像素）。
      - `alt` string

        图片的替代文本。
    - `options` object[]

      行项目所属款式的属性取值。

      *   Array [

      - `name` string

        商品属性名称，例如 `Color`。
      - `value` string

        该商品属性被选中的取值。
      *   ]
    - `wholesale_price` object[]

      批发价梯度列表。

      *   Array [

      - `min_quantity` number

        该批发价梯度要求的最小数量。
      - `price` string

        该批发价梯度的单价。
      *   ]
    - `product_tags` undefined[]

      商品的标签。
    - `published` boolean

      资源是否已发布。
    - `published_at` string

      发布时间（ISO-8601 格式）。
    - `inventory_quantity` number

      库存数量。
    - `inventory_policy` string

      商品缺货时是否继续销售。
    - `inventory_tracking` boolean

      是否启用库存追踪。
    - `cost_price` string

      款式的成本价。
    - `vendor` string

      商品的供应商。
    - `vendor_url` string

      商品供应商的链接。
    - `barcode` string

      款式的条形码。
    - `mixed_wholesale` boolean

      是否支持混批。
    - `tax_code` string
    - `retail_price` string

      以店铺主货币单位表示的零售价。
    - `add_quantity` string
    - `disabled` boolean
    *   ]

```json
{
  "state": "success",
  "message": "",
  "errors": [],
  "data": {
    "items": [
      {
        "id": "0_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684953787470717063",
        "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
        "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
        "quantity": 1,
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "sample-product",
        "product_handle": "sample-product",
        "product_url": "/products/sample-product",
        "variant_title": "01",
        "product_type": "default",
        "price": "1.00",
        "compare_at_price": "1.00",
        "origin_price": "1.00",
        "available": true,
        "available_quantity": 999999999,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "",
        "spu": "",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "width": 3000,
          "height": 1500,
          "alt": ""
        },
        "options": [
          {
            "name": "Size",
            "value": "01"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "1.00"
          }
        ],
        "product_tags": [],
        "published": true,
        "published_at": "2026-08-10T07:28:24Z",
        "inventory_quantity": 0,
        "inventory_policy": "",
        "inventory_tracking": false,
        "cost_price": "1.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "add_quantity": "1",
        "disabled": false
      }
    ]
  }
}
```

## 批量添加规格到购物车

```text
POST /{locale}/api/cart/batch
```

使用 `POST /{locale}/api/cart/batch` endpoint 将一个或多个 variants 添加到购物车。

### 请求示例

如果该商品已在购物车中，则 `quantity` 会累加到该商品的当前数量上。

**请求示例**

```javascript
const data = {
  line_items: [
    {
      product_id: "b1ab6324-ae4f-4cca-907e-18af16839447",
      variant_id: "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
      quantity: 1,
      properties: {
        Engraving: "Happy Birthday"
      }
    },
    {
      quantity: 2,
      product_id: "588ed0ce-40af-44c7-8dea-afa18b489ef8",
      variant_id: "83196e5a-b25f-42c3-8df5-359d83ea7ae8"
    }
  ]
}

fetch(window.SHOPLAZZA.routes.root + '/api/cart/batch', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  })
  .catch((error) => {
    console.error('Error: ', error);
  });
```

### 请求参数

**数据结构 | 示例**

- `line_items` object[]

  行项目列表。

  *   Array [

  - `product_id` string

    要加入购物车的商品 ID。
  - `variant_id` string

    要加入购物车的商品款式 ID。
  - `quantity` number

    加入的数量。
  - `properties` object

    挂在行项目上的自定义属性。
  *   ]

```json
{
  "line_items": [
    {
      "product_id": "b1ab6324-ae4f-4cca-907e-18af16839447",
      "variant_id": "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
      "quantity": 1,
      "properties": {
        "Engraving": "Happy Birthday"
      }
    },
    {
      "quantity": 2,
      "product_id": "588ed0ce-40af-44c7-8dea-afa18b489ef8",
      "variant_id": "83196e5a-b25f-42c3-8df5-359d83ea7ae8"
    }
  ]
}
```

### 响应

**数据结构 | 示例**

- `items` object[]

  购物车中的行项目列表。

  *   Array [

  - `id` string

    行项目的 ID。
  - `item_id` string
  - `product_id` string

    商品 ID。
  - `variant_id` string

    款式 ID。
  - `quantity` number

    商品数量。
  - `note` string

    行项目的备注。
  - `properties` string

    行项目上记录的自定义属性。
  - `custom` boolean

    该行项目是否为自定义商品。
  - `product_title` string

    商品名称。
  - `product_handle` string

    商品的 handle。
  - `product_url` string

    商品页的相对地址。
  - `variant_title` string

    款式标题，例如 `Blue, Size M`。
  - `product_type` string

    商品类型。
  - `price` string

    行项目单件商品的价格。
  - `compare_at_price` string

    划线价。
  - `origin_price` string
  - `available` boolean

    是否可购买。
  - `available_quantity` number

    仍可购买的数量。
  - `weight` string

    款式的重量。
  - `weight_unit` string

    重量单位，例如 `kg`。
  - `sku` string

    款式的 SKU，用于库存管理。
  - `spu` string

    商品的 SPU（标准产品单元）。
  - `requires_shipping` boolean

    是否需要物流配送。
  - `taxable` boolean

    是否需要计税。
  - `image` object

    行项目所属款式的图片。

    - `src` string

      图片的地址。
    - `path` string

      图片文件在图床上的路径。
    - `width` number

      图片宽度（像素）。
    - `height` number

      图片高度（像素）。
    - `alt` string

      图片的替代文本。
  - `options` object[]

    行项目所属款式的属性取值。

    *   Array [

    - `name` string

      商品属性名称，例如 `Color`。
    - `value` string

      该商品属性被选中的取值。
    *   ]
  - `wholesale_price` object[]

    批发价梯度列表。

    *   Array [

    - `min_quantity` number

      该批发价梯度要求的最小数量。
    - `price` string

      该批发价梯度的单价。
    *   ]
  - `product_tags` undefined[]

    商品的标签。
  - `published` boolean

    资源是否已发布。
  - `published_at` string

    发布时间（ISO-8601 格式）。
  - `inventory_quantity` number

    库存数量。
  - `inventory_policy` string

    商品缺货时是否继续销售。
  - `inventory_tracking` boolean

    是否启用库存追踪。
  - `cost_price` string

    款式的成本价。
  - `vendor` string

    商品的供应商。
  - `vendor_url` string

    商品供应商的链接。
  - `barcode` string

    款式的条形码。
  - `mixed_wholesale` boolean

    是否支持混批。
  - `tax_code` string
  - `retail_price` string

    以店铺主货币单位表示的零售价。
  - `add_quantity` string
  - `disabled` boolean
  *   ]

```json
{
  "items": [
    {
      "id": "684765446766863303_d41d8cd98f00b204e9800998ecf8427e",
      "item_id": "684765446766863303",
      "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
      "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
      "quantity": 2,
      "note": "",
      "properties": "",
      "custom": false,
      "product_title": "sample-product",
      "product_handle": "sample-product",
      "product_url": "/products/sample-product",
      "variant_title": "01",
      "product_type": "default",
      "price": "1.00",
      "compare_at_price": "1.00",
      "origin_price": "1.00",
      "available": true,
      "available_quantity": 999999999,
      "weight": "0.00",
      "weight_unit": "kg",
      "sku": "",
      "spu": "",
      "requires_shipping": true,
      "taxable": false,
      "image": {
        "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
        "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
        "width": 3000,
        "height": 1500,
        "alt": ""
      },
      "options": [
        {
          "name": "Size",
          "value": "01"
        }
      ],
      "wholesale_price": [
        {
          "min_quantity": 1,
          "price": "1.00"
        }
      ],
      "product_tags": [],
      "published": true,
      "published_at": "2026-08-10T07:28:24Z",
      "inventory_quantity": 0,
      "inventory_policy": "",
      "inventory_tracking": false,
      "cost_price": "1.00",
      "vendor": "",
      "vendor_url": "",
      "barcode": "",
      "mixed_wholesale": false,
      "tax_code": "",
      "retail_price": "0.00",
      "add_quantity": "1",
      "disabled": false
    }
  ]
}
```

## 批量设置行项目数量

```text
POST /{locale}/api/cart/update
```

使用 `POST /{locale}/api/cart/update` endpoint 设置购物车中已有行项目的数量。与 `POST /{locale}/api/cart` 不同，这里传的数量是覆盖当前数量，而不是累加。

### 请求示例

**请求示例**

```javascript
const data = {
  line_items: [
    {
      product_id: "b1ab6324-ae4f-4cca-907e-18af16839447",
      variant_id: "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
      quantity: 1
    }
  ]
};

fetch(window.SHOPLAZZA.routes.root + '/api/cart/update', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 请求参数

**数据结构 | 示例**

- `line_items` object[]

  要修改的行项目列表。

  *   Array [

  - `product_id` string

    variant 所属商品的 id。
  - `variant_id` string

    variant 的 id。
  - `quantity` number

    该行项目的新数量。
  *   ]

```json
{
  "line_items": [
    {
      "product_id": "b1ab6324-ae4f-4cca-907e-18af16839447",
      "variant_id": "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
      "quantity": 1
    }
  ]
}
```

### 响应

**数据结构 | 示例**

- `cart` object

  - `line_items` object[]

    行项目列表。

    *   Array [

    - `id` string

      行项目的 ID。
    - `item_id` string
    - `product_id` string

      商品 ID。
    - `variant_id` string

      款式 ID。
    - `quantity` string

      商品数量。
    - `note` string

      行项目的备注。
    - `properties` string

      行项目上记录的自定义属性。
    - `custom` boolean

      该行项目是否为自定义商品。
    - `product_title` string

      商品名称。
    - `product_handle` string

      商品的 handle。
    - `product_url` string

      商品页的相对地址。
    - `variant_title` string

      款式标题，例如 `Blue, Size M`。
    - `product_type` string

      商品类型。
    - `price` string

      行项目单件商品的价格。
    - `compare_at_price` string

      划线价。
    - `origin_price` string
    - `line_price` string

      应用折扣前，该行项目所有商品的合计价格。
    - `original_line_price` number

      折扣前该行项目的原始价格。
    - `saved_price` number

      该行项目节省的金额。
    - `final_line_price` string

      应用行级折扣后，该行项目所有商品的合计价格。
    - `final_price` string

      应用行级折扣后，该行项目单件商品的价格。
    - `discount_applications` undefined[]

      该对象已应用的折扣。
    - `fixed_discount_total` string
    - `discount_total` string

      折扣总额。
    - `discount_id` string

      所应用折扣的 ID。
    - `available` boolean

      是否可购买。
    - `available_quantity` number

      仍可购买的数量。
    - `can_buy` boolean

      行项目所属款式是否可售。
    - `weight` string

      款式的重量。
    - `weight_unit` string

      重量单位，例如 `kg`。
    - `sku` string

      款式的 SKU，用于库存管理。
    - `spu` string

      商品的 SPU（标准产品单元）。
    - `requires_shipping` boolean

      是否需要物流配送。
    - `taxable` boolean

      是否需要计税。
    - `image` object

      行项目所属款式的图片。

      - `src` string

        图片的地址。
      - `path` string

        图片文件在图床上的路径。
      - `width` number

        图片宽度（像素）。
      - `height` number

        图片高度（像素）。
      - `alt` string

        图片的替代文本。
    - `options` object[]

      行项目所属款式的属性取值。

      *   Array [

      - `name` string

        商品属性名称，例如 `Color`。
      - `value` string

        该商品属性被选中的取值。
      *   ]
    - `wholesale_price` object[]

      批发价梯度列表。

      *   Array [

      - `min_quantity` number

        该批发价梯度要求的最小数量。
      - `price` string

        该批发价梯度的单价。
      *   ]
    - `parts_price` string
    - `product_tags` undefined[]

      商品的标签。
    - `published` boolean

      资源是否已发布。
    - `published_at` string

      发布时间（ISO-8601 格式）。
    - `inventory_quantity` number

      库存数量。
    - `inventory_policy` string

      商品缺货时是否继续销售。
    - `inventory_tracking` boolean

      是否启用库存追踪。
    - `cost_price` string

      款式的成本价。
    - `vendor` string

      商品的供应商。
    - `vendor_url` string

      商品供应商的链接。
    - `barcode` string

      款式的条形码。
    - `mixed_wholesale` boolean

      是否支持混批。
    - `tax_code` string
    - `retail_price` string

      以店铺主货币单位表示的零售价。
    - `item_text` string
    - `disabled` boolean
    - `is_free_gift` boolean

      该商品是否为赠品。
    - `custom_discounts` undefined[]
    *   ]
  - `ineffectives` undefined[]

    购物车中已不可购买的行项目。
  - `discount_applications` undefined[]

    该对象已应用的折扣。
  - `attributes` undefined[]
  - `total_discount` string

    购物车所有折扣节省的总金额。
  - `discount_line_item_price` string

    已应用折扣的折后总价。
  - `currency` string

    购物车使用的货币，例如 `USD`。
  - `original_line_price` string

    折扣前该行项目的原始价格。
  - `original_total_price` string

    应用折扣前购物车的总价。
  - `line_price` string

    应用折扣前，该行项目所有商品的合计价格。
  - `total_price` string

    应用折扣后购物车的总价。
  - `note` string

    对象上的备注。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  - `item_count` number

    购物车中的商品数量。
  - `total_weight` number

    购物车中所有商品的总重量。
  - `invalid_msg` string
  - `identity_cart_id` string

    购物车标识，用于把购物车与它生成的订单关联起来。
  - `user_id` string

```json
{
  "cart": {
    "line_items": [
      {
        "id": "684765446766863303_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684765446766863303",
        "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
        "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
        "quantity": "1",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "sample-product",
        "product_handle": "sample-product",
        "product_url": "/products/sample-product",
        "variant_title": "01",
        "product_type": "default",
        "price": "1.00",
        "compare_at_price": "1.00",
        "origin_price": "1.00",
        "line_price": "1.00",
        "original_line_price": 1,
        "saved_price": 0,
        "final_line_price": "1.00",
        "final_price": "1.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 999999999,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "",
        "spu": "",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "width": 3000,
          "height": 1500,
          "alt": ""
        },
        "options": [
          {
            "name": "Size",
            "value": "01"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "1.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-08-10T07:28:24Z",
        "inventory_quantity": 0,
        "inventory_policy": "",
        "inventory_tracking": false,
        "cost_price": "1.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      },
      {
        "id": "684698318307074183_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684698318307074183",
        "product_id": "b3b656ae-504f-4f01-a054-879a610925e3",
        "variant_id": "0699bc80-19ae-41bb-87c4-dbcbe5ed90a0",
        "quantity": "2",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "Sample product",
        "product_handle": "Sample product",
        "product_url": "/products/Sample product",
        "variant_title": "Black-S",
        "product_type": "default",
        "price": "10.00",
        "compare_at_price": "20.00",
        "origin_price": "10.00",
        "line_price": "20.00",
        "original_line_price": 40,
        "saved_price": 10,
        "final_line_price": "20.00",
        "final_price": "10.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 48,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "1111-BLACK-S-A001001",
        "spu": "1111",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "path": "50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "width": 1254,
          "height": 1254,
          "alt": ""
        },
        "options": [
          {
            "name": "Color",
            "value": "Black"
          },
          {
            "name": "Size",
            "value": "S"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "10.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-07-30T02:28:23Z",
        "inventory_quantity": 48,
        "inventory_policy": "deny",
        "inventory_tracking": true,
        "cost_price": "10.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      }
    ],
    "ineffectives": [],
    "discount_applications": [],
    "attributes": [],
    "total_discount": "0.00",
    "discount_line_item_price": "0.00",
    "currency": "USD",
    "original_line_price": "41.00",
    "original_total_price": "41.00",
    "line_price": "21.00",
    "total_price": "21.00",
    "note": "",
    "created_at": "2026-06-23T19:57:16Z",
    "updated_at": "2026-09-02T14:13:29Z",
    "item_count": 3,
    "total_weight": 0,
    "invalid_msg": "",
    "identity_cart_id": "879f8b8f-c3a0-483c-baf6-f5a55a7ff5b4",
    "user_id": ""
  }
}
```

## 设置单个行项目数量

```text
PATCH /{locale}/api/cart/{variant_id}
```

使用 `PATCH /{locale}/api/cart/{variant_id}` endpoint 更新购物车的行项目数量。

### 请求示例

如果该商品已在购物车中，则 `quantity` 会被设为该商品的新数量。

**请求示例**

```javascript
const data = {
  id: "298422_d41d8cd98f00b204e9800998ecf8427e",
  product_id: "588ed0ce-40af-44c7-8dea-afa18b489ef8",
  variant_id: "83196e5a-b25f-42c3-8df5-359d83ea7ae8",
  quantity: 3,
  properties: {
    Engraving: "Happy Anniversary"
  }
};

fetch(window.SHOPLAZZA.routes.root + '/api/cart/83196e5a-b25f-42c3-8df5-359d83ea7ae8', {
  method: 'PATCH',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  })
  .catch((error) => {
    console.error('Error: ', error);
  });
```

### 请求参数

**数据结构 | 示例**

- `variant_id` string

  款式 ID，路径和请求体中都要传。
- `id` string

  要修改的行项目 ID，取购物车行项目里的 `id`。
- `product_id` string

  商品 ID。
- `quantity` number

  商品数量。
- `properties` object

  行项目的自定义属性。传入的内容会整体替换该行项目原有的属性。

```json
{
  "id": "298422_d41d8cd98f00b204e9800998ecf8427e",
  "product_id": "588ed0ce-40af-44c7-8dea-afa18b489ef8",
  "variant_id": "83196e5a-b25f-42c3-8df5-359d83ea7ae8",
  "quantity": 3,
  "properties": {
    "Engraving": "Happy Anniversary"
  }
}
```

### 响应

**数据结构 | 示例**

- `cart` object

  - `line_items` object[]

    行项目列表。

    *   Array [

    - `id` string

      行项目的 ID。
    - `item_id` string
    - `product_id` string

      商品 ID。
    - `variant_id` string

      款式 ID。
    - `quantity` string

      商品数量。
    - `note` string

      行项目的备注。
    - `properties` string

      行项目上记录的自定义属性。
    - `custom` boolean

      该行项目是否为自定义商品。
    - `product_title` string

      商品名称。
    - `product_handle` string

      商品的 handle。
    - `product_url` string

      商品页的相对地址。
    - `variant_title` string

      款式标题，例如 `Blue, Size M`。
    - `product_type` string

      商品类型。
    - `price` string

      行项目单件商品的价格。
    - `compare_at_price` string

      划线价。
    - `origin_price` string
    - `line_price` string

      应用折扣前，该行项目所有商品的合计价格。
    - `original_line_price` number

      折扣前该行项目的原始价格。
    - `saved_price` number

      该行项目节省的金额。
    - `final_line_price` string

      应用行级折扣后，该行项目所有商品的合计价格。
    - `final_price` string

      应用行级折扣后，该行项目单件商品的价格。
    - `discount_applications` undefined[]

      该对象已应用的折扣。
    - `fixed_discount_total` string
    - `discount_total` string

      折扣总额。
    - `discount_id` string

      所应用折扣的 ID。
    - `available` boolean

      是否可购买。
    - `available_quantity` number

      仍可购买的数量。
    - `can_buy` boolean

      行项目所属款式是否可售。
    - `weight` string

      款式的重量。
    - `weight_unit` string

      重量单位，例如 `kg`。
    - `sku` string

      款式的 SKU，用于库存管理。
    - `spu` string

      商品的 SPU（标准产品单元）。
    - `requires_shipping` boolean

      是否需要物流配送。
    - `taxable` boolean

      是否需要计税。
    - `image` object

      行项目所属款式的图片。

      - `src` string

        图片的地址。
      - `path` string

        图片文件在图床上的路径。
      - `width` number

        图片宽度（像素）。
      - `height` number

        图片高度（像素）。
      - `alt` string

        图片的替代文本。
    - `options` object[]

      行项目所属款式的属性取值。

      *   Array [

      - `name` string

        商品属性名称，例如 `Color`。
      - `value` string

        该商品属性被选中的取值。
      *   ]
    - `wholesale_price` object[]

      批发价梯度列表。

      *   Array [

      - `min_quantity` number

        该批发价梯度要求的最小数量。
      - `price` string

        该批发价梯度的单价。
      *   ]
    - `parts_price` string
    - `product_tags` undefined[]

      商品的标签。
    - `published` boolean

      资源是否已发布。
    - `published_at` string

      发布时间（ISO-8601 格式）。
    - `inventory_quantity` number

      库存数量。
    - `inventory_policy` string

      商品缺货时是否继续销售。
    - `inventory_tracking` boolean

      是否启用库存追踪。
    - `cost_price` string

      款式的成本价。
    - `vendor` string

      商品的供应商。
    - `vendor_url` string

      商品供应商的链接。
    - `barcode` string

      款式的条形码。
    - `mixed_wholesale` boolean

      是否支持混批。
    - `tax_code` string
    - `retail_price` string

      以店铺主货币单位表示的零售价。
    - `item_text` string
    - `disabled` boolean
    - `is_free_gift` boolean

      该商品是否为赠品。
    - `custom_discounts` undefined[]
    *   ]
  - `ineffectives` undefined[]

    购物车中已不可购买的行项目。
  - `discount_applications` undefined[]

    该对象已应用的折扣。
  - `attributes` undefined[]
  - `total_discount` string

    购物车所有折扣节省的总金额。
  - `discount_line_item_price` string

    已应用折扣的折后总价。
  - `currency` string

    购物车使用的货币，例如 `USD`。
  - `original_line_price` string

    折扣前该行项目的原始价格。
  - `original_total_price` string

    应用折扣前购物车的总价。
  - `line_price` string

    应用折扣前，该行项目所有商品的合计价格。
  - `total_price` string

    应用折扣后购物车的总价。
  - `note` string

    对象上的备注。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  - `item_count` number

    购物车中的商品数量。
  - `total_weight` number

    购物车中所有商品的总重量。
  - `invalid_msg` string
  - `identity_cart_id` string

    购物车标识，用于把购物车与它生成的订单关联起来。
  - `user_id` string

```json
{
  "cart": {
    "line_items": [
      {
        "id": "684765446766863303_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684765446766863303",
        "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
        "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
        "quantity": "2",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "sample-product",
        "product_handle": "sample-product",
        "product_url": "/products/sample-product",
        "variant_title": "01",
        "product_type": "default",
        "price": "1.00",
        "compare_at_price": "1.00",
        "origin_price": "1.00",
        "line_price": "2.00",
        "original_line_price": 2,
        "saved_price": 0,
        "final_line_price": "2.00",
        "final_price": "1.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 999999999,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "",
        "spu": "",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "width": 3000,
          "height": 1500,
          "alt": ""
        },
        "options": [
          {
            "name": "Size",
            "value": "01"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "1.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-08-10T07:28:24Z",
        "inventory_quantity": 0,
        "inventory_policy": "",
        "inventory_tracking": false,
        "cost_price": "1.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      },
      {
        "id": "684698318307074183_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684698318307074183",
        "product_id": "b3b656ae-504f-4f01-a054-879a610925e3",
        "variant_id": "0699bc80-19ae-41bb-87c4-dbcbe5ed90a0",
        "quantity": "2",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "Sample product",
        "product_handle": "Sample product",
        "product_url": "/products/Sample product",
        "variant_title": "Black-S",
        "product_type": "default",
        "price": "10.00",
        "compare_at_price": "20.00",
        "origin_price": "10.00",
        "line_price": "20.00",
        "original_line_price": 40,
        "saved_price": 10,
        "final_line_price": "20.00",
        "final_price": "10.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 48,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "1111-BLACK-S-A001001",
        "spu": "1111",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "path": "50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "width": 1254,
          "height": 1254,
          "alt": ""
        },
        "options": [
          {
            "name": "Color",
            "value": "Black"
          },
          {
            "name": "Size",
            "value": "S"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "10.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-07-30T02:28:23Z",
        "inventory_quantity": 48,
        "inventory_policy": "deny",
        "inventory_tracking": true,
        "cost_price": "10.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      }
    ],
    "ineffectives": [],
    "discount_applications": [],
    "attributes": [],
    "total_discount": "0.00",
    "discount_line_item_price": "0.00",
    "currency": "USD",
    "original_line_price": "42.00",
    "original_total_price": "42.00",
    "line_price": "22.00",
    "total_price": "22.00",
    "note": "",
    "created_at": "2026-06-23T19:57:16Z",
    "updated_at": "2026-09-02T14:13:27Z",
    "item_count": 4,
    "total_weight": 0,
    "invalid_msg": "",
    "identity_cart_id": "879f8b8f-c3a0-483c-baf6-f5a55a7ff5b4",
    "user_id": ""
  }
}
```

## 移除购物车行项目

```text
DELETE /{locale}/api/cart/{variant_id}
```

使用 `DELETE /{locale}/api/cart/{variant_id}` endpoint 移除行项目。

### 请求示例

**请求示例**

```javascript
const data = {
  id: "298422_d41d8cd98f00b204e9800998ecf8427e",
  product_id: "588ed0ce-40af-44c7-8dea-afa18b489ef8",
  variant_id: "83196e5a-b25f-42c3-8df5-359d83ea7ae8",
};

fetch(window.SHOPLAZZA.routes.root + '/api/cart/83196e5a-b25f-42c3-8df5-359d83ea7ae8', {
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  })
  .catch((error) => {
    console.error('Error: ', error);
  });
```

### 请求参数

**数据结构 | 示例**

- `variant_id` string

  款式 ID，路径和请求体中都要传。
- `id` string

  要移除的行项目 ID，取购物车行项目里的 `id`。
- `product_id` string

  商品 ID。

```json
{
  "id": "298422_d41d8cd98f00b204e9800998ecf8427e",
  "product_id": "588ed0ce-40af-44c7-8dea-afa18b489ef8",
  "variant_id": "83196e5a-b25f-42c3-8df5-359d83ea7ae8"
}
```

### 响应

**数据结构 | 示例**

- `cart` object

  - `line_items` undefined[]

    行项目列表。
  - `ineffectives` undefined[]

    购物车中已不可购买的行项目。
  - `discount_applications` undefined[]

    该对象已应用的折扣。
  - `attributes` undefined[]
  - `total_discount` string

    购物车所有折扣节省的总金额。
  - `discount_line_item_price` string

    已应用折扣的折后总价。
  - `currency` string

    购物车使用的货币，例如 `USD`。
  - `original_line_price` string

    折扣前该行项目的原始价格。
  - `original_total_price` string

    应用折扣前购物车的总价。
  - `line_price` string

    应用折扣前，该行项目所有商品的合计价格。
  - `total_price` string

    应用折扣后购物车的总价。
  - `note` string

    对象上的备注。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  - `item_count` number

    购物车中的商品数量。
  - `total_weight` number

    购物车中所有商品的总重量。
  - `invalid_msg` string
  - `identity_cart_id` string

    购物车标识，用于把购物车与它生成的订单关联起来。
  - `user_id` string

```json
{
  "cart": {
    "line_items": [],
    "ineffectives": [],
    "discount_applications": [],
    "attributes": [],
    "total_discount": "0.00",
    "discount_line_item_price": "0.00",
    "currency": "USD",
    "original_line_price": "0.00",
    "original_total_price": "0.00",
    "line_price": "0.00",
    "total_price": "0.00",
    "note": "",
    "created_at": "2026-09-03T01:03:36Z",
    "updated_at": "2026-09-03T02:41:51Z",
    "item_count": 0,
    "total_weight": 0,
    "invalid_msg": "",
    "identity_cart_id": "879f8b8f-c3a0-483c-baf6-f5a55a7ff5b4",
    "user_id": "9fe44049-abab-4fed-ab3d-1bf4ffee8ef5"
  }
}
```

## 选择参与结账的行项目

```text
POST /{locale}/api/cart/cart-select
```

使用 `POST /{locale}/api/cart/cart-select` endpoint 选择购物车中哪些行项目参与结账。不在 `selected_cart_ids` 里的行项目会变为未选中。

### 请求示例

**请求示例**

```javascript
const data = {
  selected_cart_ids: ["684765446766863303_d41d8cd98f00b204e9800998ecf8427e"]
};

fetch(window.SHOPLAZZA.routes.root + '/api/cart/cart-select', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 请求参数

**数据结构 | 示例**

- `selected_cart_ids` string[]

  要选中的行项目 id 列表，取响应里的 `id`。

```json
{
  "selected_cart_ids": [
    "684765446766863303_d41d8cd98f00b204e9800998ecf8427e"
  ]
}
```

### 响应

**数据结构 | 示例**

- `cart` object

  - `line_items` object[]

    行项目列表。

    *   Array [

    - `id` string

      行项目的 ID。
    - `item_id` string
    - `product_id` string

      商品 ID。
    - `variant_id` string

      款式 ID。
    - `quantity` string

      商品数量。
    - `note` string

      行项目的备注。
    - `properties` string

      行项目上记录的自定义属性。
    - `custom` boolean

      该行项目是否为自定义商品。
    - `product_title` string

      商品名称。
    - `product_handle` string

      商品的 handle。
    - `product_url` string

      商品页的相对地址。
    - `variant_title` string

      款式标题，例如 `Blue, Size M`。
    - `product_type` string

      商品类型。
    - `price` string

      行项目单件商品的价格。
    - `compare_at_price` string

      划线价。
    - `origin_price` string
    - `line_price` string

      应用折扣前，该行项目所有商品的合计价格。
    - `original_line_price` number

      折扣前该行项目的原始价格。
    - `saved_price` number

      该行项目节省的金额。
    - `final_line_price` string

      应用行级折扣后，该行项目所有商品的合计价格。
    - `final_price` string

      应用行级折扣后，该行项目单件商品的价格。
    - `discount_applications` undefined[]

      该对象已应用的折扣。
    - `fixed_discount_total` string
    - `discount_total` string

      折扣总额。
    - `discount_id` string

      所应用折扣的 ID。
    - `available` boolean

      是否可购买。
    - `available_quantity` number

      仍可购买的数量。
    - `can_buy` boolean

      行项目所属款式是否可售。
    - `weight` string

      款式的重量。
    - `weight_unit` string

      重量单位，例如 `kg`。
    - `sku` string

      款式的 SKU，用于库存管理。
    - `spu` string

      商品的 SPU（标准产品单元）。
    - `requires_shipping` boolean

      是否需要物流配送。
    - `taxable` boolean

      是否需要计税。
    - `image` object

      行项目所属款式的图片。

      - `src` string

        图片的地址。
      - `path` string

        图片文件在图床上的路径。
      - `width` number

        图片宽度（像素）。
      - `height` number

        图片高度（像素）。
      - `alt` string

        图片的替代文本。
    - `options` object[]

      行项目所属款式的属性取值。

      *   Array [

      - `name` string

        商品属性名称，例如 `Color`。
      - `value` string

        该商品属性被选中的取值。
      *   ]
    - `wholesale_price` object[]

      批发价梯度列表。

      *   Array [

      - `min_quantity` number

        该批发价梯度要求的最小数量。
      - `price` string

        该批发价梯度的单价。
      *   ]
    - `parts_price` string
    - `product_tags` undefined[]

      商品的标签。
    - `published` boolean

      资源是否已发布。
    - `published_at` string

      发布时间（ISO-8601 格式）。
    - `inventory_quantity` number

      库存数量。
    - `inventory_policy` string

      商品缺货时是否继续销售。
    - `inventory_tracking` boolean

      是否启用库存追踪。
    - `cost_price` string

      款式的成本价。
    - `vendor` string

      商品的供应商。
    - `vendor_url` string

      商品供应商的链接。
    - `barcode` string

      款式的条形码。
    - `mixed_wholesale` boolean

      是否支持混批。
    - `tax_code` string
    - `retail_price` string

      以店铺主货币单位表示的零售价。
    - `item_text` string
    - `disabled` boolean
    - `is_free_gift` boolean

      该商品是否为赠品。
    - `custom_discounts` undefined[]
    *   ]
  - `ineffectives` undefined[]

    购物车中已不可购买的行项目。
  - `discount_applications` undefined[]

    该对象已应用的折扣。
  - `attributes` undefined[]
  - `total_discount` string

    购物车所有折扣节省的总金额。
  - `discount_line_item_price` string

    已应用折扣的折后总价。
  - `currency` string

    购物车使用的货币，例如 `USD`。
  - `original_line_price` string

    折扣前该行项目的原始价格。
  - `original_total_price` string

    应用折扣前购物车的总价。
  - `line_price` string

    应用折扣前，该行项目所有商品的合计价格。
  - `total_price` string

    应用折扣后购物车的总价。
  - `note` string

    对象上的备注。
  - `created_at` string

    创建时间（ISO-8601 格式）。
  - `updated_at` string

    最后更新时间（ISO-8601 格式）。
  - `item_count` number

    购物车中的商品数量。
  - `total_weight` number

    购物车中所有商品的总重量。
  - `invalid_msg` string
  - `identity_cart_id` string

    购物车标识，用于把购物车与它生成的订单关联起来。
  - `user_id` string

```json
{
  "cart": {
    "line_items": [
      {
        "id": "684765446766863303_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684765446766863303",
        "product_id": "14a309ec-b966-4cf9-a9bb-33baa821fdbc",
        "variant_id": "fff360dd-6457-466a-98b3-16878bacef5b",
        "quantity": "2",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "sample-product",
        "product_handle": "sample-product",
        "product_url": "/products/sample-product",
        "variant_title": "01",
        "product_type": "default",
        "price": "1.00",
        "compare_at_price": "1.00",
        "origin_price": "1.00",
        "line_price": "2.00",
        "original_line_price": 2,
        "saved_price": 0,
        "final_line_price": "2.00",
        "final_price": "1.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 999999999,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "",
        "spu": "",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "path": "free/e6e8dc980211cbef103e16371d6e0e61.jpeg",
          "width": 3000,
          "height": 1500,
          "alt": ""
        },
        "options": [
          {
            "name": "Size",
            "value": "01"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "1.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-08-10T07:28:24Z",
        "inventory_quantity": 0,
        "inventory_policy": "",
        "inventory_tracking": false,
        "cost_price": "1.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      },
      {
        "id": "684698318307074183_d41d8cd98f00b204e9800998ecf8427e",
        "item_id": "684698318307074183",
        "product_id": "b3b656ae-504f-4f01-a054-879a610925e3",
        "variant_id": "0699bc80-19ae-41bb-87c4-dbcbe5ed90a0",
        "quantity": "2",
        "note": "",
        "properties": "",
        "custom": false,
        "product_title": "Sample product",
        "product_handle": "Sample product",
        "product_url": "/products/Sample product",
        "variant_title": "Black-S",
        "product_type": "default",
        "price": "10.00",
        "compare_at_price": "20.00",
        "origin_price": "10.00",
        "line_price": "20.00",
        "original_line_price": 40,
        "saved_price": 10,
        "final_line_price": "20.00",
        "final_price": "10.00",
        "discount_applications": [],
        "fixed_discount_total": "0.00",
        "discount_total": "0.00",
        "discount_id": "",
        "available": true,
        "available_quantity": 48,
        "can_buy": true,
        "weight": "0.00",
        "weight_unit": "kg",
        "sku": "1111-BLACK-S-A001001",
        "spu": "1111",
        "requires_shipping": true,
        "taxable": false,
        "image": {
          "src": "//img.staticdj.com/50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "path": "50fa9b8c054f4d11b0d765de5f35dd4e.png",
          "width": 1254,
          "height": 1254,
          "alt": ""
        },
        "options": [
          {
            "name": "Color",
            "value": "Black"
          },
          {
            "name": "Size",
            "value": "S"
          }
        ],
        "wholesale_price": [
          {
            "min_quantity": 1,
            "price": "10.00"
          }
        ],
        "parts_price": "0.00",
        "product_tags": [],
        "published": true,
        "published_at": "2026-07-30T02:28:23Z",
        "inventory_quantity": 48,
        "inventory_policy": "deny",
        "inventory_tracking": true,
        "cost_price": "10.00",
        "vendor": "",
        "vendor_url": "",
        "barcode": "",
        "mixed_wholesale": false,
        "tax_code": "",
        "retail_price": "0.00",
        "item_text": "",
        "disabled": false,
        "is_free_gift": false,
        "custom_discounts": []
      }
    ],
    "ineffectives": [],
    "discount_applications": [],
    "attributes": [],
    "total_discount": "0.00",
    "discount_line_item_price": "0.00",
    "currency": "USD",
    "original_line_price": "0.00",
    "original_total_price": "0.00",
    "line_price": "0.00",
    "total_price": "0.00",
    "note": "",
    "created_at": "2026-06-23T19:57:16Z",
    "updated_at": "2026-09-02T14:13:27Z",
    "item_count": 0,
    "total_weight": 0,
    "invalid_msg": "",
    "identity_cart_id": "879f8b8f-c3a0-483c-baf6-f5a55a7ff5b4",
    "user_id": ""
  }
}
```

## 保存购物车备注

```text
POST /{locale}/api/cart/note
```

使用 `POST /{locale}/api/cart/note` endpoint 为购物车保存备注。请求体是 `application/x-www-form-urlencoded`，不是 JSON。

### 请求示例

**请求示例**

```javascript
const body = new URLSearchParams({ note: 'Leave the parcel at the door' });

fetch(window.SHOPLAZZA.routes.root + '/api/cart/note', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: body
})
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### 请求参数

- `note` string

  要保存到购物车的备注。

### 响应

**数据结构 | 示例**

- `state` string

  请求结果标识，`success` 或 `0` 表示请求成功。
- `message` string

  响应返回的结果说明。
- `errors` undefined[]

  请求失败时返回的错误列表。
- `data` string

  响应数据主体。

```json
{
  "state": "success",
  "message": "success",
  "errors": [],
  "data": null
}
```

## 获取购物车商品数量

```text
GET /{locale}/api/cart/count
```

使用 `GET /{locale}/api/cart/count` endpoint 获取购物车数量。

### 请求示例

**请求示例**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/cart/count')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  })
  .catch((error) => {
    console.error('Error: ', error);
  });
```

### 响应

**数据结构 | 示例**

- `state` string

  请求结果标识，`success` 或 `0` 表示请求成功。
- `message` string

  响应返回的结果说明。
- `errors` undefined[]

  请求失败时返回的错误列表。
- `data` object

  响应数据主体。

  - `count` number

    购物车中的商品数量。

```json
{
  "state": "success",
  "message": "success",
  "errors": [],
  "data": {
    "count": 2
  }
}
```
