less than a minute read • Updated 3 hours ago
Use the cart JSON output
How to use the Foxy cart JSON output to interact with the cart programmatically from your own code.
Foxy’s cart can return its contents as a JSON object instead of HTML. This allows you to read and interact with cart data programmatically — useful for building custom cart displays, updating quantities, or triggering actions based on cart state.
Requesting the cart as JSON
Add output=json to any cart request:
https://YOURSTORE.foxycart.com/cart?output=json
To return JSONP instead (for use with jQuery or other JavaScript libraries), add the callback parameter:
https://YOURSTORE.foxycart.com/cart?output=json&callback=myFunction
Accessing the cart JSON in JavaScript
Foxy’s JavaScript exposes the current cart state as FC.json. You can access it directly once the cart is loaded:
FC.client.on('ready.done', function() {
console.log(FC.json.item_count);
console.log(FC.json.total_price);
});
Making JSON requests with FC.client.request()
Use FC.client.request() to make cart requests and get back an updated JSON object:
FC.client.request('https://' + FC.settings.storedomain + '/cart?name=My+Product&price=20').done(function(dataJSON) {
// dataJSON contains the updated cart JSON
});
This method automatically includes the session ID in the request — you do not need to add it manually.
Updating product quantities
To update the quantity of a specific item, include cart=update, the product id from the JSON, and the new quantity:
&cart=update&quantity=2&id=PRODUCT_ID_FROM_JSON
To update multiple quantities at once, prefix each product with a number starting at 1:
&cart=update&1:quantity=2&1:id=PRODUCT_ID&2:quantity=0&2:id=PRODUCT_ID_2
Notes
The session ID (
fcsid) must be included in JSON requests.FC.client.request()handles this automatically. If making your own requests, get the session ID fromFC.session.get().Modifying products in the cart beyond quantity is not currently supported.
For server-side cart interactions, see Interact with the cart server-side.