调整购物车商品数量

购物车 ajax API ,用于客户在会话期间产生的购物车交互,当需要更新购物车中商品的数量时候可调用该接口。

请求信息

API路径:

POST https://{handle}.myshopline.com/cart/change

请求header:

参数名参数类型是否必填是否数组默认值描述
Content-TypeStringYNapplication/json
AcceptStringNN*/*响应内容类型和状态码根据该字段传值不同而有所区别,有效枚举值包含:
  • \*/\*
    • 响应 content-typetext/html; charset=utf-8
    • 状态码:302,默认重定向至购物车页面。
  • application/json
    • 响应 content-typeapplication/json; charset=utf-8
    • 状态码:200
  • 请求body:

    **参数名参数类型是否必填是否数组示例描述
    idStringNN36110175633573商品唯一标识 即sku_id
    lineIntegerNN1商品行的位置下标,从1开始
    quantityLongYN2添加的商品数目,添加后购物车中该商品数目=原数目+此次添加数目
    groupIdStringNN0
  • 商品组ID,添加购物车不存在的商品时候不需要填写
  • 当添加购物车有同个商品因为不同属性组而拆行时,此时需要传入groupId来对应
  • sectionsStringNNcart-notification-product,cart-notification-button需要捆绑 section 渲染的 section,多个 section 使用 , 符号分割
    sections_urlStringNN/products/dress指定捆绑 section 渲染的页面

    响应信息

    响应body:

    一级参数名二级参数名三级参数名四级参数名五级参数名参数类型是否数组示例描述
    tokenStringN36110175633573购物车token
    noteStringN购物车备注购物车备注
    attributesMap<String,String>N购物车属性
    original_total_priceDoubleN购物车商品原价总计
    items_subtotal_priceDoubleN购物车商品小计(已扣减商品行优惠)
    total_priceDoubleN购物车最后计价(已扣减商品行折扣和购物车折扣)
    total_discountDoubleN购物车总计优惠金额(商品行优惠+购物车级别优惠)
    total_weightDoubleN商品总计重量
    item_countIntegerN购物车商品总数量
    requires_shippingBooleanN是否需要发货(只要购物车商品有一个需要发货)
    currencyStringN结算币种
    cart_level_discount_applicationsObjectY购物车级别优惠信息
    amountDoubleN优惠金额
    discount_applicationObjectN
    typeIntegerN
  • 1:价格优惠
  • 2:折扣
  • 3:免运费
  • 7:赠品
  • 8:固定价优惠
  • 9:最低商品免费
  • 11:第M件优惠
  • 12:买x送y
  • 101:表抵扣金额
  • 102:表抵扣百分比
  • 103:会员折扣
  • 104:优惠码
  • 105:指定购物金
  • 106:点数
  • titleStringN优惠名称
    descriptionStringN优惠描述
    valueDoubleN优惠金额
    created_atStringN活动创建时间
    value_typeStringN折扣活动类型:
  • percentage 折扣
  • fix_amount 固定金额
  • target_typeStringN优惠作用对象
  • line_item 商品
  • shipping_line 运费
  • itemsObjectY购物车商品列表
    idStringN36110175633573商品唯一标识 即sku_id
    group_idStringN0商品组ID
    quantityIntegerN2商品数量
    propertiesLongNimage.png
  • name: 自定义属性名
  • value: 自定义属性值
  • type: 类型,属性枚举有text,picture,link三种类型,text:字符,展示类型为 name: value; picture: 图片,展示类型为name: 通过urls获取渲染出缩略图,缩略图点击弹窗展示,并支持下载;link: 超链,展示类型为name: value,支持点击跳转 到urls第一个
  • show: 是否展示在前台
  • extInfo: 扩展字段
  • variant_idStringN36110175633573商品 sku_id
    titleStringNtest1商品title+sku title 名称+规格
    priceDoubleN200商品 售价
    original_priceDoubleN200商品 原价 (可能为0)
    discounted_priceDoubleN200减去优惠后的价格
    line_priceDoubleN200商品行售价
    original_line_priceDoubleN200商品行原价(可能为0)
    total_discountDoubleN200单个商品的总折扣金额
    discountsObjectY商品行优惠
    amountDoubleN200优惠金额
    titleStringN满100减50优惠名称
    skuStringN红色XL商品 sku_id
    gramsStringN100商品重量 单位g
    taxableBooleanNtrue是否收税
    product_idStringN36110175633573商品 spu_id
    gift_cardBooleanNtrue是否为礼品卡商品
    final_priceDoubleN500商品参与计价的金额
    final_line_priceDoubleN500商品行参与计价的金额
    urlStringNhttps://ddfasdfasdf商品主站链接
    featured_imageStringN
    aspectRatioDoubleN纵横比
    altStringN鼠标悬停提示信息
    heightIntegerN显示高度
    urlStringN图片
    widthIntegerN显示宽度
    imageStringN商品image
    handleStringN商品handle
    requires_shippingStringN是否需要发货
    product_titleStringN商品title
    variant_titleStringN所有规格的拼接
    variant_optionsStringN所有规格枚举
    options_with_valuesStringN规格
    nameStringN规格名称
    valueStringN规格值
    line_level_discount_allocationsStringN商品行优惠信息
    amountDoubleN优惠金额
    discountApplicationStringN
    typeIntegerN
  • 1:价格优惠
  • 2:折扣
  • 3:免运费
  • 7:赠品
  • 8:固定价优惠
  • 9:最低商品免费
  • 11:第M件优惠
  • 12:买x送y
  • 101:表抵扣金额
  • 102:表抵扣百分比
  • 103:会员折扣
  • 104:优惠码
  • 105:指定购物金
  • 106:点数
  • titleStringN优惠名称
    descriptionStringN优惠描述
    valueDoubleN优惠金额
    created_atStringN活动创建时间
    value_typeStringN折扣活动类型
  • percentage 折扣
  • fix_amount 固定金额
  • target_typeStringN优惠作用对象
  • line_item 商品
  • shipping_line 运费
  • line_level_total_discountDoubleN商品行优惠总金额
    sectionsObjectN{ "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>"
    }
    }
    这篇文章对你有帮助吗?