Reputation: 342
So, I am using the cart API
of Bigcommerce for adding items to the cart from a different domain which is working fine. However, when I try to repeat adding other items to the same cart it does not work. So, is there a way I can get the cart ID for an instance so that I can update my items to the existing cart?
Upvotes: 1
Views: 2544
Reputation: 6658
The Storefront API allows you to retrieve the current cart.
Execute this in the javascript console after adding an item to cart
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 something like this
[
{
"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"
}
]
Upvotes: 3
Reputation: 22926
When you created your first item, the response will include Cart ID. Use this Cart ID to add more items to the same cart.
Upvotes: 0