$(document).ready(function(){ $("#container").css({ width: "890px", margin: "0 auto", border: "1px solid #ccc", padding: "15px" }); $("#productlisting").css({ float: "left", width: "655px", border: "1px solid #ccc" }); $(".productblock").css({ width: "145px", margin: "5px", float: "left" }); }); var mydomain = "http://"+window.location.hostname+window.location.pathname; mydomain = mydomain.split("checkout/").join(""); var myArray = mydomain.split('category/'); mydomain = myArray[0]; //mydomain = mydomain+"/"; function downloadProduct(productid, userid){ //update session item list $.get(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", action: "download", id: productid, userid: userid }, function(data) { $("#downloadBtn").remove(); // hide button $("#downloadLink").html(data); // show download link } ); } function removeProduct(productid,shippingCost) { //if qty = 1, fade out item if(parseFloat($("#ddcproduct"+productid).attr("qty"))==1) { //fade out & remove item entirely $("#ddcproductCheckoutt"+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); $("#CheckoutQty"+productid).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(mydomain+"/wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", action: "removeproduct", id: productid } ); //update price varcarttotal = $("#CheckoutSubTotal").text(); //alert(varcarttotal); newtotal = parseFloat(varcarttotal)-parseFloat($("#ddcproduct"+productid).attr("price")); //alert(newtotal); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); //protect against going below zero. if(newtotal < 0) newtotal = 0; $("#carttotal").text(newtotal); $("#CheckoutSubTotal").text(newtotal); withShipping = parseFloat(newtotal) + parseFloat(shippingCost); $("#CheckoutTotal").text(withShipping.toFixed(2)); $.get(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", newprice: newtotal } ); } function checkoutUpdateQty(productid, price, qty) { $.get(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", 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(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", action: 'gettotal' }, function(data) { $('#summary_carttotal').text(""+data); } ); } ); } function addProduct(siteurl, ui, clicked, clickparts, ajaxURL) { // this is for wordpress featured page buy links on a 2 tier dynamic url /88/88/ if(ajaxURL ==1){ mydomain ="../../"; } prodparts = clickparts.split("|"); productid = prodparts[0]; productname = prodparts[1]; productprice = prodparts[2]; productsize = prodparts[3]; productcolor = prodparts[4]; productqty = prodparts[5]; if(productsize ==""){ productsize='na'; } if(productqty ==""){ productqty = 1; } //calculate & update new cart total varcarttotal = $("#carttotal").text(); // custom size if(productsize == "na"){ // custom footer value for custom sizes FindSize = $("#CustomSize").text(); if(FindSize != ""){ productsize = FindSize; } } // custom qty FindQty = $("#CustomQty").text(); if(FindQty != ""){ productqty = FindQty; }else{ productqty =1; } // custom shipping FindShip = $("#CustomShipping").text(); if(FindShip != ""){ productshipping = FindShip; }else{ productshipping =0; } // custom color if(productcolor == "na"){ // custom footer value for custom sizes FindColor = $("#CustomColor").text(); if(FindColor != ""){ productcolor = FindColor; } } //remove any commas varcarttotal = varcarttotal.replace(',', ''); newtotal = parseFloat(varcarttotal)+ ( parseFloat(productprice) * parseFloat(productqty) ); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); $("#carttotal").text(newtotal); $.get(siteurl+"functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", newprice: newtotal } ); //calculate and update product qty varcartqty = $("#cartqty").text(); if(varcartqty ==""){ varcartqty=0; } newqty = parseFloat(varcartqty)+parseFloat(productqty); $("#cartqty").text(newqty); $.get(siteurl+"functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", 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); } $.get(siteurl+"functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", action: "addproduct", id: productid, size: productsize, color: productcolor, qty: productqty, ship:productshipping } ); } function increaseQty(productid,shippingCost, max) { current = $("#CheckoutQty"+productid).text(); if(current >= max){ alert("You have reached the maximum quantity for this product."); return; } //just decrease qty productname = $("#ddcproduct"+productid).attr("productname"); newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))+1; $("#ddcproduct"+productid).attr("qty", newprodqty); $("#CheckoutQty"+productid).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(mydomain+"/wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", action: "increaseQty", id: productid } ); //update price varcarttotal = $("#CheckoutSubTotal").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); $("#CheckoutSubTotal").text(newtotal); withShipping = parseFloat(newtotal) + parseFloat(shippingCost); $("#CheckoutTotal").text(withShipping.toFixed(2)); $.get(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "b45938c32bcf6769462e677eaf19765b", newprice: newtotal } ); }