购物车添加商品
购物车 API 用于客户在会话期间产生的购物车交互,当需要向购物车中的添加新的商品时可通过请求这个接口完成对应操作。
请求信息
API路径:
POST
https://{handle}.myshopline.com/cart/add
请求header:
参数名 | 参数类型 | 是否必填 | 是否数组 | 默认值 | 描述 |
---|---|---|---|---|---|
Content-Type | String | Y | N | application/json | |
Accept | String | N | N | */* | 响应内容类型和状态码根据该字段传值不同而有所区别,有效枚举值包含: \*/\* :
application/json :
|
请求body:
一级参数名 | 二级参数名 | 参数类型 | 是否必填 | 是否数组 | 示例 | 描述 |
---|---|---|---|---|---|---|
items | Object | Y | Y | 购物车商品列表 | ||
id | String | Y | N | 36110175633573 | 商品唯一标识 即sku_id | |
quantity | Long | Y | N | 2 | 添加的商品数目,添加后购物车中该商品数目=原数目+此次添加数目 | |
groupId | String | N | N | 0 | 商品组ID,添加购物车不存在的商品时候不需要填写*当添加购物车有同个商品因为不同属性组而拆行时,此时需要传入groupId来对应 | |
properties | Object | N | Y | ![]() | ||
sections | String | N | N | cart-notification-product,cart-notification-button | 需要捆绑 section 渲染的 section,多个 section 使用 , 符号分割 | |
sections_url | String | N | N | /products/dress | 指定捆绑 section 渲染的页面 |
响应信息
响应body:
参数名 | 参数类型 | 是否数组 | 示例 | 描述 | |||
---|---|---|---|---|---|---|---|
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:正常更新购物车
{
"items": [
{
"id": "18053690554475963802050412",
"properties": null,
"quantity": 10,
"title": "自定义商品100个 ",
"price": 10,
"discounts": [],
"sku": "18053690554475963802050412",
"grams": "0.0",
"taxable": true,
"url": "https://test001.myshopline.com/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://test001.myshopline.com/products/仅仅是限时促销商品",
"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://test001.myshopline.com/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/add
status:404
{
"message": "error code",
"description": "error description"
}
场景3:捆绑 section 渲染:
POST
https://{handle}.myshopline.com/cart/add
{
"items": [
{
"id": "18053690554475963802050412",
"properties": null,
"quantity": 10,
"title": "自定义商品100个 ",
"price": 10,
"discounts": [],
"sku": "18053690554475963802050412",
"grams": "0.0",
"taxable": true,
"url": "https://test001.myshopline.com/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": {},
"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>"
}
}
这篇文章对你有帮助吗?