代码之家  ›  专栏  ›  技术社区  ›  Debashis Dash

在Bigcommerce中获取当前购物车Id

  •  1
  • Debashis Dash  · 技术社区  · 6 年前

    所以,我使用 cart API Bigcommerce的一个应用程序,用于将项目从另一个域添加到购物车,效果良好。然而,当我尝试重复向同一购物车添加其他物品时,它不起作用。那么,有没有办法获取实例的购物车ID,以便将我的物品更新到现有购物车?

    2 回复  |  直到 6 年前
        1
  •  3
  •   JJS    6 年前

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

    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"
       }
    ]
    
        2
  •  0
  •   Raj    6 年前

    创建第一个项目时,响应将包括购物车ID。使用此购物车ID可将更多项目添加到同一购物车。