$(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: "408jsopv3i401ndl3b13kctg67", 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: "408jsopv3i401ndl3b13kctg67", action: "removeproduct", id: productid } ); //update price var ShoppingCartTotal = $("#CheckoutSubTotal").text(); var RemovingProductPrice = $("#ddcproduct"+productid).attr("price"); newtotal = parseFloat(ShoppingCartTotal) - parseFloat(RemovingProductPrice); //newtotal = Math.round(newtotal*100)/100; //newtotal = parseFloat(ShoppingCartTotal) - newtotal.toFixed(2); //protect against going below zero. if(parseFloat(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: "408jsopv3i401ndl3b13kctg67", newprice: newtotal } ); } function checkoutUpdateQty(productid, price, qty) { $.get(mydomain+"wp-content/themes/shopperpress/functions/ajax/updatecart.php", { sid: "408jsopv3i401ndl3b13kctg67", 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: "408jsopv3i401ndl3b13kctg67", action: 'gettotal' }, function(data) { $('#summary_carttotal').text(""+data); } ); } ); } function addProduct(siteurl, ui, clicked, clickparts, ajaxURL, error_text, ok_text, goToLink,runOrNot) { // ASSIGN DEFAULTS productextra = 0; productprice = 0; productqty = 1; productshipping =0; // this is for wordpress featured page buy links on a 2 tier dynamic url /88/88/ if(ajaxURL ==1){ mydomain ="../../"; } //calculate & update new cart total varcarttotal = $("#carttotal").text(); prodparts = clickparts.split("|"); productid = prodparts[0]; productname = prodparts[1]; productprice = prodparts[2]; // VERSION 5.0 CUSTOM FIELDS CustomField1 = $("#CustomField_1").text(); CustomField2 = $("#CustomField_2").text(); CustomField3 = $("#CustomField_3").text(); CustomField4 = $("#CustomField_4").text(); CustomField5 = $("#CustomField_5").text(); CustomField6 = $("#CustomField_6").text(); CustomField7 = $("#CustomField_7").text(); CustomField1_Required = $("#CustomField_1_required").text(); CustomField2_Required = $("#CustomField_2_required").text(); CustomField3_Required = $("#CustomField_3_required").text(); CustomField4_Required = $("#CustomField_4_required").text(); CustomField5_Required = $("#CustomField_5_required").text(); CustomField6_Required = $("#CustomField_6_required").text(); CustomField7_Required = $("#CustomField_6_required").text(); if(CustomField1_Required ==1 && CustomField1 == ""){ alert(error_text); return false; } if(CustomField2_Required ==1 && CustomField2 == ""){ alert(error_text); return false; } if(CustomField3_Required ==1 && CustomField3 == ""){ alert(error_text); return false; } if(CustomField4_Required ==1 && CustomField4 == ""){ alert(error_text); return false; } if(CustomField5_Required ==1 && CustomField5 == ""){ alert(error_text); return false; } if(CustomField6_Required ==1 && CustomField6 == ""){ alert(error_text); return false; } if(CustomField7_Required ==1 && CustomField6 == ""){ alert(error_text); return false; } if( CustomField3 == ""){ CustomField3=0; } if( CustomField6 == ""){ CustomField6=0; } // custom qty FindQty = $("#CustomQty").text(); if(FindQty != ""){ productqty = FindQty; } // custom shipping FindShip = $("#CustomShipping").text(); if(FindShip != ""){ productshipping = FindShip;} // custom extra price options, // custom fields 3 and 6 can adjust the item price if(CustomField3 != ""){productextra = productextra + parseFloat(CustomField3); } if(CustomField6 != ""){productextra = productextra + parseFloat(CustomField6); } //remove any commas varcarttotal = varcarttotal.replace(',', ''); newtotal = parseFloat(varcarttotal)+ ( parseFloat(productprice) * parseFloat(productqty) )+parseFloat(productextra); newtotal = Math.round(newtotal*100)/100; newtotal = newtotal.toFixed(2); $("#carttotal").text(newtotal); $.get(siteurl+"functions/ajax/updatecart.php", { sid: "408jsopv3i401ndl3b13kctg67", 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: "408jsopv3i401ndl3b13kctg67", 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: "408jsopv3i401ndl3b13kctg67", action: "addproduct", id: productid, qty: productqty, ship:productshipping, c1:CustomField1, c2:CustomField2, c3:CustomField3, c4:CustomField4, c5:CustomField5, c6:CustomField6,c7:CustomField7 } ); //, size: productsize, color: productcolor, extra:productextra if(runOrNot == 'yes'){ CheckoutAlert(ok_text,goToLink); } } 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: "408jsopv3i401ndl3b13kctg67", 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: "408jsopv3i401ndl3b13kctg67", newprice: newtotal } ); }