Web Development by Alistair Robinson

« Blog home

Posts Tagged ‘json’…

FoxyCart: Replacing A Cart Item


December 14th, 2009 1 Comment

function add_pre_process() {
  //Find the id of the existing registration in the cart, if it does exist
  $.each(fc_json.products, function(key, product) {
    if(product.name=="Registration") {
      // Do the remove request, with parameter quantity=0
      $.ajax({
        async: false,
        type: "GET",
        url: "https://mydomain.foxycart.com/cart?output=json&cart=update&id="+product.id+"&quantity=0&callback=?" + fc_AddSession(),
        dataType: ‘json’
      });
    }
  });

  // Add the new one
  add_item();
}

function add_item() {
  //Get the form data
  var submitted_data = $("#signup").serialize();

  //Do the add request
  $.ajax({
    type: "GET",
    url: "https://mydomain.foxycart.com/cart?"+submitted_data+"&callback=?" + fc_AddSession(),
    dataType: ‘json’
  });
}
This javascript/jQuery code gets the contents of your cart (which is in the variable fc_json, made available by foxycart_includes.js), removes any item whose … read on »


©2010 Alistair Robinson