$(document).ready(function(){ $(".productblock").draggable({ opacity: 0.5, helper: 'clone' }); $("#container").css({ width: "890px", margin: "0 auto", border: "1px solid #ccc", padding: "15px" }); $("#productlisting").css({ float: "left", width: "655px", border: "1px solid #ccc" }); $(".drop").droppable({ accept: ".draggablediv", activeClass: 'droppable-active', tolerance: 'touch', over: function() { $("#shoppingcarticon").fadeTo("fast", 0.6); }, out: function() { $("#shoppingcarticon").fadeTo("fast", 1); }, drop: function(ev, ui) { addProduct(ev, ui, 0, ''); updateListOrder($('.reglistrow')); } }); $("#listitems").sortable({ //update: function(ev, ui) { updateListOrder(ui); } update: function() { updateListOrder($('.reglistrow'))} }); $('#checkoutrow').click( function () { updateListOrder($('.reglistrow'))}); $(".droptrash").droppable({ accept: "#listitems > li", drop: function(ev, ui) { removeLetter(ui.draggable); } }); }); function removeLetter(ui) { var kid = ui.children(".reglistrow:first"); prodparts = kid.attr("id").split("t"); productid = prodparts[1]; removeProduct(productid); } function removeProduct(productid) { //fade out & remove item entirely $("#ddcproduct"+productid).parent().fadeOut(500, function() { $("#ddcproduct"+productid).parent().remove(); }); //calculate and update product qty varcartqty = $("#cartqty").text(); newqty = parseFloat(varcartqty)-1; //protect against going below zero. if(newqty < 0) newqty = 0; $("#cartqty").text(newqty); //update session item list //alert("BANG "+productid); $.get("includes/ajax/updatecart.php", { sid: "", action: "removeproduct", id: productid } ); //alert("BANG BANG"); //update session qty $.get("includes/ajax/updatecart.php", { sid: "", action: "decreaseqty" } ); //update price varcarttotal = $("#carttotal").text(); newtotal = parseFloat(varcarttotal)-parseFloat($("#ddcproduct"+productid).attr("price")); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); //protect against going below zero. if(newtotal < 0) newtotal = 0; $("#carttotal").text(newtotal); $.get("includes/ajax/updatecart.php", { sid: "", newprice: newtotal } ); } function checkoutUpdateQty(productid, price, qty) { option_size = $('select#size_option_'+productid).val(); $.get("includes/ajax/updatecart.php", { sid: "", action: 'changeqty', id: productid, price: price, option_size: option_size, qty: qty }, function(data) { //update price new_qty = option_size*qty; newprice = price*qty; new_tot = Number(new_qty) + Number(newprice); newprice = new_tot.toFixed(2); //send to dom $('#totalprice_'+productid).text("$"+newprice); //update summary total $.get("includes/ajax/updatecart.php", { sid: "", action: 'gettotal' }, function(data) { $('#summary_carttotal').text("$"+data); } ); } ); } function checkoutUpdateOptionsize(productid, price, option_size) { qty = $('input#qty_'+productid).val(); $.get("includes/ajax/updatecart.php", { sid: "", action: 'changeoption_size', id: productid, price: price, option_size: option_size, qty: qty}, function(data) { //$('select#size_option_'+productid).val(option_size); //update price new_qty = option_size*qty; newprice = price*qty; new_tot = Number(new_qty) + Number(newprice); newprice = new_tot.toFixed(2); //send to dom $('#totalprice_'+productid).text("$"+newprice); //update summary total $.get("includes/ajax/updatecart.php", { sid: "", action: 'gettotal' }, function(data) { $('#summary_carttotal').text("$"+data); } ); } ); } function addProduct(ev, ui, clicked, clickparts) { //no more than 9 letters available varcartqty = $("#cartqty").text(); if (varcartqty < 9) { //if dragged, explode title, gather parts. if(clicked == 0) { //prodparts = $(ui.draggable.element).attr("product").split("|"); prodparts = $(ui.draggable).attr("product").split("|"); } else { prodparts = clickparts.split("|"); } productid = prodparts[0]; productname = prodparts[1]; productprice = prodparts[2]; productfilename = prodparts[3]; productqty = 1; //calculate & update new cart total varcarttotal = $("#carttotal").text(); //remove any commas varcarttotal = varcarttotal.replace(',', ''); newtotal = parseFloat(varcarttotal)+parseFloat(productprice); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); $("#carttotal").text(newtotal); $.get("includes/ajax/updatecart.php", { sid: "", newprice: newtotal } ); //calculate and update product qty varcartqty = $("#cartqty").text(); newqty = parseFloat(varcartqty)+1; $("#cartqty").text(newqty); $.get("includes/ajax/updatecart.php", { sid: "", action: "increaseqty" } ); //add to list! //$("#listitems").prepend("
  • "+productname+"
    "+productqty+"
    $"+productprice+"
  • "); //$("#listitems").prepend("
  • "); $("#listitems").append("
  • "); $.get("includes/ajax/updatecart.php", { sid: "", action: "addproduct", id: productid } ); $("#addhowto").css("display", "none"); $("#parentlist").css("display", "none"); $("#parentlist").fadeIn("fast"); $("#shoppingcarticon").fadeTo("fast", 1); $("#listitems").sortable("refresh"); } else { alert("You can only have 9 letters!"); } } function increaseQty(product) { prodparts = product.split("|"); productid = prodparts[0]; productprice = prodparts[1]; //calculate & update new cart total varcarttotal = $("#carttotal").text(); //remove any commas varcarttotal = varcarttotal.replace(',', ''); newtotal = parseFloat(varcarttotal)+parseFloat(productprice); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); $("#carttotal").text(newtotal); $.get("includes/ajax/updatecart.php", { sid: "", newprice: newtotal } ); //calculate and update product qty varcartqty = $("#cartqty").text(); newqty = parseFloat(varcartqty)+1; $("#cartqty").text(newqty); $.get("includes/ajax/updatecart.php", { sid: "", action: "increaseqty" } ); newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))+1; $("#ddcproduct"+productid).attr("qty", newprodqty); $("#ddcproduct"+productid+" > #cell2").html(newprodqty); $.get("includes/ajax/updatecart.php", { sid: "", action: "addproduct", id: productid } ); } function updateListOrder(obj) { //var obj = ui.item.parent().children().children(); var i = 0; var o; var output = ''; /*for (o in obj) { output = output + '&' + key + '[]=' + obj.eq(i++).attr("productid"); }*/ obj.each(function () { var str = $(this).attr('id'); //output = output + '' + key + '[]=' + str.substr(10); output = output + ',' + str.substr(10); }); //strip off the leading ampersand output = output.substr(1); $.get("includes/ajax/storeProductOrder.php", { sid: "", list: output } ) }