购物车
Cart API 用于在客户会话期间与购物车进行交互。本指南介绍如何使用 Cart API 来添加、更新、删除购物车行项目,以及更新购物车备注。
获取购物车
GET /{locale}/api/cart
使用 GET /{locale}/api/cart endpoint 以 JSON 格式获取购物车。
所有货币属性均以客户的展示货币返回。若您已添加其他市场,可在 response 中使用 currency 字段来查看客户的展示货币。
以下是使用 fetch API 的简化 GET 请求示例。headers 中的 Content-Type 应设置为 application/json。Response 为关联行项目的 JSON 格式。
请求示例
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 [idstring行项目的 ID。
item_idstringproduct_idstring商品 ID。
variant_idstring款式 ID。
quantitystring商品数量。
notestring行项目的备注。
propertiesstring行项目的自定义属性,返回的是 JSON 字符串,使用前需要自行解析。
customboolean该行项目是否为自定义商品。
product_titlestring商品名称。
product_handlestring商品的 handle。
product_urlstring商品页的相对地址。
variant_titlestring款式标题,例如
Blue, Size M。product_typestring商品类型。
pricestring行项目单件商品的价格。
compare_at_pricestring划线价。
origin_pricestringline_pricestring应用折扣前,该行项目所有商品的合计价格。
original_line_pricenumber折扣前该行项目的原始价格。
saved_pricenumber该行项目节省的金额。
final_line_pricestring应用行级折扣后,该行项目所有商品的合计价格。
final_pricestring应用行级折扣后,该行项目单件商品的价格。
discount_applicationsundefined[]该对象已应用的折扣。
fixed_discount_totalstringdiscount_totalstring折扣总额。
discount_idstring所应用折扣的 ID。
availableboolean是否可购买。
available_quantitynumber仍可购买的数量。
can_buyboolean行项目所属款式是否可售。
weightstring款式的重量。
weight_unitstring重量单位,例如
kg。skustring款式的 SKU,用于库存管理。
spustring商品的 SPU(标准产品单元)。
requires_shippingboolean是否需要物流配送。
taxableboolean是否需要计税。
image object
行项目所属款式的图片。
srcstring图片的地址。
pathstring图片文件在图床上的路径。
widthnumber图片宽度(像素)。
heightnumber图片高度(像素)。
altstring图片的替代文本。
options object[]
行项目所属款式的属性取值。
Array [namestring商品属性名称,例如
Color。valuestring该商品属性被选中的取值。
]wholesale_price object[]
批发价梯度列表。
Array [min_quantitynumber该批发价梯度要求的最小数量。
pricestring该批发价梯度的单价。
]parts_pricestringproduct_tagsundefined[]商品的标签。
publishedboolean资源是否已发布。
published_atstring发布时间(ISO-8601 格式)。
inventory_quantitynumber库存数量。
inventory_policystring商品缺货时是否继续销售。
inventory_trackingboolean是否启用库存追踪。
cost_pricestring款式的成本价。
vendorstring商品的供应商。
vendor_urlstring商品供应商的链接。
barcodestring款式的条形码。
mixed_wholesaleboolean是否支持混批。
tax_codestringretail_pricestring以店铺主货币单位表示的零售价。
item_textstringdisabledbooleanis_free_giftboolean该商品是否为赠品。
custom_discountsundefined[]]ineffectivesundefined[]购物车中已不可购买的行项目。
discount_applicationsundefined[]该对象已应用的折扣。
attributesundefined[]total_discountstring购物车所有折扣节省的总金额。
discount_line_item_pricestring已应用折扣的折后总价。
currencystring购物车使用的货币,例如
USD。original_line_pricestring折扣前该行项目的原始价格。
original_total_pricestring应用折扣前购物车的总价。
line_pricestring应用折扣前,该行项目所有商品的合计价格。
total_pricestring应用折扣后购物车的总价。
notestring对象上的备注。
created_atstring创建时间(ISO-8601 格式)。
updated_atstring最后更新时间(ISO-8601 格式)。
item_countnumber购物车中的商品数量。
total_weightnumber购物车中所有商品的总重量。
invalid_msgstringidentity_cart_idstring购物车标识,用于把购物车与它生成的订单关联起来。
user_idstring已登录顾客的 ID,游客状态下没有这个值。
{
"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"
}
}
添加单个规格到购物车
POST /{locale}/api/cart
使用 POST /{locale}/api/cart endpoint 将单个 variant 添加到购物车。
请求示例
如果该商品已在购物车中,则 quantity 会累加到该商品的当前数量上。
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);
});
请求参数
- 数据结构
- 示例
variant 所属商品的 id。
需要添加到购物车的数量。
variant 的 id。
refer_info object
请求来源的引用信息。它包含一个 source 属性,可能的取值为:add_to_cart、buy_now 或 cart。
挂在行项目上的自定义属性,例如定制选项。属性会随行项目一直带到订单。
{
"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 字符串,读键之前要先解析。加购时没有传属性的行返回空字符串,所以要先判空,并且对解析结果不是普通对象的情况做兜底。
键以下划线开头的属性仍会由本接口返回,但不会展示给顾客,后台订单页也不显示。从商品页写入属性到从订单读回的完整流程,见给购物车和订单添加自定义属性。
响应
- 数据结构
- 示例
- Array [
- Array [
- ]
- Array [
- ]
- ]
请求结果标识,success 或 0 表示请求成功。
响应返回的结果说明。
请求失败时返回的错误列表。
data object
响应数据主体。
items object[]
购物车中的行项目列表。
行项目的 ID。
商品 ID。
款式 ID。
商品数量。
行项目的备注。
行项目的自定义属性,返回的是 JSON 字符串,使用前需要自行解析。
该行项目是否为自定义商品。
商品名称。
商品的 handle。
商品页的相对地址。
款式标题,例如 Blue, Size M。
商品类型。
行项目单件商品的价格。
划线价。
是否可购买。
仍可购买的数量。
款式的重量。
重量单位,例如 kg。
款式的 SKU,用于库存管理。
商品的 SPU(标准产品单元)。
是否需要物流配送。
是否需要计税。
image object
行项目所属款式的图片。
图片的地址。
图片文件在图床上的路径。
图片宽度(像素)。
图片高度(像素)。
图片的替代文本。
options object[]
行项目所属款式的属性取值。
商品属性名称,例如 Color。
该商品属性被选中的取值。
wholesale_price object[]
批发价梯度列表。
该批发价梯度要求的最小数量。
该批发价梯度的单价。
商品的标签。
资源是否已发布。
发布时间(ISO-8601 格式)。
库存数量。
商品缺货时是否继续销售。
是否启用库存追踪。
款式的成本价。
商品的供应商。
商品供应商的链接。
款式的条形码。
是否支持混批。
以店铺主货币单位表示的零售价。
{
"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
}
]
}
}
批量添加规格到购物车
POST /{locale}/api/cart/batch
使用 POST /{locale}/api/cart/batch endpoint 将一个或多个 variants 添加到购物车。
请求示例
如果该商品已在购物车中,则 quantity 会累加到该商品的当前数量上。
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);
});
请求参数
- 数据结构
- 示例
- Array [
- ]
line_items object[]
行项目列表。
要加入购物车的商品 ID。
要加入购物车的商品款式 ID。
加入的数量。
挂在行项目上的自定义属性。
{
"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"
}
]
}
响应
- 数据结构
- 示例
- Array [
- Array [
- ]
- Array [
- ]
- ]
items object[]
购物车中的行项目列表。
行项目的 ID。
商品 ID。
款式 ID。
商品数量。
行项目的备注。
行项目上记录的自定义属性。
该行项目是否为自定义商品。
商品名称。
商品的 handle。
商品页的相对地址。
款式标题,例如 Blue, Size M。
商品类型。
行项目单件商品的价格。
划线价。
是否可购买。
仍可购买的数量。
款式的重量。
重量单位,例如 kg。
款式的 SKU,用于库存管理。
商品的 SPU(标准产品单元)。
是否需要物流配送。
是否需要计税。
image object
行项目所属款式的图片。
图片的地址。
图片文件在图床上的路径。
图片宽度(像素)。
图片高度(像素)。
图片的替代文本。
options object[]
行项目所属款式的属性取值。
商品属性名称,例如 Color。
该商品属性被选中的取值。
wholesale_price object[]
批发价梯度列表。
该批发价梯度要求的最小数量。
该批发价梯度的单价。
商品的标签。
资源是否已发布。
发布时间(ISO-8601 格式)。
库存数量。
商品缺货时是否继续销售。
是否启用库存追踪。
款式的成本价。
商品的供应商。
商品供应商的链接。
款式的条形码。
是否支持混批。
以店铺主货币单位表示的零售价。
{
"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
}
]
}
批量设置行项目数量
POST /{locale}/api/cart/update
使用 POST /{locale}/api/cart/update endpoint 设置购物车中已有行项目的数量。与 POST /{locale}/api/cart 不同,这里传的数量是覆盖当前数量,而不是累加。
请求示例
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...
});
请求参数
- 数据结构
- 示例
- Array [
- ]
line_items object[]
要修改的行项目列表。
variant 所属商品的 id。
variant 的 id。
该行项目的新数量。
{
"line_items": [
{
"product_id": "b1ab6324-ae4f-4cca-907e-18af16839447",
"variant_id": "4a3d825c-2fac-4f72-a68b-b8604b0935c4",
"quantity": 1
}
]
}
响应
- 数据结构
- 示例
cart object
line_items object[]
行项目列表。
Array [idstring行项目的 ID。
item_idstringproduct_idstring商品 ID。
variant_idstring款式 ID。
quantitystring商品数量。
notestring行项目的备注。
propertiesstring行项目上记录的自定义属性。
customboolean该行项目是否为自定义商品。
product_titlestring商品名称。
product_handlestring商品的 handle。
product_urlstring商品页的相对地址。
variant_titlestring款式标题,例如
Blue, Size M。product_typestring商品类型。
pricestring行项目单件商品的价格。
compare_at_pricestring划线价。
origin_pricestringline_pricestring应用折扣前,该行项目所有商品的合计价格。
original_line_pricenumber折扣前该行项目的原始价格。
saved_pricenumber该行项目节省的金额。
final_line_pricestring应用行级折扣后,该行项目所有商品的合计价格。
final_pricestring应用行级折扣后,该行项目单件商品的价格。
discount_applicationsundefined[]该对象已应用的折扣。
fixed_discount_totalstringdiscount_totalstring折扣总额。
discount_idstring所应用折扣的 ID。
availableboolean是否可购买。
available_quantitynumber仍可购买的数量。
can_buyboolean行项目所属款式是否可售。
weightstring款式的重量。
weight_unitstring重量单位,例如
kg。skustring款式的 SKU,用于库存管理。
spustring商品的 SPU(标准产品单元)。
requires_shippingboolean是否需要物流配送。
taxableboolean是否需要计税。
image object
行项目所属款式的图片。
srcstring图片的地址。
pathstring图片文件在图床上的路径。
widthnumber图片宽度(像素)。
heightnumber图片高度(像素)。
altstring图片的替代文本。
options object[]
行项目所属款式的属性取值。
Array [namestring商品属性名称,例如
Color。valuestring该商品属性被选中的取值。
]wholesale_price object[]
批发价梯度列表。
Array [min_quantitynumber该批发价梯度要求的最小数量。
pricestring该批发价梯度的单价。
]parts_pricestringproduct_tagsundefined[]商品的标签。
publishedboolean资源是否已发布。
published_atstring发布时间(ISO-8601 格式)。
inventory_quantitynumber库存数量。
inventory_policystring商品缺货时是否继续销售。
inventory_trackingboolean是否启用库存追踪。
cost_pricestring款式的成本价。
vendorstring商品的供应商。
vendor_urlstring商品供应商的链接。
barcodestring款式的条形码。
mixed_wholesaleboolean是否支持混批。
tax_codestringretail_pricestring以店铺主货币单位表示的零售价。
item_textstringdisabledbooleanis_free_giftboolean该商品是否为赠品。
custom_discountsundefined[]]ineffectivesundefined[]购物车中已不可购买的行项目。
discount_applicationsundefined[]该对象已应用的折扣。
attributesundefined[]total_discountstring购物车所有折扣节省的总金额。
discount_line_item_pricestring已应用折扣的折后总价。
currencystring购物车使用的货币,例如
USD。original_line_pricestring折扣前该行项目的原始价格。
original_total_pricestring应用折扣前购物车的总价。
line_pricestring应用折扣前,该行项目所有商品的合计价格。
total_pricestring应用折扣后购物车的总价。
notestring对象上的备注。
created_atstring创建时间(ISO-8601 格式)。
updated_atstring最后更新时间(ISO-8601 格式)。
item_countnumber购物车中的商品数量。
total_weightnumber购物车中所有商品的总重量。
invalid_msgstringidentity_cart_idstring购物车标识,用于把购物车与它生成的订单关联起来。
user_idstring
{
"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": ""
}
}
设置单个行项目数量
PATCH /{locale}/api/cart/{variant_id}
使用 PATCH /{locale}/api/cart/{variant_id} endpoint 更新购物车的行项目数量。
请求示例
如果该商品已在购物车中,则 quantity 会被设为该商品的新数量。
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);
});
请求参数
- 数据结构
- 示例
款式 ID,路径和请求体中都要传。
要修改的行项目 ID,取购物车行项目里的 id。
商品 ID。
商品数量。
行项目的自定义属性。传入的内容会整体替换该行项目原有的属性。
{
"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 [idstring行项目的 ID。
item_idstringproduct_idstring商品 ID。
variant_idstring款式 ID。
quantitystring商品数量。
notestring行项目的备注。
propertiesstring行项目上记录的自定义属性。
customboolean该行项目是否为自定义商品。
product_titlestring商品名称。
product_handlestring商品的 handle。
product_urlstring商品页的相对地址。
variant_titlestring款式标题,例如
Blue, Size M。product_typestring商品类型。
pricestring行项目单件商品的价格。
compare_at_pricestring划线价。
origin_pricestringline_pricestring应用折扣前,该行项目所有商品的合计价格。
original_line_pricenumber折扣前该行项目的原始价格。
saved_pricenumber该行项目节省的金额。
final_line_pricestring应用行级折扣后,该行项目所有商品的合计价格。
final_pricestring应用行级折扣后,该行项目单件商品的价格。
discount_applicationsundefined[]该对象已应用的折扣。
fixed_discount_totalstringdiscount_totalstring折扣总额。
discount_idstring所应用折扣的 ID。
availableboolean是否可购买。
available_quantitynumber仍可购买的数量。
can_buyboolean行项目所属款式是否可售。
weightstring款式的重量。
weight_unitstring重量单位,例如
kg。skustring款式的 SKU,用于库存管理。
spustring商品的 SPU(标准产品单元)。
requires_shippingboolean是否需要物流配送。
taxableboolean是否需要计税。
image object
行项目所属款式的图片。
srcstring图片的地址。
pathstring图片文件在图床上的路径。
widthnumber图片宽度(像素)。
heightnumber图片高度(像素)。
altstring图片的替代文本。
options object[]
行项目所属款式的属性取值。
Array [namestring商品属性名称,例如
Color。valuestring该商品属性被选中的取值。
]wholesale_price object[]
批发价梯度列表。
Array [min_quantitynumber该批发价梯度要求的最小数量。
pricestring该批发价梯度的单价。
]parts_pricestringproduct_tagsundefined[]商品的标签。
publishedboolean资源是否已发布。
published_atstring发布时间(ISO-8601 格式)。
inventory_quantitynumber库存数量。
inventory_policystring商品缺货时是否继续销售。
inventory_trackingboolean是否启用库存追踪。
cost_pricestring款式的成本价。
vendorstring商品的供应商。
vendor_urlstring商品供应商的链接。
barcodestring款式的条形码。
mixed_wholesaleboolean是否支持混批。
tax_codestringretail_pricestring以店铺主货币单位表示的零售价。
item_textstringdisabledbooleanis_free_giftboolean该商品是否为赠品。
custom_discountsundefined[]]ineffectivesundefined[]购物车中已不可购买的行项目。
discount_applicationsundefined[]该对象已应用的折扣。
attributesundefined[]total_discountstring购物车所有折扣节省的总金额。
discount_line_item_pricestring已应用折扣的折后总价。
currencystring购物车使用的货币,例如
USD。original_line_pricestring折扣前该行项目的原始价格。
original_total_pricestring应用折扣前购物车的总价。
line_pricestring应用折扣前,该行项目所有商品的合计价格。
total_pricestring应用折扣后购物车的总价。
notestring对象上的备注。
created_atstring创建时间(ISO-8601 格式)。
updated_atstring最后更新时间(ISO-8601 格式)。
item_countnumber购物车中的商品数量。
total_weightnumber购物车中所有商品的总重量。
invalid_msgstringidentity_cart_idstring购物车标识,用于把购物车与它生成的订单关联起来。
user_idstring
{
"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": ""
}
}
移除购物车行项目
DELETE /{locale}/api/cart/{variant_id}
使用 DELETE /{locale}/api/cart/{variant_id} endpoint 移除行项目。
请求示例
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);
});
请求参数
- 数据结构
- 示例
款式 ID,路径和请求体中都要传。
要移除的行项目 ID,取购物车行项目里的 id。
商品 ID。
{
"id": "298422_d41d8cd98f00b204e9800998ecf8427e",
"product_id": "588ed0ce-40af-44c7-8dea-afa18b489ef8",
"variant_id": "83196e5a-b25f-42c3-8df5-359d83ea7ae8"
}
响应
- 数据结构
- 示例
cart object
line_itemsundefined[]行项目列表。
ineffectivesundefined[]购物车中已不可购买的行项目。
discount_applicationsundefined[]该对象已应用的折扣。
attributesundefined[]total_discountstring购物车所有折扣节省的总金额。
discount_line_item_pricestring已应用折扣的折后总价。
currencystring购物车使用的货币,例如
USD。original_line_pricestring折扣前该行项目的原始价格。
original_total_pricestring应用折扣前购物车的总价。
line_pricestring应用折扣前,该行项目所有商品的合计价格。
total_pricestring应用折扣后购物车的总价。
notestring对象上的备注。
created_atstring创建时间(ISO-8601 格式)。
updated_atstring最后更新时间(ISO-8601 格式)。
item_countnumber购物车中的商品数量。
total_weightnumber购物车中所有商品的总重量。
invalid_msgstringidentity_cart_idstring购物车标识,用于把购物车与它生成的订单关联起来。
user_idstring
{
"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"
}
}
选择参与结账的行项目
POST /{locale}/api/cart/cart-select
使用 POST /{locale}/api/cart/cart-select endpoint 选择购物车中哪些行项目参与结账。不在 selected_cart_ids 里的行项目会变为未选中。
请求示例
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...
});
请求参数
- 数据结构
- 示例
要选中的行项目 id 列表,取响应里的 id。
{
"selected_cart_ids": [
"684765446766863303_d41d8cd98f00b204e9800998ecf8427e"
]
}
响应
- 数据结构
- 示例
cart object
line_items object[]
行项目列表。
Array [idstring行项目的 ID。
item_idstringproduct_idstring商品 ID。
variant_idstring款式 ID。
quantitystring商品数量。
notestring行项目的备注。
propertiesstring行项目上记录的自定义属性。
customboolean该行项目是否为自定义商品。
product_titlestring商品名称。
product_handlestring商品的 handle。
product_urlstring商品页的相对地址。
variant_titlestring款式标题,例如
Blue, Size M。product_typestring商品类型。
pricestring行项目单件商品的价格。
compare_at_pricestring划线价。
origin_pricestringline_pricestring应用折扣前,该行项目所有商品的合计价格。
original_line_pricenumber折扣前该行项目的原始价格。
saved_pricenumber该行项目节省的金额。
final_line_pricestring应用行级折扣后,该行项目所有商品的合计价格。
final_pricestring应用行级折扣后,该行项目单件商品的价格。
discount_applicationsundefined[]该对象已应用的折扣。
fixed_discount_totalstringdiscount_totalstring折扣总额。
discount_idstring所应用折扣的 ID。
availableboolean是否可购买。
available_quantitynumber仍可购买的数量。
can_buyboolean行项目所属款式是否可售。
weightstring款式的重量。
weight_unitstring重量单位,例如
kg。skustring款式的 SKU,用于库存管理。
spustring商品的 SPU(标准产品单元)。
requires_shippingboolean是否需要物流配送。
taxableboolean是否需要计税。
image object
行项目所属款式的图片。
srcstring图片的地址。
pathstring图片文件在图床上的路径。
widthnumber图片宽度(像素)。
heightnumber图片高度(像素)。
altstring图片的替代文本。
options object[]
行项目所属款式的属性取值。
Array [namestring商品属性名称,例如
Color。valuestring该商品属性被选中的取值。
]wholesale_price object[]
批发价梯度列表。
Array [min_quantitynumber该批发价梯度要求的最小数量。
pricestring该批发价梯度的单价。
]parts_pricestringproduct_tagsundefined[]商品的标签。
publishedboolean资源是否已发布。
published_atstring发布时间(ISO-8601 格式)。
inventory_quantitynumber库存数量。
inventory_policystring商品缺货时是否继续销售。
inventory_trackingboolean是否启用库存追踪。
cost_pricestring款式的成本价。
vendorstring商品的供应商。
vendor_urlstring商品供应商的链接。
barcodestring款式的条形码。
mixed_wholesaleboolean是否支持混批。
tax_codestringretail_pricestring以店铺主货币单位表示的零售价。
item_textstringdisabledbooleanis_free_giftboolean该商品是否为赠品。
custom_discountsundefined[]]ineffectivesundefined[]购物车中已不可购买的行项目。
discount_applicationsundefined[]该对象已应用的折扣。
attributesundefined[]total_discountstring购物车所有折扣节省的总金额。
discount_line_item_pricestring已应用折扣的折后总价。
currencystring购物车使用的货币,例如
USD。original_line_pricestring折扣前该行项目的原始价格。
original_total_pricestring应用折扣前购物车的总价。
line_pricestring应用折扣前,该行项目所有商品的合计价格。
total_pricestring应用折扣后购物车的总价。
notestring对象上的备注。
created_atstring创建时间(ISO-8601 格式)。
updated_atstring最后更新时间(ISO-8601 格式)。
item_countnumber购物车中的商品数量。
total_weightnumber购物车中所有商品的总重量。
invalid_msgstringidentity_cart_idstring购物车标识,用于把购物车与它生成的订单关联起来。
user_idstring
{
"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": ""
}
}
保存购物车备注
POST /{locale}/api/cart/note
使用 POST /{locale}/api/cart/note endpoint 为购物车保存备注。请求体是 application/x-www-form-urlencoded,不是 JSON。
请求示例
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...
});
请求参数
要保存到购物车的备注。
响应
- 数据结构
- 示例
请求结果标识,success 或 0 表示请求成功。
响应返回的结果说明。
请求失败时返回的错误列表。
响应数据主体。
{
"state": "success",
"message": "success",
"errors": [],
"data": null
}
获取购物车商品数量
GET /{locale}/api/cart/count
使用 GET /{locale}/api/cart/count endpoint 获取购物车数量。
请求示例
fetch(window.SHOPLAZZA.routes.root + '/api/cart/count')
.then((response) => response.json())
.then((data) => {
// do something...
})
.catch((error) => {
console.error('Error: ', error);
});
响应
- 数据结构
- 示例
请求结果标识,success 或 0 表示请求成功。
响应返回的结果说明。
请求失败时返回的错误列表。
data object
响应数据主体。
购物车中的商品数量。
{
"state": "success",
"message": "success",
"errors": [],
"data": {
"count": 2
}
}