/* for checking delivery */ function runDeliveryCall(cart_only = false){ let address_fields = jQuery("[id^='io_cd_']"); let address_data = { "address": getCookie("address"), "state": getCookie("state"), "city": getCookie("city"), "zip": getCookie("zip") }; let times = getAvailTimes(); let start_date = times[0]; let end_date = start_date; let start_time = times[1]; let duration = times[2]; let rental_ids = ""; simpleCart.each(function (item, x) { if(typeof item.get('timeslots') != "undefined"){ if(item.get('timeslots').length > 0){ var timeslots_html = item.get('timeslots'); var rental_id = item.get('rentalid'); if(typeof timeslots_html == "undefined") return; if(timeslots_html.length == 0) return; var timeslot_name = getTimeslotName(timeslots_html); var timeslot_sel_range = jQuery(".item-timeslots [name=\""+timeslot_name+"\"] option:selected").val(); if(typeof timeslot_sel_range != "undefined"){ /* timeslots */ setTimeslotSelected(item, timeslot_name); }else{ /* timepickers */ setTimePicker(item, timeslot_name);//todo? let start_timepicker = document.getElementsByName(timeslot_name.replace("io_timepicker_", "start_timeslot_")); let end_timepicker = document.getElementsByName(timeslot_name.replace("io_timepicker_", "end_timeslot_")); timeslot_sel_range = start_timepicker[start_timepicker.length-1].value; timeslot_sel_range += " - " + end_timepicker[end_timepicker.length-1].value; } var timeslot_sel_arr = ""; if(typeof timeslot_sel_range != "undefined"){ timeslot_sel_arr = timeslot_sel_range.split(" - "); var timeslot_start_time = timeslot_sel_arr[0].replace("am"," am").replace("pm"," pm").replace(" "," "); var timeslot_end_time = timeslot_sel_arr[1].replace("am"," am").replace("pm"," pm").replace(" "," "); if(timeslot_start_time && timeslot_end_time){ let newDate1 = convertDateStringtoDateObject(start_date, timeslot_start_time); let newDate2 = convertDateStringtoDateObject(end_date, timeslot_end_time); let timeslot_duration = ((newDate2 - newDate1) / 3600) / 1000; rental_ids += rental_id+"-"+item.get("quantity")+"-"+timeslot_start_time+"-"+timeslot_duration+"|"; } } } } else{ var cart_id = item.get("rentalid"); rental_ids += cart_id + "-" + item.get("quantity") + "|"; } }); address_fields.each(function() { let field = this.id.split("_")[2]; value = this.value; if(!value && !address_data[field]){ jQuery(this).addClass("invalid_address_field") } else if(value){ jQuery(this).removeClass("invalid_address_field") address_data[field] = this.value; } }); if(jQuery(".invalid_address_field").length > 0){ return; } getCookie("io_delivery_method") setCookie("address", address_data["address"], 14); setCookie("city", address_data["city"], 14); setCookie("state", address_data["state"], 14); setCookie("zip", address_data["zip"], 14); cart_total = simpleCart.total(); if(cart_total === "TBD") cart_total = 0; url = "https://rental.software/quotes/get_delivery_info.php?callback=?"; if(window.location.href.indexOf("localhost") > -1){ //url = "http://localhost/bugs/quotes/get_delivery_info.php?callback=?"; url = "http://localhost/io/bugs/quotes/get_delivery_info.php?callback=?"; } url += "&name=" + encodeURIComponent("KidZone Party Rentals") + "&rental_ids=" + rental_ids + "&street=" + encodeURIComponent(address_data["address"]) + "&city=" + encodeURIComponent(address_data["city"]) + "&state=" + encodeURIComponent(address_data["state"]) + "&zip=" + encodeURIComponent(address_data["zip"]) + "&startdate=" + start_date + "&starttime=" + start_time + "&duration=" + duration + "&delivery_method=" + encodeURIComponent(getCookie("io_delivery_method")) + "&total=" + cart_total jQuery.getJSON(url, function(data){ if(data["delivery_restrict"] === 1){ data["charge"] = 0; } handleDeliveryInfo(data, cart_only); }); } function handleDeliveryInfo(data, cart_only = false){ jQuery("#deliverSubtotalContainer").show(); jQuery("#checkDeliveryMessage").hide(); let info_box = jQuery("#delivery_charge_info_box"); if(data["delivery_restrict"] == 1){ jQuery("#info_box_header").text("Sorry..."); jQuery("#info_box_information").text(data["error"]) setDeliverySubtotal(data["charge"], true) } else{ setDeliverySubtotal(data["charge"]) jQuery("#info_box_header").text("Success!"); if(data["charge"] > 0){ jQuery("#info_box_information").html("We are able to deliver to your location with a " + simpleCart.toCurrency(data["charge"]) +" fee!"); } else{ jQuery("#info_box_information").html("We are able to deliver to your location with no charge!"); } } if(simpleCart.items().length == 0 && cart_only){ jQuery("#info_box_header").text("Items Required."); jQuery("#info_box_information").html("There needs to be items in your cart to check for delivery fees. But we will save the address information so you don't have to enter it again!") } info_box.show(); jQuery.fancybox.update(jQuery(".address_entry")); } function showAddressEntry(cart_only=false){ cartHide(); jQuery(".invalid_address_field").removeClass("invalid_address_field") jQuery("#delivery_charge_info_box").hide(); jQuery("#io_cd_address").val(getCookie("address")); jQuery("#io_cd_state").val(getCookie("state")); jQuery("#io_cd_city").val(getCookie("city")); jQuery("#io_cd_zip").val(getCookie("zip")); if(!cart_only){ jQuery("#address_entry_submit").on("click", null, function(){ runDeliveryCall(); }); } else{ jQuery("#address_entry_submit").on("click", null, function(){ runDeliveryCall(cart_only); }); } jQuery.fancybox.open(jQuery(".address_entry")); } function closeAddressEntry(){ jQuery.fancybox.close(); } function setDeliverySubtotal(amount, unavailable=false){ if(unavailable){ jQuery("#deliverySubtotal").html("Unavailable"); } else{ jQuery("#deliverySubtotal").html(simpleCart.toCurrency(amount)); } } function addressCookiesSet(){ if(getCookie("address") && getCookie("state") && getCookie("city") && getCookie("zip")){ return true; } else{ return false } }