调整购物车商品数量
购物车 ajax API ,用于客户在会话期间产生的购物车交互,当需要更新购物车中商品的数量时候可调用该接口。
请求信息
API路径:
POST
https://{handle}.myshopline.com/cart/change
请求header:
参数名 | 参数类型 | 是否必填 | 是否数组 | 默认值 | 描述 |
---|---|---|---|---|---|
Content-Type | String | Y | N | application/json | |
Accept | String | N | N | */* | 响应内容类型和状态码根据该字段传值不同而有所区别,有效枚举值包含: \*/\* :
application/json :
|
请求body:
**参数名 | 参数类型 | 是否必填 | 是否数组 | 示例 | 描述 |
---|---|---|---|---|---|
id | String | N | N | 36110175633573 | 商品唯一标识 即sku_id |
line | Integer | N | N | 1 | 商品行的位置下标,从1开始 |
quantity | Long | Y | N | 2 | 添加的商品数目,添加后购物车中该商品数目=原数目+此次添加数目 |
groupId | String | N | N | 0 | |
sections | String | N | N | cart-notification-product,cart-notification-button | 需要捆绑 section 渲染的 section,多个 section 使用 , 符号分割 |
sections_url | String | N | N | /products/dress | 指定捆绑 section 渲染的页面 |
响应信息
响应body:
一级参数名 | 二级参数名 | 三级参数名 | 四级参数名 | 五级参数名 | 参数类型 | 是否数组 | 示例 | 描述 |
---|---|---|---|---|---|---|---|---|
token | String | N | 36110175633573 | 购物车token | ||||
note | String | N | 购物车备注 | 购物车备注 | ||||
attributes | Map<String,String> | N | 购物车属性 | |||||
original_total_price | Double | N | 购物车商品原价总计 | |||||
items_subtotal_price | Double | N | 购物车商品小计(已扣减商品行优惠) | |||||
total_price | Double | N | 购物车最后计价(已扣减商品行折扣和购物车折扣) | |||||
total_discount | Double | N | 购物车总计优惠金额(商品行优惠+购物车级别优惠) | |||||
total_weight | Double | N | 商品总计重量 | |||||
item_count | Integer | N | 购物车商品总数量 | |||||
requires_shipping | Boolean | N | 是否需要发货(只要购物车商品有一个需要发货) | |||||
currency | String | N | 结算币种 | |||||
cart_level_discount_applications | Object | Y | 购物车级别优惠信息 | |||||
amount | Double | N | 优惠金额 | |||||
discount_application | Object | N | ||||||
type | Integer | N | ||||||
title | String | N | 优惠名称 | |||||
description | String | N | 优惠描述 | |||||
value | Double | N | 优惠金额 | |||||
created_at | String | N | 活动创建时间 | |||||
value_type | String | N | 折扣活动类型: | |||||
target_type | String | N | 优惠作用对象 | |||||
items | Object | Y | 购物车商品列表 | |||||
id | String | N | 36110175633573 | 商品唯一标识 即sku_id | ||||
group_id | String | N | 0 | 商品组ID | ||||
quantity | Integer | N | 2 | 商品数量 | ||||
properties | Long | N | ![]() | |||||
variant_id | String | N | 36110175633573 | 商品 sku_id | ||||
title | String | N | test1 | 商品title+sku title 名称+规格 | ||||
price | Double | N | 200 | 商品 售价 | ||||
original_price | Double | N | 200 | 商品 原价 (可能为0) | ||||
discounted_price | Double | N | 200 | 减去优惠后的价格 | ||||
line_price | Double | N | 200 | 商品行售价 | ||||
original_line_price | Double | N | 200 | 商品行原价(可能为0) | ||||
total_discount | Double | N | 200 | 单个商品的总折扣金额 | ||||
discounts | Object | Y | 商品行优惠 | |||||
amount | Double | N | 200 | 优惠金额 | ||||
title | String | N | 满100减50 | 优惠名称 | ||||
sku | String | N | 红色XL | 商品 sku_id | ||||
grams | String | N | 100 | 商品重量 单位g | ||||
taxable | Boolean | N | true | 是否收税 | ||||
product_id | String | N | 36110175633573 | 商品 spu_id | ||||
gift_card | Boolean | N | true | 是否为礼品卡商品 | ||||
final_price | Double | N | 500 | 商品参与计价的金额 | ||||
final_line_price | Double | N | 500 | 商品行参与计价的金额 | ||||
url | String | N | https://ddfasdfasdf | 商品主站链接 | ||||
featured_image | String | N | ||||||
aspectRatio | Double | N | 纵横比 | |||||
alt | String | N | 鼠标悬停提示信息 | |||||
height | Integer | N | 显示高度 | |||||
url | String | N | 图片 | |||||
width | Integer | N | 显示宽度 | |||||
image | String | N | 商品image | |||||
handle | String | N | 商品handle | |||||
requires_shipping | String | N | 是否需要发货 | |||||
product_title | String | N | 商品title | |||||
variant_title | String | N | 所有规格的拼接 | |||||
variant_options | String | N | 所有规格枚举 | |||||
options_with_values | String | N | 规格 | |||||
name | String | N | 规格名称 | |||||
value | String | N | 规格值 | |||||
line_level_discount_allocations | String | N | 商品行优惠信息 | |||||
amount | Double | N | 优惠金额 | |||||
discountApplication | String | N | ||||||
type | Integer | N | ||||||
title | String | N | 优惠名称 | |||||
description | String | N | 优惠描述 | |||||
value | Double | N | 优惠金额 | |||||
created_at | String | N | 活动创建时间 | |||||
value_type | String | N | 折扣活动类型 | |||||
target_type | String | N | 优惠作用对象 | |||||
line_level_total_discount | Double | N | 商品行优惠总金额 | |||||
sections | Object | N | { "header": "<p>header</p>" } | section 渲染结果 |
请求、响应示例
场景1:正常更新购物车
{
"token": "a5f1d38bf17f4578959ad0d8e4ff7cac",
"note": "购物车备注",
"attributes": {},
"currency": "USD",
"original_total_price": 110,
"items_subtotal_price": 101,
"total_price": 11,
"total_discount": 99,
"total_weight": 0,
"item_count": 11,
"requires_shipping": true,
"cart_level_discount_applications": [
{
"amount": 90,
"discount_application": {
"type": 1,
"title": "所有商品满100减90",
"description": null,
"value": 90,
"created_at": null,
"value_type": "fix_amount",
"target_type": "line_item"
}
}
],
"items": [
{
"id": "18053690554475963802050412",
"properties": null,
"quantity": 10,
"title": "自定义商品100个 ",
"price": 10,
"discounts": [],
"sku": "18053690554475963802050412",
"grams": "0.0",
"taxable": true,
"url": "https://{handle}/products/自定义商品100个",
"image": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"handle": "自定义商品100个",
"group_id": "0",
"variant_id": "18053690554475963802050412",
"original_price": 0,
"discounted_price": 10,
"line_price": 100,
"original_line_price": 0,
"total_discount": 0,
"product_id": "16053690554473111675530412",
"gift_card": false,
"final_price": 10,
"final_line_price": 100,
"featured_image": {
"alt": null,
"height": null,
"url": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"width": null,
"aspect_ratio": null
},
"requires_shipping": true,
"product_title": "自定义商品100个",
"variant_title": "",
"variant_options": [],
"options_with_values": [],
"line_level_discount_allocations": [],
"line_level_total_discount": 0
},
{
"id": "18053340946130027787140412",
"properties": null,
"quantity": 1,
"title": "仅仅是限时促销商品 ",
"price": 10,
"discounts": [
{
"amount": 9,
"title": "促销活动1"
}
],
"sku": "18053340946130027787140412",
"grams": "0.0",
"taxable": true,
"url": "https://{handle}//products/仅仅是限时促销商品",
"image": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"handle": "仅仅是限时促销商品",
"group_id": "0",
"variant_id": "18053340946130027787140412",
"original_price": 0,
"discounted_price": 1,
"line_price": 10,
"original_line_price": 0,
"total_discount": 9,
"product_id": "16053340946118954823760412",
"gift_card": false,
"final_price": 1,
"final_line_price": 1,
"featured_image": {
"alt": null,
"height": null,
"url": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"width": null,
"aspect_ratio": null
},
"requires_shipping": true,
"product_title": "仅仅是限时促销商品",
"variant_title": "",
"variant_options": [],
"options_with_values": [],
"line_level_discount_allocations": [
{
"amount": 9,
"discount_application": {
"type": 8,
"title": "促销活动1",
"description": null,
"value": 9,
"created_at": null,
"value_type": null,
"target_type": "line_item"
}
}
],
"line_level_total_discount": 9
}
],
"sections": {}
}
场景2:请求错误:
POST
https://{handle}.myshopline.com/cart/change
status:404
{
"message": "error code",
"description": "error description"
}
场景3:捆绑 section 渲染:
{
"token": "a5f1d38bf17f4578959ad0d8e4ff7cac",
"note": "购物车备注",
"attributes": {},
"currency": "USD",
"original_total_price": 110,
"items_subtotal_price": 101,
"total_price": 11,
"total_discount": 99,
"total_weight": 0,
"item_count": 11,
"requires_shipping": true,
"cart_level_discount_applications": [
{
"amount": 90,
"discount_application": {
"type": 1,
"title": "所有商品满100减90",
"description": null,
"value": 90,
"created_at": null,
"value_type": "fix_amount",
"target_type": "line_item"
}
}
],
"items": [
{
"id": "18053690554475963802050412",
"properties": null,
"quantity": 10,
"title": "自定义商品100个 ",
"price": 10,
"discounts": [],
"sku": "18053690554475963802050412",
"grams": "0.0",
"taxable": true,
"url": "https://{handle}/products/自定义商品100个",
"image": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"handle": "自定义商品100个",
"group_id": "0",
"variant_id": "18053690554475963802050412",
"original_price": 0,
"discounted_price": 10,
"line_price": 100,
"original_line_price": 0,
"total_discount": 0,
"product_id": "16053690554473111675530412",
"gift_card": false,
"final_price": 10,
"final_line_price": 100,
"featured_image": {
"alt": null,
"height": null,
"url": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"width": null,
"aspect_ratio": null
},
"requires_shipping": true,
"product_title": "自定义商品100个",
"variant_title": "",
"variant_options": [],
"options_with_values": [],
"line_level_discount_allocations": [],
"line_level_total_discount": 0
}
],
"sections": {
"cart-notification-product": "<div id=\"shopline-section-cart-notification-product\" class=\"shopline-section\"><link rel=\"dns-prefetch\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" crossorigin>\n<link rel=\"dns-prefetch\" href=\"https://fonts.gstatic.com\">\n<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap\" media=\"all\"> <div id=\"cart-notification-product-18062607064090484554672730:6dbf69a53a854f65ab2e23e783a7dcff\" class=\"cart-item\">\n <div class=\"cart-notification-product__image global-media-border-shadow\">\n <img\n src=\"https://d2n979dmt31clo.cloudfront.net/image/store/1655365532096/-_200x.jpeg?w=275&h=183\"\n alt=\"\"\n width=\"100\"\n height=\"67\"\n loading=\"lazy\"\n />\n </div>\n <div class=\"cart-notification-product__details\">\n <div class=\"cart-notification-product__name body2\">三文鱼鱼籽</div>\n\n </div>\n </div>\n</div>",
"cart-notification-button": "<div id=\"shopline-section-cart-notification-button\" class=\"shopline-section\"><link rel=\"dns-prefetch\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" crossorigin>\n<link rel=\"dns-prefetch\" href=\"https://fonts.gstatic.com\">\n<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap\" media=\"all\"><div class=\"cart-notification-button\">View cart (6)</div></div>",
"cart-icon-bubble": "<div id=\"shopline-section-cart-icon-bubble\" class=\"shopline-section\"><link rel=\"dns-prefetch\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" crossorigin>\n<link rel=\"dns-prefetch\" href=\"https://fonts.gstatic.com\">\n<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap\" media=\"all\"><div id=\"cart-icon-bubble-wrapper\">\n <svg class=\"icon icon-cart\" width=\"18\" height=\"20\" viewBox=\"0 0 18 20\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M1.10959 19L1 6H17L16.8904 19H1.10959Z\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path d=\"M5 6V5C5 2.79086 6.79086 1 9 1V1C11.2091 1 13 2.79086 13 5V6\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n\n <span class=\"header__cart-point body6\">6</span>\n</div>\n</div>",
"cart-notification-subtotal": "<div id=\"shopline-section-cart-notification-subtotal\" class=\"shopline-section\"><link rel=\"dns-prefetch\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" crossorigin>\n<link rel=\"dns-prefetch\" href=\"https://fonts.gstatic.com\">\n<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap\" media=\"all\"><div class=\"cart-notification-subtotal\">\n <em class=\"body2\">Cart subtotal</em>\n <span class=\"body1 fw-bold\">HK$0.00</span>\n</div></div>"
}
}
这篇文章对你有帮助吗?