在 Bigcommerce 中获取当前的购物车 ID

Getting current Cart Id in Bigcommerce

因此,我正在使用 Bigcommerce 的 cart API 将来自不同域的商品添加到购物车,效果很好。但是,当我尝试重复将其他商品添加到同一个购物车时,它不起作用。那么,有没有一种方法可以获得实例的购物车 ID,以便我可以将我的商品更新到现有购物车?

当您创建第一个项目时,响应将包含购物车 ID。使用此购物车 ID 将更多商品添加到同一购物车。

Storefront API 允许您检索当前购物车。

将商品添加到购物车后,在 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))
  })
});

returns 像这样

[
   {
      "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"
   }
]