var discount ; discount = new Array() ; discount[0] = 100 ; discount[1] = 80 ; discount[2] = 70 ; discount[3] = 60 ; discount[4] = 50 ; $(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('In den Warenkorb legen'); 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({ }); $("#productlisting").css({ }); $(".productblock").css({ }); $(".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: "", action: "removeproduct", id: productid } ); //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) { $.get("includes/ajax/updatecart.php", { sid: "", action: 'changeqty', id: productid, price: price, qty: qty }, function(data) { //update price newprice = price*qty; newprice = newprice.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) { //if dragged, explode title, gather parts. if(clicked == 0) { prodparts = $(ui.draggable.element).attr("product").split("|"); } else { prodparts = clickparts.split("|"); } productid = prodparts[0]; productname = prodparts[1]; productprice = prodparts[2]; productcat = prodparts[3]; productqty = 1; if($("#ddcproduct"+productid).text()=="") { //calculate & update new cart total varcarttotal = $("#carttotal").text(); //remove any commas varcarttotal = varcarttotal.replace(',', '.'); varcarttotal = varcarttotal.replace('€', ''); varcarttotal = varcarttotal.replace('', ''); newtotal = parseFloat(varcarttotal)+parseFloat(productprice); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); newtotal = newtotal + ' €' ; $("#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("