function showInstallment() { if ($("#installment_payment").hasClass("in") == false) { $("#installment_payment").addClass("in"); $("#installment_payment").attr("aria-expanded", true); } $("#installment_payment").show(); $("#installment_anchar").removeClass("collapsed"); } function showFullPayment() { if (!$("#installment_payment").hasClass("in")) { $("#installment_payment").addClass("in"); $("#installment_payment").attr("aria-expanded", true); $("#installment_payment").collapse("toggle"); } $("#installment_anchar").removeClass("collapsed"); } function hideFullPaymentAccord() { if (!$("#collapsed_fullPyament").hasClass("collapsed")) { $("#collapsed_fullPyament").addClass("collapsed"); } if ($("#fullpayment").hasClass("in")) { $("#fullpayment").removeClass("in"); $("#fullpayment").hide(); } } function hideInstallmentAccord() { if (!$("#installment_anchar").hasClass("collapsed")) { $("#installment_anchar").addClass("collapsed"); } if ($("#installment_payment").hasClass("in")) { $("#installment_payment").removeClass("in"); $("#installment_payment").hide(); } } $(window).load(function(event) { if (typeof CustomerId === 'undefined' || CustomerId === null) { var CustomerId = ''; } if (($("#shoppingcart_page").size() > 0) || $("#frmcheckout").size() > 0) { if (PaymentType == "") { hideInstallmentAccord(); } if (CustomerId == "" && PaymentType == "installment") { if ($('.shopnewaccount').prop("checked") == true) { $('.c-account').css('display', 'block'); } if ($('.shopnewaccount').prop("checked") == false) { $('#installment_payment').hide(); } else { $('#installment_payment').show(); } } else if (CustomerId == "" && (PaymentType == '' || PaymentType == 'fullpayment')) { $('.shopnewaccount').prop('checked', false); } $('[data-toggle="popover"]').popover(); $('#newLogin').click(function() { $('.Checkout-dropdown').attr('aria-expanded', true); $('.Checkout-dropdown').trigger('click'); $('#demo').show(); $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); setTimeout(function() { if (PaymentType == "installment") { nonUI = true; showInstallment(); $("#checkbox1-77").trigger("click"); if ($("#frmcheckout").length > 0) { $("#frmcheckout").data("bootstrapValidator").revalidateField("form[password]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[confirm_password]"); } } else { $("#checkbox1-77").trigger("click"); $("#checkbox1-77").trigger("click"); if ($("#frmcheckout").length > 0) { $("#frmcheckout").data("bootstrapValidator").revalidateField("form[password]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[confirm_password]"); } } if ($("#frmcheckout").length > 0) { $("#frmcheckout").data('bootstrapValidator').revalidateField('form[password]'); $("#frmcheckout").data('bootstrapValidator').revalidateField('form[confirm_password]'); } }, 20); } }); var lastUrl = lastUrlSegment(site_url); var stateAjax = true; var cityAjax = true; function calculateCheckoutTax() { var ship_country = $("#shipping_countryId").val(); var ship_state = $("#form_shipping_stateId").val(); var ship_city = $("#formShippingCity").val(); var ship_zipcode = $("#form_shipping_zipcode").val(); var bill_country = $("#billing_countryId").val(); var bill_state = $("#form_billing_stateId").val(); var bill_city = $("#formBillingCity").val(); var bill_zipcode = $("#form_billing_zipcode").val(); var noOfInstallment = $("#form_total_no_of_payments").val(); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if (selected_shipping_method_slug == "instorepickup") { ship_country = $("#instore_country_id").val(); ship_state = $("#instore_state_id").val(); ship_city = $("#instore_city_id").val(); ship_zipcode = $("#instore_zipcode").val(); } $.ajax({ type: "POST", dataType: "json", url: site_url + "/product/getCalculateCheckoutTax", cache: false, data: "ship_country=" + ship_country + "&ship_state=" + ship_state + "&ship_city=" + ship_city + "&ship_zipcode=" + ship_zipcode + "&bill_country=" + bill_country + "&bill_state=" + bill_state + "&bill_city=" + bill_city + "&bill_zipcode=" + bill_zipcode + "&noOfInstallment=" + noOfInstallment + "&shipping_method_slug=" + selected_shipping_method_slug, success: function(response) { var taxtotalcart_without_currency = 0; var subtotalcart = response.totalcart_new; var finaltotalcart = response.totalcart_with_tax_new; var taxtotalcart = response.total_tax_new; var taxtotalcart_without_currency = response.total_tax; $("#fullpayment .c-subtotal").html(subtotalcart); $("#fullpayment .c-taxtotal").html(taxtotalcart); $("#fullpayment .c-shipping-total").html(finaltotalcart); $("#amount").val(response.cart_total_with_shipping_charge_tax); if ((typeof $("#fullpayment .c-taxtotal").attr("data-totaltax") !== 'undefined') && ($("#fullpayment .c-taxtotal").attr("data-totaltax").length > 0)) { $("#fullpayment .c-taxtotal").attr("data-totaltax", parseFloat(taxtotalcart_without_currency).toFixed(2)); } $("#fullpayment .grand_total_with_tax_scharge").html(response.cart_total_with_shipping_charge_tax_new); if (checkInstallment == "Yes") { var taxtotalcart_without_currency = 0; var subtotalcart = response.installment.installment_sale_price_with_currency; var finaltotalcart = response.total_tax_with_installment_markup_new; var taxtotalcart = response.installment.installment_tax_with_currency; var taxtotalcart_without_currency = response.installment.installment_tax; $("#installment_payment .c-subtotal").html(subtotalcart); $("#installment_payment .c-taxtotal").html(taxtotalcart); $("#installment_payment .c-shipping-total").html(finaltotalcart); $("#amount").val(response.installment.first_installment_price); if ((typeof $("#installment_payment .c-taxtotal").attr("data-totaltax") !== 'undefined') && ($("#installment_payment .c-taxtotal").attr("data-totaltax").length > 0)) { $("#installment_payment .c-taxtotal").attr("data-totaltax", taxtotalcart_without_currency); } $("#installment_payment .c-grandtotal").attr("data-grandtotal", response.installment.installment_total_payable_amount); $("#installment_payment .c-grandtotal").html(response.installment.installment_total_payable_amount_with_currency); $("#installment_payment .grand_total_with_tax_scharge").html(response.installment.first_installment_price_with_currency); } }, }); } if (lastUrl == "shoppingcart") { var session_state = ""; var session_city = ""; $("body").delegate("input.show_shipping_charge", "click", function(e) { e.preventDefault(); e.stopImmediatePropagation(); $(".show_shipping_charge").removeAttr("checked"); $(this).attr("checked", "checked"); $(".show_shipping_charge").next().find("span.check").css("opacity", "0"); $(".show_shipping_charge").next().find("span.check").css("transform", "none"); $(this).next().find("span.check").css("opacity", "1"); $(this).next().find("span.check").css("transform", "none"); var selected_method_name = $(this).attr("data-radiobtnshippingslug"); $("#selected_shipping_radio_btn").val(selected_method_name); if (selected_method_name == "ups") { $("#shipping_method_ups").css("display", "block"); return true; } if (selected_method_name == "fedex") { $("#shipping_method_fedex").css("display", "block"); return true; } if (selected_method_name == "instorepickup") { $("#shipping_method_instorepickup").css("display", "block"); return true; } if (selected_method_name == "usps") { $("#shipping_method_usps").css("display", "block"); return true; } $(".thirdparty_shipping option:selected").prop("selected", false); var shipping_method_id = $(this).attr("data-shipping-method-id"); var shipping_method_name = $(this).attr("data-shipping-method"); var shipping_method_slug = $(this).attr("data-shipping-slug"); var shipping_options_id = $(this).val(); var charge_symbol = $(this).attr("data-charge-symbol"); var charge = $(this).attr("data-charge"); var carttotalprice = $(".shpsubtotal").attr("data-subtotal"); var total_tax = 0; $("#shipping_charge").html(charge_symbol); var countryId = $("#countryId").val(); var stateId = $("#stateId").val(); var cityId = $("#city").val(); var zipcode = $("#zipcode").val(); var baseUrl = getBaseUrl(); var shipping_label = $(this).attr("data-label"); bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label); }); $("body").delegate("#shipping_method_fedex", "change", function(e) { e.preventDefault(); e.stopImmediatePropagation(); $(".show_shipping_charge").prop("checked", false); $("#shipping_method_usps option").attr("selected", false); $("#shipping_method_ups option").attr("selected", false); $("#shipping_method_instorepickup option").attr("selected", false); var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge_symbol = $("option:selected", this).attr("data-charge-symbol"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var countryId = $("#countryId").val(); var stateId = $("#stateId").val(); var cityId = $("#city").val(); var zipcode = $("#zipcode").val(); var baseUrl = getBaseUrl(); bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label); }); $("body").delegate("#shipping_method_usps", "change", function(e) { e.preventDefault(); e.stopImmediatePropagation(); $(".show_shipping_charge").prop("checked", false); $("#shipping_method_fedex option").attr("selected", false); $("#shipping_method_ups option").attr("selected", false); $("#shipping_method_instorepickup option").attr("selected", false); var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge_symbol = $("option:selected", this).attr("data-charge-symbol"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var carttotalprice = $(".shpsubtotal").attr("data-subtotal"); var opt_value = $("option:selected", this).attr("value"); var countryId = $("#countryId").val(); var stateId = $("#stateId").val(); var cityId = $("#city").val(); var zipcode = $("#zipcode").val(); var baseUrl = getBaseUrl(); bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label); }); $("body").delegate("#shipping_method_ups", "change", function(e) { e.preventDefault(); e.stopImmediatePropagation(); $(".show_shipping_charge").prop("checked", false); $("#shipping_method_fedex option").attr("selected", false); $("#shipping_method_usps option").attr("selected", false); $("#shipping_method_instorepickup option").attr("selected", false); var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge_symbol = $("option:selected", this).attr("data-charge-symbol"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var carttotalprice = $(".shpsubtotal").attr("data-subtotal"); var opt_value = $("option:selected", this).attr("value"); var countryId = $("#countryId").val(); var stateId = $("#stateId").val(); var cityId = $("#city").val(); var zipcode = $("#zipcode").val(); var baseUrl = getBaseUrl(); bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label); }); $("body").delegate("#shipping_method_instorepickup", "change", function(e) { e.preventDefault(); e.stopImmediatePropagation(); if ($("option:selected", this).attr("value") == "") { var shipping_method_lable = $("option:selected", this).attr("data-radiobtnshippingslug"); $("#selected_shipping_radio_btn").val(shipping_method_lable); } $(".show_shipping_charge").prop("checked", false); $("#shipping_method_fedex option").attr("selected", false); $("#shipping_method_usps option").attr("selected", false); $("#shipping_method_ups option").attr("selected", false); var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge_symbol = $("option:selected", this).attr("data-charge-symbol"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var carttotalprice = $(".shpsubtotal").attr("data-subtotal"); var opt_value = $("option:selected", this).attr("value"); var countryId = $("#countryId").val(); var stateId = $("#stateId").val(); var cityId = $("#city").val(); if($("#shippingcalculationfrm").length > 0) { var item=$("option:selected", this).text(); if(item!="Select Store Option"){ $("#zipcode").val(''); var zipcode = item.split(",").pop(); $("#zipcode").val(zipcode);//alert(lastItem); alert(zipcode); }else{ var zipcode = $("#zipcode").val(); } }else{ var zipcode = $("#zipcode").val(); } // var zipcode = $("#zipcode").val(); var baseUrl = getBaseUrl(); bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label); }); } function bindShippingData(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, countryId, stateId, cityId, zipcode, baseUrl, shipping_label) { showLoader(); $.ajax({ type: "POST", cache: true, url: baseUrl + "/updateshippingdata", data: "countryId=" + countryId + "&stateId=" + stateId + "&cityId=" + cityId + "&zipcode=" + zipcode + "&shipping_method_id=" + shipping_method_id + "&shipping_options_id=" + shipping_options_id + "&shipping_charge=" + charge + "&shipping_label=" + shipping_label + "&shipping_method_name=" + shipping_method_name + "&shipping_method_slug=" + shipping_method_slug, success: function(result) { if (wbGoogleAnalyticId != "" && wbStandardTracking == 1 && wbEcommerceTracking == 1) { gtag("event", "set_checkout_option", { event_label: shipping_method_name, checkout_step: 1, checkout_option: "shipping method", value: shipping_method_name, }); } loadShopppingCart(); return true; }, error: function(jqXHR, textStatus, errorThrown) { return false; }, }); hideLoader(); } function bindShippingDataCheckoutPageOld(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label) { showLoader(); $.ajax({ type: "POST", cache: true, url: baseUrl + "/checkoutupdateshippingdata", data: "shipping_countryId=" + shipping_countryId + "&shipping_stateId=" + shipping_stateId + "&shipping_cityId=" + shipping_cityId + "&shipping_zipcode=" + shipping_zipcode + "&billing_countryId=" + billing_countryId + "&billing_stateId=" + billing_stateId + "&billing_cityId=" + billing_cityId + "&billing_zipcode=" + billing_zipcode + "&shipping_method_id=" + shipping_method_id + "&shipping_options_id=" + shipping_options_id + "&shipping_charge=" + charge + "&shipping_label=" + shipping_label + "&shipping_method_name=" + shipping_method_name + "&shipping_method_slug=" + shipping_method_slug, success: function(result) { if (wbGoogleAnalyticId != "" && wbStandardTracking == 1 && wbEcommerceTracking == 1) { gtag("event", "set_checkout_option", { event_label: shipping_method_name, checkout_step: 1, checkout_option: "shipping method", value: shipping_method_name, }); } $(".loader").removeClass("hide"); $(".loader").addClass("show"); setTimeout(function() { location.reload(true); }, 3000); return true; }, error: function(jqXHR, textStatus, errorThrown) { return false; }, }); } function bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label) { showLoader(); var bill_diff_address = 0; if ($("#chkbilladdress").prop("checked") == true || $('#selected_shipping_method_slug').val() == 'instorepickup') { bill_diff_address = 1; } if(bill_diff_address == 0 && ($.trim($("#shipping_firstName").val())=="" && $.trim($("#shipping_lastName").val())=="" && $.trim($("#form_shipping_address1").val())=="" && $.trim($("#shipping_emailid").val())=="" && $.trim($("#shipping_contact").val())=="")){ var form_ship_data = "&ship_first_name=" + $("#billing_firstName").val() + "&ship_middle_name=" + $("#billing_middleName").val() + "&ship_last_name=" + $("#billing_lastName").val() + "&ship_company_name=" + $("#billing_companyName").val() + "&ship_address1=" + $("#form_billing_address1").val() + "&ship_address2=" + $("#form_billing_address2").val() + "&ship_email=" + $("#billing_emailid").val() + "&ship_phone=" + $("#billing_contact").val() + "&ship_fax=" + $("#billing_fax").val() + "&shipping_countryId=" + $("#billing_countryId").val() + "&shipping_stateId=" + $("#form_billing_stateId").val() + "&shipping_cityId=" + $("#formBillingCity").val() + "&shipping_zipcode=" + $("#form_billing_zipcode").val(); }else{ if($.trim($("#shipping_firstName").val())=="" && $.trim($("#shipping_lastName").val())=="" && $.trim($("#form_shipping_address1").val())=="" && $.trim($("#shipping_emailid").val())=="" && $.trim($("#shipping_contact").val())==""){ /*As Bill to Diff address are not checked but user select option "In store Pickup" so once user make entries in the form while select "In store option" at that time we need to copied the billing Information data to the Delivery Address So once user will change from "In store Option" to any other shipping option the "Delivery Address" has already copied the data of billing address. */ var form_ship_data = "&ship_first_name=" + $("#billing_firstName").val() + "&ship_middle_name=" + $("#billing_middleName").val() + "&ship_last_name=" + $("#billing_lastName").val() + "&ship_company_name=" + $("#billing_companyName").val() + "&ship_address1=" + $("#form_billing_address1").val() + "&ship_address2=" + $("#form_billing_address2").val() + "&ship_email=" + $("#billing_emailid").val() + "&ship_phone=" + $("#billing_contact").val() + "&ship_fax=" + $("#billing_fax").val() + "&shipping_countryId=" + $("#billing_countryId").val() + "&shipping_stateId=" + $("#form_billing_stateId").val() + "&shipping_cityId=" + $("#formBillingCity").val() + "&shipping_zipcode=" + $("#form_billing_zipcode").val(); }else{ /* If user already make entries in the "Delivery Address" and then change the Shipping option then we do not change billing info to the delivery address As user already make entry to that form as user just change the Shipping option */ var form_ship_data = "&ship_first_name=" + $("#shipping_firstName").val() + "&ship_middle_name=" + $("#shipping_middleName").val() + "&ship_last_name=" + $("#shipping_lastName").val() + "&ship_company_name=" + $("#shipping_companyName").val() + "&ship_address1=" + $("#form_shipping_address1").val() + "&ship_address2=" + $("#form_shipping_address2").val() + "&ship_email=" + $("#shipping_emailid").val() + "&ship_phone=" + $("#shipping_contact").val() + "&ship_fax=" + $("#shipping_fax").val(); } } //alert($('#formShippingCity').val()); //alert($('#form_shipping_stateId').val()); if(bill_diff_address == 0 && ($.trim($("#shipping_firstName").val()) != '') && ($.trim($("#shipping_lastName").val()) != '')){ //alert('in another if'); var form_bil_data = "&bil_first_name=" + $("#shipping_firstName").val() + "&bil_middle_name=" + $("#shipping_middleName").val() + "&bil_last_name=" + $("#shipping_lastName").val() + "&bil_company_name=" + $("#shipping_companyName").val() + "&bil_address1=" + $("#form_shipping_address1").val() + "&bil_address2=" + $("#form_shipping_address2").val() + "&bil_email=" + $("#shipping_emailid").val() + "&bil_phone=" + $("#shipping_contact").val() + "&bil_fax=" + $("#shipping_fax").val(); billing_stateId = $('#form_shipping_stateId').val(); billing_cityId = $('#formShippingCity').val(); }else{ //alert('in another else'); var form_bil_data = "&bil_first_name=" + $("#billing_firstName").val() + "&bil_middle_name=" + $("#billing_middleName").val() + "&bil_last_name=" + $("#billing_lastName").val() + "&bil_company_name=" + $("#billing_companyName").val() + "&bil_address1=" + $("#form_billing_address1").val() + "&bil_address2=" + $("#form_billing_address2").val() + "&bil_email=" + $("#billing_emailid").val() + "&bil_phone=" + $("#billing_contact").val() + "&bil_fax=" + $("#billing_fax").val(); } var other_data = "&bill_diff_address=" + bill_diff_address + '&sales_person=' + $('#form_salesPerson').val(); $.ajax({ type: "POST", cache: true, url: baseUrl + "/checkoutupdateshippingdata", data: "shipping_countryId=" + shipping_countryId + "&shipping_stateId=" + shipping_stateId + "&shipping_cityId=" + shipping_cityId + "&shipping_zipcode=" + shipping_zipcode + "&billing_countryId=" + billing_countryId + "&billing_stateId=" + billing_stateId + "&billing_cityId=" + billing_cityId + "&billing_zipcode=" + billing_zipcode + "&shipping_method_id=" + shipping_method_id + "&shipping_options_id=" + shipping_options_id + "&shipping_charge=" + charge + "&shipping_label=" + shipping_label + "&shipping_method_name=" + shipping_method_name + "&shipping_method_slug=" + shipping_method_slug + form_ship_data + form_bil_data + other_data, success: function(result) { if (wbGoogleAnalyticId != "" && wbStandardTracking == 1 && wbEcommerceTracking == 1) { gtag("event", "set_checkout_option", { event_label: shipping_method_name, checkout_step: 1, checkout_option: "shipping method", value: shipping_method_name, }); } $(".loader").removeClass("hide"); $(".loader").addClass("show"); setTimeout(function() { location.reload(true); //var url = $(location).attr('href'); //var newurl = url+'/shippingchange'; //window.redirect(newurl); //window.location.href = newurl; }, 4000); //setTimeout(function() { // $('#shipmethod').addClass(' in'); //},2500); return true; }, error: function(jqXHR, textStatus, errorThrown) { return false; }, }); } if (lastUrl == "checkout") { getshippingoptins(); } function getshippingoptins() { showLoader(); $("#shipping_html,#installment_shipping_html").delegate("input.show_shipping_charge", "click", function(e) { $("#shipping_options_html").attr("checked", false); $(this).attr("checked", "checked"); $(".show_shipping_charge").next().find("span.check").css("opacity", "0"); $(".show_shipping_charge").next().find("span.check").css("transform", "none"); $(this).next().find("span.check").css("opacity", "1"); $(this).next().find("span.check").css("transform", "none"); if ($('input[type="checkbox"][name="form[shopterms]"]').is(":checked")) { $('input[type="checkbox"][name="form[shopterms]"]').attr("checked", false); $(".payment_accordian").addClass("disableDiv"); } var selected_method_name = $(this).attr("data-radiobtnshippingslug"); $("#selected_shipping_radio_btn").val(selected_method_name); if (selected_method_name == "ups") { $("input:radio[data-inst='ups']").next().find("span.check").css("opacity", "1"); $("input:radio[data-inst='ups']").next().find("span.check").css("transform", "none"); $("#installment_shipping_html #shipping_method_ups").css("display", "block"); $("#shipping_html #shipping_method_ups").css("display", "block"); return false; } if (selected_method_name == "fedex") { $("input:radio[data-inst='fedex']").next().find("span.check").css("opacity", "1"); $("input:radio[data-inst='fedex']").next().find("span.check").css("transform", "none"); $("#installment_shipping_html #shipping_method_fedex").css("display", "block"); $("#shipping_html #shipping_method_fedex").css("display", "block"); return false; } if (selected_method_name == "instorepickup") { $("input:radio[data-inst='instorepickup']").next().find("span.check").css("opacity", "1"); $("input:radio[data-inst='instorepickup']").next().find("span.check").css("transform", "none"); $("#installment_shipping_html #shipping_method_instorepickup").css("display", "block"); $("#shipping_html #shipping_method_instorepickup").css("display", "block"); return false; } if (selected_method_name == "usps") { $("input:radio[data-inst='usps']").next().find("span.check").css("opacity", "1"); $("input:radio[data-inst='usps']").next().find("span.check").css("transform", "none"); $("#installment_shipping_html #shipping_method_usps").css("display", "block"); $("#shipping_html #shipping_method_usps").css("display", "block"); return false; } var shipping_method_id = $(this).attr("data-shipping-method-id"); var shipping_method_name = $(this).attr("data-shipping-method"); var shipping_method_slug = $(this).attr("data-shipping-slug"); var shipping_options_id = $(this).val(); var charge = $(this).attr("data-charge"); var shipping_countryId = $("#shipping_countryId").val(); var shipping_stateId = $("#form_shipping_stateId").val(); var shipping_cityId = $("#formShippingCity").val(); var shipping_zipcode = $("#form_shipping_zipcode").val(); var billing_countryId = $("#billing_countryId").val(); var billing_stateId = $("#form_billing_stateId").val(); var billing_cityId = $("#formBillingCity").val(); var billing_zipcode = $("#form_billing_zipcode").val(); var baseUrl = getBaseUrl(); var shipping_label = $(this).attr("data-label"); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if ((shipping_countryId != "" && shipping_countryId != undefined && shipping_stateId != "" && shipping_stateId != undefined && shipping_zipcode != undefined) || selected_shipping_method_slug == "instorepickup") { if (billing_stateId == null) { billing_stateId = ""; } if (billing_cityId == null) { billing_cityId = ""; } bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label); } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("shipping_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("shippingstateId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_zipcode]"); } }); } function checkSelectedShippingOption(id = "") { if (id != "proceed-installment" && id != "form[shopterms]") { var baseUrl = getBaseUrl(); $.ajax({ url: baseUrl + "/shoppingcart/installmentsessionremove", success: function(response) { if (response.msg == "failed") { return false; } }, }); } var radio_btn_slug = $("#selected_shipping_radio_btn").val(); var selected_method = $("#selected_shipping_method_slug").val(); if ($('input[name="' + id + '"]').is(":checked")) { if ((radio_btn_slug == "" || radio_btn_slug == "instorepickup" || radio_btn_slug == "usps" || radio_btn_slug == "ups" || radio_btn_slug == "fedex") && (selected_method == "localshipping" || selected_method == "freeshipping" || (selected_method != "" && selected_method != "undefined"))) { if (radio_btn_slug == "" && (selected_method == "instorepickup" || selected_method == "usps" || selected_method == "ups" || selected_method == "fedex")) { if ($("#shipping_method_instorepickup").val() == "" || $("#shipping_method_usps").val() == "" || $("#shipping_method_ups").val() || $("#shipping_method_fedex").val() == "") { swal("Error!", "Please select shipping options by entering your address details like Country, State / County, Town / City and Postcode / Zip", "error"); return false; } } else { if (selected_method == "instorepickup") { if ($("#shipping_method_instorepickup").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please choose a store location in the \"Select Store Option\" dropdown to pick up your products", "error"); return false; } if (radio_btn_slug == "usps") { if ($("#shipping_method_usps").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of USPS from USPS Option", "error"); return false; } } if (radio_btn_slug == "ups") { if ($("#shipping_method_ups").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of UPS from UPS Option", "error"); return false; } } if (radio_btn_slug == "fedex") { if ($("#shipping_method_fedex").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of Fedex from Fedex Option", "error"); return false; } } } } $(".payment_accordian").removeClass("disableDiv"); } else { $(".payment_accordian").addClass("disableDiv"); if (radio_btn_slug == "instorepickup") { if ($("#shipping_method_instorepickup").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please choose a store location in the \"Select Store Option\" dropdown to pick up your products", "error"); return false; } } if (radio_btn_slug == "usps") { if ($("#shipping_method_usps").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of USPS from USPS Option", "error"); return false; } } if (radio_btn_slug == "ups") { if ($("#shipping_method_ups").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of UPS from UPS Option", "error"); return false; } } if (radio_btn_slug == "fedex") { if ($("#shipping_method_fedex").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of Fedex from Fedex Option", "error"); return false; } } swal("Error!", "Please select shipping options by entering your address details like Country, State / County, Town / City and Postcode / Zip", "error"); return false; } } else { $(".payment_accordian").addClass("disableDiv"); } if (selected_method == "undefined" && lastUrl == "checkout") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select shipping options by entering your address details like Country, State / County, Town / City and Postcode / Zip", "error"); return false; } if (radio_btn_slug == "instorepickup") { if ($("#shipping_method_instorepickup").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please choose a store location in the \"Select Store Option\" dropdown to pick up your products", "error"); return false; } } if (radio_btn_slug == "usps") { if ($("#shipping_method_usps").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of USPS from USPS Option", "error"); return false; } } if (radio_btn_slug == "ups") { if ($("#shipping_method_ups").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of UPS from UPS Option", "error"); return false; } } if (radio_btn_slug == "fedex") { if ($("#shipping_method_fedex").val() == "") { $(".payment_accordian").addClass("disableDiv"); swal("Error!", "Please select option of Fedex from Fedex Option", "error"); return false; } } return true; } $(document).ready(function() { if (strstr(lastUrl, "checkout", false) == "checkout") { $("html, body").animate({ scrollTop: 0 }, "slow"); } if ($("#shipping_countryId").length > 0) { var countryId = $("#shipping_countryId").val(); getPhoneNumberFormat("#shipping_contact", "form[shipping_contact]" , countryId); stateAjax = true; getCheckoutState(countryId, checkout_ship_state, "shipping"); var stateId = $("#form_shipping_stateId").val(); cityAjax = true; getCheckoutCity(checkout_ship_state, checkout_ship_city, "shipping"); } if ($("#billing_countryId").length > 0) { var billCountryId = $("#billing_countryId").val(); getPhoneNumberFormat("#billing_contact", "form[billing_contact]" , billCountryId); stateAjax = true; getCheckoutState(billCountryId, checkout_bil_state, "billing"); cityAjax = true; getCheckoutCity(checkout_bil_state, checkout_bil_city, "billing"); } $("#shipping_html,#installment_shipping_html").delegate("#shipping_method_fedex", "change", function(e) { var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var shipping_countryId = $("#shipping_countryId").val(); var shipping_stateId = $("#form_shipping_stateId").val(); var shipping_cityId = $("#formShippingCity").val(); var shipping_zipcode = $("#form_shipping_zipcode").val(); var billing_countryId = $("#billing_countryId").val(); var billing_stateId = $("#form_billing_stateId").val(); var billing_cityId = $("#formBillingCity").val(); var billing_zipcode = $("#form_billing_zipcode").val(); var baseUrl = getBaseUrl(); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if ((shipping_zipcode != undefined) || selected_shipping_method_slug == "instorepickup") { if (billing_stateId == null) { billing_stateId = ""; } if (billing_cityId == null) { billing_cityId = ""; } bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label); } }); $("#shipping_html,#installment_shipping_html").delegate("#shipping_method_usps", "change", function(e) { var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var shipping_countryId = $("#shipping_countryId").val(); var shipping_stateId = $("#form_shipping_stateId").val(); var shipping_cityId = $("#formShippingCity").val(); var shipping_zipcode = $("#form_shipping_zipcode").val(); var billing_countryId = $("#billing_countryId").val(); var billing_stateId = $("#form_billing_stateId").val(); var billing_cityId = $("#formBillingCity").val(); var billing_zipcode = $("#form_billing_zipcode").val(); var baseUrl = getBaseUrl(); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if ((shipping_zipcode != undefined) || selected_shipping_method_slug == "instorepickup") { if (billing_stateId == null) { billing_stateId = ""; } if (billing_cityId == null) { billing_cityId = ""; } bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label); } }); $("#shipping_html,#installment_shipping_html").delegate("#shipping_method_ups", "change", function(e) { var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var shipping_countryId = $("#shipping_countryId").val(); var shipping_stateId = $("#form_shipping_stateId").val(); var shipping_cityId = $("#formShippingCity").val(); var shipping_zipcode = $("#form_shipping_zipcode").val(); var billing_countryId = $("#billing_countryId").val(); var billing_stateId = $("#form_billing_stateId").val(); var billing_cityId = $("#formBillingCity").val(); var billing_zipcode = $("#form_billing_zipcode").val(); var baseUrl = getBaseUrl(); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if ((shipping_zipcode != undefined) || selected_shipping_method_slug == "instorepickup") { if (billing_stateId == null) { billing_stateId = ""; } if (billing_cityId == null) { billing_cityId = ""; } bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label); } }); $("#shipping_html,#installment_shipping_html").delegate("#shipping_method_instorepickup", "change", function(e) { if ($("option:selected", this).attr("value") == "") { $("#shipping_method_instorepickup").val(""); var shipping_method_lable = $("option:selected", this).attr("data-radiobtnshippingslug"); $("#selected_shipping_radio_btn").val(shipping_method_lable); } var shipping_method_id = $("option:selected", this).attr("data-shipping-method-id"); var shipping_method_name = $("option:selected", this).attr("data-shipping-method"); var shipping_method_slug = $("option:selected", this).attr("data-shipping-slug"); var shipping_options_id = $("option:selected", this).attr("data-value"); var charge = $("option:selected", this).attr("data-charge"); var shipping_label = $("option:selected", this).attr("data-label"); var shipping_countryId = $("#shipping_countryId").val(); var shipping_stateId = $("#form_shipping_stateId").val(); var shipping_cityId = $("#formShippingCity").val(); var shipping_zipcode = $("#form_shipping_zipcode").val(); var billing_countryId = $("#billing_countryId").val(); var billing_stateId = $("#form_billing_stateId").val(); var billing_cityId = $("#formBillingCity").val(); var billing_zipcode = $("#form_billing_zipcode").val(); var baseUrl = getBaseUrl(); var selected_shipping_method_slug = $("#selected_shipping_method_slug").val(); if ((shipping_zipcode != undefined) || selected_shipping_method_slug == "instorepickup") { if (billing_stateId == null) { billing_stateId = ""; } if (billing_cityId == null) { billing_cityId = ""; } bindShippingDataCheckoutPage(shipping_method_id, shipping_method_name, shipping_method_slug, shipping_options_id, charge, shipping_countryId, shipping_stateId, shipping_cityId, shipping_zipcode, billing_countryId, billing_stateId, billing_cityId, billing_zipcode, baseUrl, shipping_label); } }); $("#countryId").on("select2:unselecting", function(e) { $("#stateId").val(null).trigger("change"); }); $("#shippingcalculationfrm").bootstrapValidator({ excluded: ":disabled", feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" }, fields: { countryId: { validators: { notEmpty: { message: "Please select Country" } }, }, stateId: { validators: { notEmpty: { message: "Please select State / County" } }, }, zipcode: { validators: { notEmpty: { message: "Please enter Postcode / Zip" }, stringLength: { max: 15, message: "Please enter valid Postcode / Zip", }, }, }, }, submitHandler: function(validator, form, submitButton) {}, }); if ($(".select2").length > 0) { if ($(".countryId").is(":visible")) { $(".countryId").select2({ placeholder: "Select Country", allowClear: true, width: "100%", }); } if ($(".stateId").is(":visible")) { $(".stateId").select2({ placeholder: "Select State / County", allowClear: true, width: "100%", }); } $("#checkbox6-444").change(function() { if ($(this).is(":checked")) { $("#countryId").select2({ placeholder: countryPlaceholder, allowClear: true, width: "100%", }); $("#stateId").select2({ placeholder: statePlaceholder, allowClear: true, width: "100%", }); $("#city").select2({ placeholder: cityPlaceholder, allowClear: true, width: "100%", }); } }); if ($(".addressId").is(":visible")) { $(".addressId").select2({ placeholder: front_sel_available_address, allowClear: true, width: "100%", }); } if ($(".form_dealers").is(":visible")) { $(".form_dealers").select2({ placeholder: "Select Dealers", allowClear: true, width: "100%", }); } if ($("#shipping_countryId").is(":visible")) { $("#shipping_countryId").select2({ placeholder: countryPlaceholder, allowClear: true, width: "100%", }); } if ($("#form_shipping_stateId").is(":visible")) { $("#form_shipping_stateId").select2({ placeholder: statePlaceholder, allowClear: true, width: "100%", }); } if ($("#formShippingCity").is(":visible")) { $("#formShippingCity").select2({ placeholder: cityPlaceholder, allowClear: true, width: "100%", }); } $("#chkbilladdress").change(function() { if ($(this).is(":checked")) { $("#billing_countryId").select2({ placeholder: countryPlaceholder, allowClear: true, width: "100%", }); $("#form_billing_stateId").select2({ placeholder: statePlaceholder, allowClear: true, width: "100%", }); $("#formBillingCity").select2({ placeholder: cityPlaceholder, allowClear: true, width: "100%", }); if (countryId != "" && checkout_bil_state != "") { stateAjax = true; var shipping_country = $('#shipping_countryId').val(); var xx = document.getElementById("billing_countryId"); if (xx.options.length == 2 && $('#billingaddressId').val() == '') { countryId = xx.options[1].value; if (shipping_country != countryId) { $('#billing_countryId').val(countryId).trigger('change'); $('#form_billing_zipcode').val(''); } } else { getCheckoutState(countryId, checkout_bil_state, "billing"); } } if (checkout_bil_state != "" && checkout_bil_city != "") { cityAjax = true; var shipping_country = $('#shipping_countryId').val(); var xx = document.getElementById("billing_countryId"); if (xx.options.length > 2) { getCheckoutCity(checkout_bil_state, checkout_bil_city, "billing"); } } } else { billingsameasshipping(); } }); } $("#calculatetaxmodal").on("shown.bs.modal", function(e) { $("#taxcalculationfrm #locationCountry").focus(); if ($(".select2").length > 0) { $("#locationCountry").select2({ placeholder: "Select Country", allowClear: true, width: "100%", dropdownParent: $("#calculatetaxmodal"), }); $("#locationState").select2({ placeholder: "Select State / County", allowClear: true, width: "100%", dropdownParent: $("#calculatetaxmodal"), }); } $("#taxcalculationfrm").bootstrapValidator({ excluded: ":disabled", feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" }, fields: { locationCountry: { validators: { notEmpty: { message: "Please select Country" } }, }, locationState: { validators: { notEmpty: { message: "Please select State / County" } }, }, locationCity: { validators: { notEmpty: { message: "Please enter Town / City" } }, }, locationZipcode: { validators: { notEmpty: { message: "Please enter Postcode / Zip" }, stringLength: { max: 15, message: "Please enter valid Postcode / Zip", }, }, }, }, submitHandler: function(validator, form, submitButton) {}, }); }); }); $("#form_shipping_zipcode").on("change", function(event) { event.preventDefault(); if ($(this).val() != "" && $(this).val() != undefined) { event.preventDefault(); event.stopImmediatePropagation(); var formData = $("#frmcheckout").serialize(); var country = $("#shipping_countryId").val(); var state = $("#form_shipping_stateId").val(); if (country != "" && state != "") { if ("#shipping_base_on".length > 0) { if ($("#shipping_base_on").val() == "shipping_address" || $("#hdn_location_flag").val() == "No" || ($("#shipping_base_on").val() == "billing_address" && $("#chkbilladdress").prop("checked") == false)) showShippingOptions(formData); if ($('input[type="checkbox"][name="form[shopterms]"]').is(":checked")) { $('input[type="checkbox"][name="form[shopterms]"]').attr("checked", false); $(".payment_accordian").addClass("disableDiv"); } } } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("shipping_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("shippingstateId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_zipcode]"); } } }); $("#form_billing_zipcode").on("change", function(event) { if ($(this).val() != "" && $(this).val() != undefined) { event.preventDefault(); event.stopImmediatePropagation(); var formData = $("#frmcheckout").serialize(); var country = $("#billing_countryId").val(); var state = $("#form_billing_stateId").val(); if (country != "" && state != "") { if ("#shipping_base_on".length > 0) { if ($("#shipping_base_on").val() != "shipping_address") showShippingOptions(formData); if ($('input[type="checkbox"][name="form[shopterms]"]').is(":checked")) { $('input[type="checkbox"][name="form[shopterms]"]').attr("checked", false); $(".payment_accordian").addClass("disableDiv"); } } } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("billing_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("billingstateId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[billing_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[billing_zipcode]"); } } }); function showShippingOptions(formData, abc) { var baseUrl = getBaseUrl(); var bill_diff_address = 0; if ($("#chkbilladdress").prop("checked") == true || $('#selected_shipping_method_slug').val() == 'instorepickup') { bill_diff_address = 1; } $.ajax({ type: "POST", dataType: "json", url: baseUrl + "/shippingchargeoptions", cache: false, data: formData + '&bill_diff_address=' + bill_diff_address, beforeSend: function() { $(".loader").removeClass("hide"); $(".loader").addClass("show"); }, success: function(response) { if (response["shipping_data"] != "") { $("#shipping_html").html(response["shipping_data"]["ShippingHtml"]); $("#installment_shipping_html").html(response["shipping_data"]["InstallmentShippingHtml"]); thousandSeparator = response["thousand_separator"]; decimalSeparator = response["decimal_separator"] decimalNumber = response["decimal_number"]; function formatNumber(number, decimalSeparator, thousandSeparator, decimalNumber) { if (decimalSeparator === "") { number = Math.round(number); } else if (decimalNumber !== "") { number = Math.round(number * Math.pow(10, decimalNumber)) / Math.pow(10, decimalNumber); } const [integerPart, decimalPart] = number.toFixed(decimalNumber).split('.'); const formattedIntegerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator); return decimalPart ? formattedIntegerPart + decimalSeparator + decimalPart : formattedIntegerPart; } if (response["is_error"] != 1) { var totaldiscount = 0; var grandtotal = $(".c-subtotal").attr("data-subtotal"); var tax = 0; if ($(".c-taxtotal").length > 0) { tax = $(".c-taxtotal").attr("data-totaltax"); } if ($(".c-discounttotal").length > 0) { totaldiscount = $(".c-discounttotal").attr("data-totaldiscount"); } grandtotal = parseFloat(grandtotal) + parseFloat(tax) - parseFloat(totaldiscount); grandtotal = grandtotal * session_currency_rate; grandtotalnew = formatNumber(grandtotal, `${decimalSeparator}`, `${thousandSeparator}`, `${decimalNumber}`); $(".grand_total_with_tax_scharge").text(symbol + grandtotalnew); $(".cls_shipping_charge").html(""); $("#is_shipping_calculated").val(""); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[is_shipping_calculated]"); if ($('#delivery_address_div').css('display') == 'none') { $("#delivery_address_div").css("display", "block"); $("#billing-address-checkbox").css("display", "block"); $("#shipping_countryId").select2().change(); $("#form_shipping_stateId").select2(); $("#formShippingCity").select2(); $("#chkbilladdress").attr('checked', true); } $("#selected_shipping_method_slug").val(""); if ($("#instorepickup_address_div").length > 0) { $("#instorepickup_address_div").css("display", "none"); } $('.predate').hide(); } else { $("#is_shipping_calculated").val(1); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[is_shipping_calculated]"); var grandtotal = $(".c-subtotal").attr("data-subtotal"); var selectedradioId = $('input[type=radio][name="radio_shipping_method_name"]:checked').attr("id"); var selectedradio_slug = $('input[type=radio][name="radio_shipping_method_name"]:checked').attr("data-shipping-slug"); $("#selected_shipping_method_slug").val(selectedradio_slug); if (selectedradio_slug != "instorepickup") { if ($('#delivery_address_div').css('display') == 'none') { $("#delivery_address_div").css("display", "block"); $("#billing-address-checkbox").css("display", "block"); $("#shipping_countryId").select2().change(); $("#form_shipping_stateId").select2(); $("#formShippingCity").select2(); $("#chkbilladdress").prop('checked',true); } if ($("#instorepickup_address_div").length > 0) { $("#instorepickup_address_div").css("display", "none"); } } if (selectedradio_slug != "localshipping") { $('.predate').hide(); } else { $('.predate').show(); } if (selectedradioId != undefined) { var totaldiscount = 0; var charge_symbol = $('input[type=radio][name="radio_shipping_method_name"]:checked').attr("data-charge-symbol"); var shipping_charge = $('input[type=radio][name="radio_shipping_method_name"]:checked').attr("data-charge"); $(".cls_shipping_charge").attr("data-shippingcharge", shipping_charge); var tax = 0; if ($(".c-taxtotal").length > 0) { tax = $(".c-taxtotal").attr("data-totaltax"); } if ($(".c-discounttotal").length > 0) { totaldiscount = $(".c-discounttotal").attr("data-totaldiscount"); } grandtotal = parseFloat(grandtotal) + parseFloat(shipping_charge) + parseFloat(tax) - parseFloat(totaldiscount); grandtotal = grandtotal * session_currency_rate; grandtotalnew = formatNumber(grandtotal, `${decimalSeparator}`, `${thousandSeparator}`, `${decimalNumber}`); $(".cls_shipping_charge").html(charge_symbol); if (PaymentType == "fullpayment") { $("#fullpayment .grand_total_with_tax_scharge").html(symbol + grandtotalnew); } } } $("#frmcheckout").bootstrapValidator("revalidateField", "form[shipping_city]"); $("#frmcheckout").bootstrapValidator("revalidateField", "shippingstateId"); $("#frmcheckout").bootstrapValidator("revalidateField", "billingstateId"); $("#frmcheckout").bootstrapValidator("revalidateField", "form[billing_city]"); } else { $("#shipping_html").html(""); $("#installment_shipping_html").html(""); } $("#loading").css("display", "none"); }, complete: function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, }); } $("#shipping_countryId").on("change", function() { var ship_country = $("#shipping_countryId").val(); getPhoneNumberFormat("#shipping_contact", "form[shipping_contact]" , ship_country); getCheckoutState(ship_country, (selectedState = ""), "shipping", "change"); calculateCheckoutTax(); getShipZipOnChange(); }); $("#form_shipping_stateId").on("change", function() { var ship_state = $("#form_shipping_stateId").val(); $("#formShippingCity").val(""); getCheckoutCity(ship_state, (selectedCity = ""), "shipping", "change"); calculateCheckoutTax(); getShipZipOnChange(); }); $("#formShippingCity").on("change", function() { calculateCheckoutTax(); $("#form_shipping_zipcode").trigger("change"); }); $("#form_shipping_zipcode").on("blur", function() { calculateCheckoutTax(); $("#form_shipping_zipcode").trigger("change"); }); $("#formShippingCity").on("change", function() { calculateCheckoutTax(); getShipZipOnChange(); }); $("#formShippingCity").on("blur", function() { calculateCheckoutTax(); getShipZipOnChange(); }); $("#billing_countryId").on("change", function() { var bill_country = $("#billing_countryId").val(); getPhoneNumberFormat("#billing_contact", "form[billing_contact]" , bill_country); getCheckoutState(bill_country, (selectedState = ""), "billing", "change"); calculateCheckoutTax(); getBillZipOnChange(); }); $("#form_billing_stateId").on("change", function() { var bill_state = $("#form_billing_stateId").val(); getCheckoutCity(bill_state, (selectedCity = ""), "billing", "change"); calculateCheckoutTax(); getBillZipOnChange(); }); $("#formBillingCity").on("change", function() { calculateCheckoutTax(); $("#form_billing_zipcode").trigger("change"); }); $("#form_billing_zipcode").on("blur", function() { calculateCheckoutTax(); $("#form_billing_zipcode").trigger("change"); }); $("#formBillingCity").on("blur", function() { calculateCheckoutTax(); getBillZipOnChange(); }); $("#formBillingCity").on("change", function() { calculateCheckoutTax(); getBillZipOnChange(); }); function getShipZipOnChange() { var formData = $("#frmcheckout").serialize(); var country = $("#shipping_countryId").val(); var state = $("#form_shipping_stateId").val(); if (country != "" && state != "") { if ("#shipping_base_on".length > 0) { if ($("#shipping_base_on").val() == "shipping_address" || $("#hdn_location_flag").val() == "No" || ($("#shipping_base_on").val() == "billing_address" && $("#chkbilladdress").prop("checked") == false)) showShippingOptions(formData); if ($('input[type="checkbox"][name="form[shopterms]"]').is(":checked")) { $('input[type="checkbox"][name="form[shopterms]"]').attr("checked", false); $(".payment_accordian").addClass("disableDiv"); } } } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("shipping_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("shippingstateId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_zipcode]"); } } function getBillZipOnChange() { var formData = $("#frmcheckout").serialize(); var country = $("#billing_countryId").val(); var state = $("#form_billing_stateId").val(); if (country != "" && state != "") { if ("#shipping_base_on".length > 0) { if ($("#shipping_base_on").val() != "shipping_address") showShippingOptions(formData); if ($('input[type="checkbox"][name="form[shopterms]"]').is(":checked")) { $('input[type="checkbox"][name="form[shopterms]"]').attr("checked", false); $(".payment_accordian").addClass("disableDiv"); } } } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("billing_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("billingstateId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[billing_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[billing_zipcode]"); } } if ($(".datepicker").length > 0) { $("#rangeFrom").datepicker({ format: "mm/dd/yyyy", startDate: "0d", beforeShowDay: closedDay, firstDay: 1, }).on("changeDate", function(e) { var minDate = new Date(e.date.valueOf()); $("#rangeTo").datepicker("setStartDate", minDate); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeFrom"); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeTo"); }); $("#rangeTo").datepicker({ format: "mm/dd/yyyy", startDate: "0d", beforeShowDay: closedDay, firstDay: 1, }).on("changeDate", function(e) { var maxDate = new Date(e.date.valueOf()); $("#rangeFrom").datepicker("setEndDate", maxDate); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeFrom"); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeTo"); }); var leadTime = $("#form_leadTime").val(); var currentDate = new Date(); var start_date = addWorkingDays(currentDate, leadTime); $("#form_deliveryDate").datepicker({ format: "mm/dd/yyyy", startDate: start_date, beforeShowDay: isWeekend, firstDay: 1, }); $("#rangeFrom_installment").datepicker({ format: "mm/dd/yyyy", startDate: "0d", beforeShowDay: closedDay, firstDay: 1, }).on("changeDate", function(e) { var minDate = new Date(e.date.valueOf()); $("#rangeTo_installment").datepicker("setStartDate", minDate); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeFrom"); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeTo"); }); $("#rangeTo_installment").datepicker({ format: "mm/dd/yyyy", startDate: "0d", beforeShowDay: closedDay, firstDay: 1, }).on("changeDate", function(e) { var maxDate = new Date(e.date.valueOf()); $("#rangeFrom_instalment").datepicker("setEndDate", maxDate); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeFrom"); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeTo"); }); function closedDay(date) { if (shipping_days != "") { var ship_days = shipping_days.split(","); var total_days = ["1", "2", "3", "4", "5", "6"]; var onDays = []; var offDays = []; for (var d = 0; d < total_days.length; d++) { if ($.inArray(total_days[d], ship_days) != -1) { onDays.push(total_days[d]); } else { offDays.push(total_days[d]); } } var day = date.getDay(); if (day == 0) { return false; } else { for (var i = 0; i < offDays.length; i++) { if (day == offDays[i]) { return false; } } } return true; } else { return true; } } $(".datepicker").on("change", function() { $("#frmcheckout").bootstrapValidator("revalidateField", "rangeFrom"); $("#frmcheckout").bootstrapValidator("revalidateField", "rangeTo"); }); } function isWeekend(date) { var day = date.getDay(); return [day !== 0 && day !== 6, '']; } $("body").delegate("#calculate_shipping_charge", "click", function(e) { e.preventDefault(); e.stopImmediatePropagation(); var btn_calc = $(this).attr("data-value"); $("#shippingcalculationfrm").bootstrapValidator({ excluded: ":disabled", feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" }, fields: { countryId: { validators: { notEmpty: { message: "Please select Country" } }, }, stateId: { validators: { notEmpty: { message: "Please select State / County" } }, }, city: { validators: { notEmpty: { message: "Please select Town / City" } }, }, zipcode: { validators: { notEmpty: { message: "Please enter Postcode / Zip" }, stringLength: { max: 10, message: "Please enter valid Postcode / Zip", }, }, }, }, submitHandler: function(validator, form, submitButton) {}, }); $("#shippingcalculationfrm").bootstrapValidator("revalidateField", "countryId"); $("#shippingcalculationfrm").bootstrapValidator("revalidateField", "stateId"); $("#shippingcalculationfrm").bootstrapValidator("revalidateField", "zipcode"); if ($("#shippingcalculationfrm").bootstrapValidator("validate").has(".has-error").length === 0) { // var formData = $("#shippingcalculationfrm").serialize(); var formData = $('[form-data="shoppingcart"]').serialize(); getShippingCharge(formData, btn_calc); } else { return false; } }); $("body").delegate("#calculate_shipping_charge_chekoutpage", "click", function(e) { e.preventDefault(); //e.stopImmediatePropagation(); var btn_calc = $(this).attr("data-value"); $("#shippingcalculationfrmchkoutpg").bootstrapValidator({ excluded: ":disabled", feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" }, fields: { countryId: { validators: { notEmpty: { message: "Please select Country" } }, }, stateId: { validators: { notEmpty: { message: "Please select State / County" } }, }, city: { validators: { notEmpty: { message: "Please select Town / City" } }, }, zipcode: { validators: { notEmpty: { message: "Please enter Postcode / Zip" }, stringLength: { max: 10, message: "Please enter valid Postcode / Zip", }, }, }, }, submitHandler: function(validator, form, submitButton) {}, }); $("#shippingcalculationfrmchkoutpg").bootstrapValidator("revalidateField", "countryId"); $("#shippingcalculationfrmchkoutpg").bootstrapValidator("revalidateField", "stateId"); $("#shippingcalculationfrmchkoutpg").bootstrapValidator("revalidateField", "zipcode"); if ($("#shippingcalculationfrmchkoutpg").bootstrapValidator("validate").has(".has-error").length === 0) { var formData = $('[scope="part1"]').serialize(); getShippingChargeOnCheckout(formData, btn_calc); } else { return false; } }); $("#chkbilladdress").change(function() { if ($(this).is(":checked") && checkout_billing_address == "" && isDiffBillAddrr == '0') { if ($("#billing_firstName").val() == '') { $("#billing_firstName").val($("#shipping_firstName").val()); } if ($("#billing_middleName").val() == '') { $("#billing_middleName").val($("#shipping_middleName").val()); } if ($("#billing_lastName").val() == '') { $("#billing_lastName").val($("#shipping_lastName").val()); } if ($("#billing_companyName").val() == '') { $("#billing_companyName").val($("#shipping_companyName").val()); } if ($("#billing_emailid").val() == '') { $("#billing_emailid").val($("#shipping_emailid").val()); } if ($("#billing_contact").val() == '') { $("#billing_contact").val($("#shipping_contact").val()); } if ($("#billing_fax").val() == '') { $("#billing_fax").val($("#shipping_fax").val()); } $("#billing_countryId").val($("#shipping_countryId").val()); getPhoneNumberFormat("#billing_contact", "form[billing_contact]" , $("#shipping_countryId").val()); setTimeout(function() { $("#form_billing_stateId").html($("#form_shipping_stateId").html()); $("#form_billing_stateId").val($("#form_shipping_stateId").val()); $("#frmcheckout").bootstrapValidator("revalidateField", "billingstateId"); }, 500); setTimeout(function() { $("#formBillingCity").html($("#formShippingCity").html()).val($("#formShippingCity").val()); $("#formBillingCity").val($("#formShippingCity").val()); $("#frmcheckout").bootstrapValidator("revalidateField", "form[billing_city]"); }, 500); $("#form_billing_zipcode").val($("#form_shipping_zipcode").val()).trigger("change"); } }); //added by milind dave on 18122023 for shipping calculator on checkout page function getShippingChargeOnCheckout(formData, btn_calc){ var baseUrl = getBaseUrl(); $.ajax({ type: "POST", dataType: "json", url: baseUrl + "/shippingcharge", cache:false, data: formData, beforeSend: function(){ showLoader(); }, success: function(response){ if(response['shipping_data'] != ''){ $("#shipping_html").html(response['shipping_data']['ShippingHtml']); var selectedradioId = $('.show_shipping_charge:checked').attr('id'); $('input[id="' + selectedradioId + '"]:radio').trigger("click"); getCheckoutState($("#shipping_countryId").val(), $('#stateId').val(), "shipping", "change"); //getCheckoutCity($('#stateId').val(), $('#cityId').val(), "shipping", "change"); //$("#form_shipping_stateId").val($('#stateId').val()).trigger('change.select2') $('#formShippingCity').val($('#city').val()).trigger('change.select2'); $('#form_shipping_zipcode').val($('#zipcode').val()); //loadShopppingCart(btn_calc); //getshippingoptins(); calculateCheckoutTax(); getShipZipOnChange(); showShippingOptions(); }else{ $('#shipping_html').html(''); } if(response.popUpShipping == 1) { $('#popUpShipping').modal('show'); $(".inStorePickup").show(); $(".shippingNull").hide(); } else if(response.popUpShipping == 2) { $('#popUpShipping').modal('show'); $(".inStorePickup").hide(); $(".shippingNull").show(); } hideLoader(); setTimeout(function() { $('#shipmethod').removeClass('in'); $('#collapsed_shipmethod').addClass('collapsed'); $("#collapsed_shipmethod").attr("aria-expanded","false"); }, 3000); }, complete: function(){ hideLoader(); }, }); } //end of added by milind dave on 18122023 for shipping calculator on checkout page function getShippingCharge(formData, btn_calc) { var baseUrl = getBaseUrl(); $.ajax({ type: "POST", dataType: "json", url: baseUrl + "/shippingcharge", cache: false, data: formData, beforeSend: function() { showLoader(); }, success: function(response) { if (response["shipping_data"] != "") { $("#shipping_html").html(response["shipping_data"]["ShippingHtml"]); var selectedradioId = $(".show_shipping_charge:checked").attr("id"); $('input[id="' + selectedradioId + '"]:radio').trigger("click"); loadShopppingCart(btn_calc); } else { $("#shipping_html").html(""); } $("#loading").css("display", "none"); }, complete: function() { //showLoader(); hideLoader(); }, }); } function loadShopppingCart(btn_calc = "") { $.ajax({ type: "GET", cache: false, url: "/shoppingcartajax", dataType: "json", data: { btn_calc: btn_calc }, beforeSend: function() { showLoader(); }, success: function(result) { loadMiniCart(); $("#myShoppingCartDiv").html(result.html); $(".countryId").select2({ placeholder: "Select Country", allowClear: true, width: "100%", }); $(".stateId").select2({ placeholder: "Select State", allowClear: true, width: "100%", }); var first_installment_price_hdn_val = $("#first_installment_price_hdn_val").val(); if (first_installment_price_hdn_val) { $("#first-payment-amount-val").text(first_installment_price_hdn_val); } if ($(".touchspin").length > 0) { $(".touchspin").TouchSpin({ buttondown_class: "btn red", buttonup_class: "btn blue", min: 2, max: InstallmentData.max_no_of_installment, }).on("touchspin.on.startupspin", function() { var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); var extra_charge = InstallmentData.first_installment_price - InstallmentData.installment_price - InstallmentData.down_payment; var new_set_amount = (parseFloat(InstallmentData.installment_total_amount) - extra_charge) / total_no_of_payments; var pre_first_installment = parseFloat(InstallmentData.first_installment_price) - parseFloat(InstallmentData.installment_price); var new_first_payment = pre_first_installment + new_set_amount; new_first_payment = new_first_payment * session_currency_rate; new_first_payment = symbol + new_first_payment.toFixed(2); $("#first-payment-amount-val").text(new_first_payment); $("#first_installment_price_hdn_val").val(new_first_payment); new_set_amount = new_set_amount * session_currency_rate; new_set_amount = symbol + new_set_amount.toFixed(2); $("#monthly_payment_amount").text(new_set_amount); }).on("touchspin.on.startdownspin", function() { var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); var extra_charge = InstallmentData.first_installment_price - InstallmentData.installment_price - InstallmentData.down_payment; var new_set_amount = (parseFloat(InstallmentData.installment_total_amount) - extra_charge) / total_no_of_payments; var pre_first_installment = parseFloat(InstallmentData.first_installment_price) - parseFloat(InstallmentData.installment_price); var new_first_payment = pre_first_installment + new_set_amount; new_first_payment = new_first_payment * session_currency_rate; new_first_payment = symbol + new_first_payment.toFixed(2); $("#first-payment-amount-val").text(new_first_payment); $("#first_installment_price_hdn_val").val(new_first_payment); new_set_amount = new_set_amount * session_currency_rate; new_set_amount = symbol + new_set_amount.toFixed(2); $("#monthly_payment_amount").text(new_set_amount); }); } if(result.popUpShipping == 1 && btn_calc != '') { $('#popUpShipping').modal('show'); $(".inStorePickup").show(); $(".shippingNull").hide(); } else if(result.popUpShipping == 2 && btn_calc != '') { $('#popUpShipping').modal('show'); $(".inStorePickup").hide(); $(".shippingNull").show(); } if (result.gtaData != "" && wbGoogleAnalyticId != "" && wbStandardTracking == 1 && wbEcommerceTracking == 1) { gtag("event", "checkout_progress", { event_label: "Checkout Progress", items: result.gtaData.item, coupon: result.gtaData.coupon, }); } }, error: function(jqXHR, textStatus, errorThrown) { return false; }, complete: function() { hideLoader(); }, }); } function getCheckoutState(countryId, selectedState, onChange, type = "") { var warehouse = $("#shipping_method_instorepickup").val(); if (stateAjax == true) { if(!(warehouse != '' && onChange == "shipping") || typeof warehouse === "undefined") { stateAjax = false; $.ajax({ type: "POST", cache: true, url: "/getstate", data: "ctrid=" + countryId + "&state_id=" + selectedState + "&onchange=" + onChange, beforeSend: function() { $(".loader").removeClass("hide"); $(".loader").addClass("show"); }, success: function(result) { stateAjax = true; if (onChange == "shipping") { $("#form_shipping_stateId").html(result).trigger('change.select2'); $("#stateId").html(result).trigger('change.select2'); } else if (onChange == "billing") { $("#form_billing_stateId").html(result).trigger('change.select2'); } else if (onChange == "invoice") { $("#invoice_state_id").html(result).trigger('change.select2'); } else { $(".product_inquiry_stateId").html(result);//.trigger('change.select2') } $("#frmcheckout").bootstrapValidator("revalidateField", "shippingstateId"); $("#frmcheckout").bootstrapValidator("revalidateField", "billingstateId"); }, error: function(jqXHR, textStatus, errorThrown) { return false; }, complete: function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, }); } } } function getCheckoutCity(stateId, selectedCity, onChange, type = "") { var warehouse = $("#shipping_method_instorepickup").val(); if (cityAjax == true) { if (onChange == "shipping") { $("#formShippingCity").html(""); } else if (onChange == "billing") { $("#formBillingCity").html(""); } else if(onChange == "calculate") { $("#city").html(""); } if(!(warehouse != '' && onChange == "shipping") || typeof warehouse === "undefined") { cityAjax = false; $.ajax({ type: "POST", cache: true, url: "/getcity", data: "stateid=" + stateId + "&city_id=" + selectedCity + "&onchange=" + onChange, beforeSend: function() { $(".loader").removeClass("hide"); $(".loader").addClass("show"); }, success: function(result) { if (onChange == "shipping") { $("#formShippingCity").html(result).trigger('change.select2'); $('#city').html(result).trigger('change.select2'); } else if (onChange == "billing") { $("#formBillingCity").html(result).trigger('change.select2'); } else if (onChange == "invoice") { $("#invoice_city").html(result).trigger('change.select2'); } else if(onChange == "calculate") { $("#city").html(result).trigger('change.select2'); } else { $(".product_inquiry_cityId").html(result); } $("#frmcheckout").bootstrapValidator("revalidateField", "form[shipping_city]"); $("#frmcheckout").bootstrapValidator("revalidateField", "form[billing_city]"); cityAjax = true; }, error: function(jqXHR, textStatus, errorThrown) { return false; }, complete: function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, }); } } } function getPhoneNumberFormat(elementId, elementName ,countryId) { $.ajax({ type: "POST", cache: true, url: "/get-phone-format", data: "ctrid=" +countryId, dataType: "json", success: function(result) { //console.log('result.phoneNumberformat ' + result.phoneNumberformat) //console.log('result.stringlength ' + result.phoneNumberLen) $(elementId).attr("data-phone-mask", result.phoneNumberformat); //$(elementId).attr('pattern', result.regex); $(elementId).attr('placeholder', result.phoneNumberformat); $(elementId).attr('maxlength', result.phoneNumberLen); //$("#frmcheckout").bootstrapValidator("revalidateField",elementName); var phoneFormat = result.phoneNumberformat.replace(/\x/g, '9'); $(elementId).inputmask({"mask": phoneFormat}); }, error: function(jqXHR, textStatus, errorThrown) { return false; } }); } if ($('.form_dealers').length > 0) { if ($('#hdnDealerId').val()) { getDealerAddress($('#hdnDealerId').val()); } } $('body').delegate('.form_dealers', 'change', function(e) { var dealerId = $(this).val(); getDealerAddress(dealerId); }); $('body').delegate('#stateId', 'change', function(e) { var stateId = $("#stateId").val(); var selectedCity = $("#cityId").val(); getCheckoutCity(stateId,selectedCity, "calculate", "change"); }); function getDealerAddress(dealerId) { var baseUrl = getBaseUrl(); $.ajax({ type: "post", cache: false, url: baseUrl + "/getdealers", data: "dealerId=" + dealerId, dataType: "json", beforeSend: function() { $(".loader").removeClass("hide"); $(".loader").addClass("show"); }, success: function(result) { $(".addressId").html(result.ShippingAddrHtml); $("#shipping_firstName").val(result.customerAddress.firstName); $("#shipping_middleName").val(result.customerAddress.middleName); $("#shipping_lastName").val(result.customerAddress.lastName); $("#shipping_emailid").val(result.customerAddress.emailid); $("#shipping_contact").val(result.customerAddress.contact); $("#shipping_fax").val(result.customerAddress.fax); $("#frmcheckout").bootstrapValidator("revalidateField", "form[shipping_city]"); $("#frmcheckout").bootstrapValidator("revalidateField", "shippingstateId"); $("#frmcheckout").bootstrapValidator("revalidateField", "billingstateId"); $("#frmcheckout").bootstrapValidator("revalidateField", "form[billing_city]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_address1]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_address2]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("shipping_countryId"); $("#frmcheckout").data("bootstrapValidator").revalidateField("rangeFrom"); $("#frmcheckout").data("bootstrapValidator").revalidateField("rangeTo"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_zipcode]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_firstName]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_lastName]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_emailid]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[shipping_contact]"); }, error: function(jqXHR, textStatus, errorThrown) { return false; }, complete: function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, }); } $(document).ready(function() { $("body").delegate(".date-picker", "change", function(e) { if ($(this).prop("required")) $("#storefrmbuilder").bootstrapValidator("updateStatus", $(this), "NOT_VALIDATED").bootstrapValidator("validateField", $(this)); }); }); function installmentPlusbutton() { var max = InstallmentData.max_no_of_installment; var baseUrl = getBaseUrl(); var first_installment_price_hdn_val = $("#first_installment_price_hdn_val").val(); if (first_installment_price_hdn_val) { $("#first-payment-amount-val").text(first_installment_price_hdn_val); } var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); if (total_no_of_payments < max) { parseInt($("#form_total_no_of_payments").val(parseInt(total_no_of_payments) + 1)); var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); } $.ajax({ type: "POST", url: baseUrl + "/shoppingcart/installmentsession", cache: false, data: { totalNoOfPayments: total_no_of_payments }, success: function(response) { if (response.msg == "failed") { return false; } }, }); var extra_charge = InstallmentData.first_installment_price - InstallmentData.installment_price - InstallmentData.down_payment; var new_set_amount = (parseFloat(InstallmentData.installment_total_amount) - extra_charge) / total_no_of_payments; var pre_first_installment = parseFloat(InstallmentData.first_installment_price) - parseFloat(InstallmentData.installment_price); var new_first_payment = pre_first_installment + new_set_amount; new_first_payment = new_first_payment * session_currency_rate; var newFirst_payment = new_first_payment; new_first_payment = symbol + number_format(new_first_payment, decimal_number, decimal_separator, thousand_separator); $("#first-payment-amount-val").text(new_first_payment); $("#first_installment_price_hdn_val").val(new_first_payment); new_set_amount = new_set_amount * session_currency_rate; new_set_amount = symbol + number_format(new_set_amount, decimal_number, decimal_separator, thousand_separator); $("#monthly_payment_amount").val(new_set_amount); $("#monthly_payment").text(new_set_amount); var installment_grand_total = parseFloat(newFirst_payment); installment_grand_total = number_format(installment_grand_total, decimal_number, decimal_separator, thousand_separator); $("#installment_grand_total").text(symbol + installment_grand_total); } function installmentMinusbutton() { var min = 2; var baseUrl = getBaseUrl(); var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); if (total_no_of_payments > min) { parseInt($("#form_total_no_of_payments").val(parseInt(total_no_of_payments) - 1)); var total_no_of_payments = parseInt($("#form_total_no_of_payments").val()); } $.ajax({ type: "POST", url: baseUrl + "/shoppingcart/installmentsession", cache: false, data: { totalNoOfPayments: total_no_of_payments }, success: function(response) { if (response.msg == "failed") { return false; } }, }); var extra_charge = InstallmentData.first_installment_price - InstallmentData.installment_price - InstallmentData.down_payment; var new_set_amount = (parseFloat(InstallmentData.installment_total_amount) - extra_charge) / total_no_of_payments; var pre_first_installment = parseFloat(InstallmentData.first_installment_price) - parseFloat(InstallmentData.installment_price); var new_first_payment = pre_first_installment + new_set_amount; new_first_payment = new_first_payment * session_currency_rate; var newFirst_payment = new_first_payment; new_first_payment = symbol + number_format(new_first_payment, decimal_number, decimal_separator, thousand_separator) $("#first-payment-amount-val").text(new_first_payment); $("#first_installment_price_hdn_val").val(new_first_payment); new_set_amount = new_set_amount * session_currency_rate; new_set_amount = symbol + number_format(new_set_amount, decimal_number, decimal_separator, thousand_separator); $("#monthly_payment_amount").val(new_set_amount); $("#monthly_payment").text(new_set_amount); var installment_grand_total = parseFloat(newFirst_payment); installment_grand_total = number_format(installment_grand_total, decimal_number, decimal_separator, thousand_separator); $("#installment_grand_total").text(symbol + installment_grand_total); } $("#heading_fullpaymet").on("click", function(e) { $("#fullpayment").removeAttr("style"); hideInstallmentAccord(); $("#collapsed_fullPyament").addClass("collapsed"); $("#amount").val($("#fullpayment_grand_total").attr("data-grandtotal")); var PaymentType = "fullpayment"; var baseUrl = getBaseUrl(); $.ajax({ type: "POST", url: baseUrl + "/shoppingcart/accordiansessionset", cache: false, data: { PaymentType: PaymentType }, success: function(response) { if (response.msg == "success") { window.location = "checkout"; $("#collapsed_fullPyament").removeClass("collapsed"); } }, }); }); $("body").delegate("#checkbox1-77", "change", function(e) { e.stopImmediatePropagation(); if ($(this).prop("checked") == true) { $("#frmcheckout").bootstrapValidator("enableFieldValidators", "form[password]", true).bootstrapValidator("enableFieldValidators", "form[confirm_password]", true); $("#frmcheckout").bootstrapValidator("revalidateField", "form[password]"); $("#frmcheckout").bootstrapValidator("revalidateField", "form[confirm_password]"); } else { $("#frmcheckout").bootstrapValidator("enableFieldValidators", "form[password]", false).bootstrapValidator("enableFieldValidators", "form[confirm_password]", false); } $("#checkbox1-77").removeClass("checkbox-border"); if ($(this).prop("checked") == false) { hideInstallmentAccord(); } else { $("#frmcheckout").data("bootstrapValidator").revalidateField("form[password]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[confirm_password]"); } }); $("#installment_anchar").on("click", function(e) { $(".loader").removeClass("hide"); $(".loader").addClass("show"); if ($("#installment_anchar").hasClass("collapsed")) { setTimeout(function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, 1000); $("#amount").val($("#installment_grand_total").attr("data-grandtotal")); var total_no_of_payments = $("#form_total_no_of_payments").val(); var baseUrl = getBaseUrl(); var password = $("#form_password").val(); $.ajax({ type: "POST", url: baseUrl + "/shoppingcart/proceedInstallment", cache: false, data: { totalNoOfPayments: total_no_of_payments }, success: function(response) { if (response == 1) { if (CustomerId == "") { if ($(".shopnewaccount").prop("checked") == true) { showInstallment(); } else { swal({ title: ' "In order to proceed with the "' + $("#installment_method_swt").html() + '" Option, you will be required to "Log In" or "Create" an account. Please choose one of the options below.', type: "warning", allowOutsideClick: true, showCancelButton: true, confirmButtonText: "Create an Account", cancelButtonText: "Log In", }, function(isConfirm) { if (isConfirm) { var nonUI = true; PaymentType = "installment"; $("html, body").animate({ scrollTop: $("#new_account").position().top, }, 2000); $("#checkbox1-77").trigger("click"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[password]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[confirm_password]"); showInstallment(); Pclick = true; return true; } else { hideInstallmentAccord(); $(".Checkout-dropdown").attr("aria-expanded", true); if ($("#demo").hasClass("in") == false) { $(".Checkout-dropdown").trigger("click"); } $("html, body").animate({ scrollTop: $("#demo").position().top, }, 2000); $("#demo").show(); } }); $("#checkbox1-77").addClass("checkbox-border"); e.preventDefault(); e.stopImmediatePropagation(); } } else if (PaymentType == "") { showInstallment(); e.preventDefault(); e.stopImmediatePropagation(); return true; } else { swal({ title: 'To proceed with "' + $("#installment_method_swt").html() + '", option, you will be required to have an account. Please select the option to "Create an Account" Or "Login" using your credentials.', type: "warning", showCancelButton: false, confirmButtonText: "Ok", }); hideInstallmentAccord(); $("#checkbox1-77").addClass("checkbox-border"); } } else if (response == "true") { if (CustomerId != "") { showInstallment(); e.preventDefault(); e.stopImmediatePropagation(); return true; } } else { if (response == "false") { swal({ title: "Something went to wrong !!!", type: "error", showCancelButton: false, confirmButtonText: "Ok, Remove", cancelButtonText: "No, Cancel", }); } else { var product_ids = response; swal({ title: 'Thank you for showing interest. Unfortunately, some products cannot be purchase using Installment. Please click "Ok" in order to remove those product from the cart, and click "Full Payment" to purchase by Fullpayment.', type: "warning", showCancelButton: true, confirmButtonText: "Ok, Remove", cancelButtonText: "Full Payment", }, function(isConfirm) { if (isConfirm) { $.ajax({ type: "POST", url: baseUrl + "/shoppingcart/removeWithoutInstallmentItem", cache: false, data: "product_ids=" + product_ids + "&totalNoOfPayments=" + total_no_of_payments, success: function(response) { if (response == "true") { window.location = "checkout"; showInstallment(); } }, }); return false; } else { hideInstallmentAccord(); showFullPayment(); } }); } } }, }); } else { setTimeout(function() { $(".loader").removeClass("show"); $(".loader").addClass("hide"); }, 1000); hideInstallmentAccord(); e.preventDefault(); e.stopImmediatePropagation(); } }); $("document").ready(function() { var nonUI = false; $("#checkbox1-77").click(function(e) { if ($(this).is(":checked")) { var shipping_emailid = $("#shipping_emailid").val(); if (shipping_emailid != undefined && shipping_emailid != "") { checkExistRegister(shipping_emailid); } } else { if ($("#shipping_emailid") != undefined && $("#shipping_emailid").val() != "") { $("#frmcheckout").data('bootstrapValidator').revalidateField('form[shipping_emailid]'); } var checked = nonUI ? !this.checked : this.checked; } }); setTimeout(function() { if ($("#shoppingcart_page").size() > 0 || $("#frmcheckout").size() > 0) { if (PaymentType == "installment") { nonUI = true; $("#checkbox1-77").trigger("click"); if ($("#installment_anchar").hasClass("collapsed")) { $("#installment_anchar").removeClass("collapsed"); $("#installment_anchar").attr("aria-expanded", "true"); } if (!$("#installment_payment").hasClass("in")) { $("#installment_payment").addClass("in"); $("#installment_payment").collapse("show"); } $("#frmcheckout").data("bootstrapValidator").revalidateField("form[password]"); $("#frmcheckout").data("bootstrapValidator").revalidateField("form[confirm_password]"); } } }, 20); $("#instorepickup_popup").click(function(){ if($(this).is(':checked')) { $("input[data-shipping-slug=instorepickup]").prop('checked', true); } $("#popUpShipping").modal('hide'); }); }); function billingsameasshipping() { var baseUrl = getBaseUrl(); showLoader(); var form_ship_data = "&ship_first_name=" + $("#shipping_firstName").val() + "&ship_middle_name=" + $("#shipping_middleName").val() + "&ship_last_name=" + $("#shipping_lastName").val() + "&ship_company_name=" + $("#shipping_companyName").val() + "&ship_address1=" + $("#form_shipping_address1").val() + "&ship_address2=" + $("#form_shipping_address2").val() + "&ship_email=" + $("#shipping_emailid").val() + "&ship_phone=" + $("#shipping_contact").val() + "&ship_fax=" + $("#shipping_fax").val() + "&ship_country=" + $("#shipping_countryId").val() + "&ship_state=" + $("#form_shipping_stateId").val() + "&ship_city=" + $("#formShippingCity").val() + "&ship_zip=" + $("#form_shipping_zipcode").val() + "&sales_person=" + $("#form_salesPerson").val(); $.ajax({ type: "POST", cache: true, url: baseUrl + "/billingsameasshipping", data: form_ship_data, success: function(result) { $(".loader").removeClass("hide"); $(".loader").addClass("show"); setTimeout(function() { location.reload(true); }, 2000); return true; }, error: function(jqXHR, textStatus, errorThrown) { return false; }, }); } var selectedmethod = []; var selectedVal = ''; $('.show_shipping_charge').each(function() { selectedVal = (this.checked ? $(this).data('shipping-slug') : ""); if (selectedVal != '') { selectedmethod.push(selectedVal); } }); if (selectedmethod.length == 0 && $('#selected_shipping_method_slug').val() != '') { $('.show_shipping_charge[data-shipping-slug="' + $('#selected_shipping_method_slug').val() + '"]').attr('checked', true); } function number_format(number, decimals, dec_point, thousands_sep) { number = (number + '').replace(/[^0-9+\-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function(n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } function ShipInfoUpdate(){ var btn_calc = $(this).attr("data-value"); var formData = $("#shippingcalculationfrm").serialize(); getShippingCharge(formData, btn_calc); } function addWorkingDays(currentDate, leadWorkingDays) { // Create a copy of the current date var resultDate = new Date(currentDate); // Loop through each day until leadWorkingDays are added for (var i = 0; i < leadWorkingDays; i++) { // Add one day to the current date resultDate.setDate(resultDate.getDate() + 1); // Check if the result date is a weekend (Saturday or Sunday) // If it is, add an extra day until it's not a weekend while (resultDate.getDay() === 0 || resultDate.getDay() === 6) { resultDate.setDate(resultDate.getDate() + 1); } } return resultDate; }