在Bigcommerce中获取当前购物车Id
因此,我正在使用Bigcommerce的在Bigcommerce中获取当前购物车Id,bigcommerce,Bigcommerce,因此,我正在使用Bigcommerce的购物车API从另一个域向购物车添加项目,这很好。但是,当我尝试重复将其他项目添加到同一购物车时,它不起作用。那么,是否有一种方法可以获取实例的购物车ID,以便将我的项目更新到现有购物车?当您创建第一个项目时,响应将包括购物车ID。使用此购物车ID可以将更多项目添加到同一购物车。允许您检索当前购物车 将项目添加到购物车后,在javascript控制台中执行此操作 fetch('/api/storefront/carts?include=', { 'cre
购物车API
从另一个域向购物车添加项目,这很好。但是,当我尝试重复将其他项目添加到同一购物车时,它不起作用。那么,是否有一种方法可以获取实例的购物车ID,以便将我的项目更新到现有购物车?当您创建第一个项目时,响应将包括购物车ID。使用此购物车ID可以将更多项目添加到同一购物车。允许您检索当前购物车
将项目添加到购物车后,在javascript控制台中执行此操作
fetch('/api/storefront/carts?include=',
{
'credentials':'include',
'headers':{
'Accept':'application/json',
'Content-Type': 'application/json'
}
}).then(function(response){
response.json().then(function(data) {
console.log(JSON.stringify(data, null, 3))
})
});
返回类似这样的内容
[
{
"id": "aaaaaaaa-bbbb-ccccc-dddd-eeeeeeeeeeee",
"customerId": 0,
"email": null,
"currency": {
"name": "US Dollars",
"code": "USD",
"symbol": "$",
"decimalPlaces": 2
},
"isTaxIncluded": false,
"baseAmount": 100,
"discountAmount": 0,
"cartAmount": 100,
"coupons": [],
"discounts": [
{
"id": "79f73e11-87ba-4dd1-acaf-41c0098ea6ca",
"discountedAmount": 0
}
],
"lineItems": {
"physicalItems": [
{
"id": "79f73e11-87ba-4dd1-acaf-41c0098ea6ca",
"variantId": 77,
"productId": 112,
"sku": "1111",
"name": "Physical A",
"url": "http://vanity.mybigcommerce.com/physical-a/",
"quantity": 1,
"isTaxable": true,
"imageUrl": "http://cdn8.bigcommerce.com/r-de362a881829f428d7c6c20159e24db4a9c0a751/themes/ClassicNext/images/ProductDefault.gif",
"discounts": [],
"discountAmount": 0,
"couponAmount": 0,
"listPrice": 100,
"salePrice": 100,
"extendedListPrice": 100,
"extendedSalePrice": 100,
"isShippingRequired": true,
"type": "physical",
"giftWrapping": null
}
],
"digitalItems": [],
"giftCertificates": []
},
"createdTime": "2018-05-07T19:32:19+00:00",
"updatedTime": "2018-05-07T19:33:48+00:00"
}
]
是的,这就是我的计划,但我没有找到任何方法来获取返回的购物车ID。我无法将其保存在会话或Web存储中,因为在添加到购物车过程之前存在跨域通信。您是否使用V3购物车API或店面购物车API?我使用的是V3 API。然后将购物车ID存储在您身边是保留它的唯一方法。对于店面购物车API,您可以调用
/API/storefront/carts
,以获取当前购物车ID@emaillenin这个答案将受益于1。说明如何创建第一项以及响应的工作代码,以及2。指向文档的URL。