The JSON Cart Object

In an effort to make FoxyCart as flexible, customizable, and “Web 2.0” as possible, we've provided a JSON cart object for you to manipulate to your heart's content.

If it exists, the function fc_PreProcess() is called before the FoxyBox (Thickbox) is opened.

If it exists, the function fc_BuildFoxyCart() is called when the FoxyBox (Thickbox) is closed.

Example Code

The following code will render an ugly, table-based cart from the JSON object.

var FoxyDomain = "YOURDOMAIN.foxycart.com/";
 
function fc_PreProcess() {
	// do something here before opening the cart... maybe some form error checking?
        // if you don't want the cart to open, say for example if there were some data validation problems you
        // want your customer to fix, then return false from this function instead of true.
	return true;
}
 
function fc_BuildFoxyCart() {
	fc_FoxyCart = "";
	fc_FoxyCart += "<div><table border=1 id=\"fc_table\">";
	fc_FoxyCart += "<tr>";
	fc_FoxyCart += "<th>Name</th>";
//	fc_FoxyCart += "<th>Options</th>";
	fc_FoxyCart += "<th>Code</th>";
	fc_FoxyCart += "<th>Quantity</th>";
	fc_FoxyCart += "<th>Price Each</th>";
	fc_FoxyCart += "<th>Price</th>";
	fc_FoxyCart += "</tr>";
	for (i=0;i<fc_json.cart.length;i++) {
		// BEGIN DO NOT EDIT
		fc_BuildFoxyCartRow(fc_json.cart[i].product.name,fc_json.cart[i].product.code,fc_json.cart[i].product.options,fc_json.cart[i].product.quantity,fc_json.cart[i].product.price_each,fc_json.cart[i].product.price);
		// END DO NOT EDIT
	}
	fc_FoxyCart += "</table></div>";
 
	// fc_FoxyCart is a javascript variable that now holds your shopping cart data
 
	// if you have some products in your cart, why not display it?
	if (fc_json.cart.length > 0) {
		$("#fc_cart").html(fc_FoxyCart);
	} else {
		$("#fc_cart").html("");
	}
}
 
// This function is called by fc_BuildFoxyCart() for each product in your cart.
// Feel free to edit this function as needed to display each row of your cart.
function fc_BuildFoxyCartRow(fc_name,fc_code,fc_options,fc_quantity,fc_price_each,fc_price) {
	fc_FoxyCart += "<tr>";
	fc_FoxyCart += "<td>" + fc_name + "</td>";
//	fc_FoxyCart += "<td>" + fc_options + "</td>";
	fc_FoxyCart += "<td>" + fc_code + "</td>";
	fc_FoxyCart += "<td>" + fc_quantity + "</td>";
	fc_FoxyCart += "<td>" + fc_price_each + "</td>";
	fc_FoxyCart += "<td>" + fc_price + "</td>";
	fc_FoxyCart += "</tr>";
}