$(document).ready(function(){ $(".productblock").draggable({ opacity: 0.5, helper: 'clone' }); /* $("#productdetail").draggable({ opacity: 0.5, helper: function() { clone = $(this).clone().css('border', 'none'); clone = clone.text('Arrastralo al carrito'); clone = clone.css('width', '200px'); clone = clone.css('border', '1px solid #ccc'); clone = clone.css('font-size', '22px'); clone = clone.css('font-weight', 'bold'); clone = clone.css('padding', '0'); clone = clone.css('float', 'none'); return clone; }, cursorAt: {top:5, left:5} });*/ $("#container").css({ width: "930px", margin: "0 auto", border: "1px solid #ccc", padding: "14px" }); $("#productlisting").css({ float: "left", width: "655px", border: "1px solid #ccc" }); $(".productblock").css({ width: "145px", margin: "5px", float: "left" }); $(".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, ''); } }); }); function removeProduct(productid) { //if qty = 1, fade out item if(parseFloat($("#ddcproduct"+productid).attr("qty"))==1) { //disable link $("#ddcproduct"+productid+" > #cell0 > a").attr('onclick', ''); //fade out & remove item entirely $("#ddcproduct"+productid).fadeOut(500, function() { $("#ddcproduct"+productid).remove(); }); } else { //just decrease qty productname = $("#ddcproduct"+productid).attr("productname"); newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))-1; $("#ddcproduct"+productid).attr("qty", newprodqty); $("#ddcproduct"+productid+" > #cell2").html(newprodqty); } //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 $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", action: "removeproduct", id: productid } ); //update session qty $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", 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: "b58adbfbe3961a52952e370414155543", newprice: newtotal } ); } function checkoutUpdateQty(productid, price, qty) { option_size = $('select#size_option_'+productid).val(); $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", 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: "b58adbfbe3961a52952e370414155543", 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: "b58adbfbe3961a52952e370414155543", 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: "b58adbfbe3961a52952e370414155543", action: 'gettotal' }, function(data) { $('#summary_carttotal').text("$"+data); } ); } ); } function addProduct(ev, ui, clicked, clickparts) { //if dragged, explode title, gather parts. if(clicked == 0) { prodparts = $(ui.draggable.element).attr("product").split("|"); } else { prodparts = clickparts.split("|"); } // added by juan for config varConfig = $("#productConfig").val(); //alert(varConfig); // for debuggin purposes productid = prodparts[0]; productname = prodparts[1] + ' ' + varConfig; productprice = prodparts[2]; 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: "b58adbfbe3961a52952e370414155543", newprice: newtotal } ); //calculate and update product qty varcartqty = $("#cartqty").text(); newqty = parseFloat(varcartqty)+1; $("#cartqty").text(newqty); $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", action: "increaseqty" } ); if($("#ddcproduct"+productid).text()!="") { //already in list, just increase qty newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))+1; $("#ddcproduct"+productid).attr("qty", newprodqty); $("#ddcproduct"+productid+" > #cell2").html(newprodqty); } else { //add to list! $("#listitems").prepend("
"+productname+"
"+productqty+"
$"+productprice+"
"); } $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", action: "addproduct", id: productid , config: varConfig} ); $("#addhowto").css("display", "none"); $("#parentlist").css("display", "none"); $("#parentlist").fadeIn("fast"); $("#shoppingcarticon").fadeTo("fast", 1); } 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: "b58adbfbe3961a52952e370414155543", newprice: newtotal } ); //calculate and update product qty varcartqty = $("#cartqty").text(); newqty = parseFloat(varcartqty)+1; $("#cartqty").text(newqty); $.get("includes/ajax/updatecart.php", { sid: "b58adbfbe3961a52952e370414155543", 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: "b58adbfbe3961a52952e370414155543", action: "addproduct", id: productid } ); } function productConfig(productType) { }