1// 2function allow_numeric(a) { 3 /^\d+(\.\d*)?$/.test(a.value) || (a.value = theVal = a.value.replace(/[^0-9.]/g, ""), theVal > "" && (a.value = parseFloat("0" + theVal), a.focus())); 4} 5var en = { 6 SoldOut: window.Store.TemplateConfig.sold_out_button_text, 7 AddToCart: 'Add To Cart', 8 Save: 'Saved.', 9 MadeToOrder: 'Made To Order', 10 BuyNow: 'Buy Now', 11 AddToCartListButton: '<span>Add To Cart</span> <i class="ico-cart"><svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><circle cx="9" cy="21" r="1"></circle><circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg></i>', 12 MaxOrderQuantityTxt: 'Maximum order quantity must be' 13}; 14 15var de = { 16 SoldOut: 'Momentan nicht verfügbar', 17 AddToCart: 'In den Warenkorb legen', 18 Save: 'Gespeichert.', 19 MadeToOrder: 'Auf Bestellung gefertigt', 20 BuyNow: 'Jetzt kaufen', 21 AddToCartListButton: '<span>In den Warenkorb legen</span> <i class="ico-cart"><svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><circle cx="9" cy="21" r="1"></circle><circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg></i>', 22 MaxOrderQuantityTxt: 'Die maximale Bestellmenge beträgt' 23};
24var Theme = Theme || {}; 25Theme.Data = Theme.Data || {}; 26Theme.Utils = Theme.Utils || {}; 27Theme.ProductData = Theme.ProductData || {}; 28 29 30//Theme Language (Multi Language) 31Theme.Language = Theme.Language || {}; 32Theme.Language.defaultLanguage = (typeof window.BRAND_STORE_LANGUAGE !== 'undefined') ? window.BRAND_STORE_LANGUAGE : "en"; // default language 33Theme.Language.supportedLanguages = ['en', 'fr', 'es']; 34// 2ï¸â£ Language dictionaries 35Theme.Language.dictionary = { 36 en: { 37 SoldOut: window.Store.TemplateConfig.sold_out_button_text, 38 AddToCart: 'Add To Cart', 39 Save: 'Saved.', 40 MadeToOrder: 'Made To Order', 41 BuyNow: 'Buy Now', 42 AddToCartListButton: '<span>Add To Cart</span> <i class="ico-cart"><svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><circle cx="9" cy="21" r="1"></circle><circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg></i>', 43 MaxOrderQuantityTxt: 'Maximum order quantity must be ', 44 PlaceHolderMobileNoTxt: 'Enter your mobile', 45 PlaceHolderEmailTxt: 'Enter your email', 46 LabelEmail: 'Email', 47 LabelMobile: 'Mobile No.', 48 LabelWhatsappMobile: 'Whatsapp Mobile No.', 49 }, 50 de: { 51 SoldOut: 'Momentan nicht verfügbar', 52 AddToCart: 'In den Warenkorb legen', 53 Save: 'Gespeichert.', 54 MadeToOrder: 'Auf Bestellung gefertigt', 55 BuyNow: 'Jetzt kaufen', 56 AddToCartListButton: '<span>In den Warenkorb legen</span> <i class="ico-cart"><svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><circle cx="9" cy="21" r="1"></circle><circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg></i>', 57 MaxOrderQuantityTxt: 'Die maximale Bestellmenge muss betragen ', 58 PlaceHolderMobileNoTxt: 'Geben Sie Ihr Mobiltelefon ein', 59 PlaceHolderEmailTxt: 'Geben Sie Ihre E-Mail-Adresse ein', 60 LabelEmail: 'E-Mail', 61 LabelMobile: 'Mobil-Nr.', 62 LabelWhatsappMobile: 'WhatsApp-Mobilnummer.', 63 } 64}; 65 66// 3ï¸â£ Translator functions 67Theme.Language.currentLanguage = Theme.Language.defaultLanguage; 68 69// Set active language 70Theme.Language.setStr = function(lang) { 71 if (Theme.Language.supportedLanguages.includes(lang)) { 72 Theme.Language.currentLanguage = lang; 73 } else { 74 //console.warn('Unsupported language:', lang); 75 Theme.Language.currentLanguage = Theme.Language.defaultLanguage; 76 } 77}; 78 79// Get translated string 80Theme.Language.getStr = function(key, fallback) { 81 const lang = Theme.Language.currentLanguage; 82 const dict = Theme.Language.dictionary; 83 84 // Try current language â fallback â default â key 85 return ((dict[lang] && dict[lang][key]) || (dict[Theme.Language.defaultLanguage] && dict[Theme.Language.defaultLanguage][key]) || fallback || key); 86}; 87 88Theme.Language.ParseLanguage = function(lang) { 89 var __construct = function() { 90 if (eval('typeof ' + lang) == 'undefined') { 91 lang = "en"; 92 } 93 return; 94 }(); 95 96 this.getStr = function(str, defaultStr) { 97 var retStr = eval('eval(lang).' + str); 98 if (typeof retStr != 'undefined') { 99 return retStr; 100 } else { 101 if (typeof defaultStr != 'undefined') { 102 return defaultStr; 103 } else { 104 return eval('en.' + str); 105 } 106 } 107 } 108} 109 110// Theme.Utils.PhoneCountryCode = function(selectors, countryISO2) { 111// if($("#"+selectors).val() != undefined && window.intlTelInput) { 112// return window.intlTelInput(document.querySelector("#"+selectors), { 113// utilsScript: "/css/assets/plugins/intl-tel-input/js/utils.js", 114// initialCountry: countryISO2,
115// //autoInsertDialCode: true, 116// nationalMode: true, 117// //showSelectedDialCode: true, 118// //separateDialCode: true, 119// //formatOnDisplay: false, 120// //strictMode: true, 121// // hiddenInput: function(telInputName) { 122// // // Return a string or an object with 'phone' and 'country' keys 123// // return "payment_phone_with_country_code"; // or { phone: "phone_full", country: "country_code" } 124// // } 125// }); 126// } 127// } 128Theme.Utils.PhoneCountryCode = function(selectors, countryISO2) { 129 if($("#"+selectors).val() != undefined && window.intlTelInput) { 130 return window.intlTelInput(document.querySelector("#"+selectors), { 131 utilsScript: "/css/assets/plugins/intl-tel-input/js/utils.js", 132 initialCountry: countryISO2, 133 //autoInsertDialCode: true, 134 nationalMode: true, 135 //showSelectedDialCode: true, 136 separateDialCode: true, 137 formatOnDisplay: false, 138 strictMode: true, 139 // hiddenInput: function(telInputName) { 140 // // Return a string or an object with 'phone' and 'country' keys 141 // return "payment_phone_with_country_code"; // or { phone: "phone_full", country: "country_code" } 142 // } 143 }); 144 } 145} 146 147Theme.Utils.Element = { 148 init: function() { 149 /****** Condition For Date Picker ******/ 150 var d = new Date(); 151 d.setFullYear(d.getFullYear() - 60); 152 153 if ($('input').hasClass('datepick')) { 154 $('.datepick').datepicker({ 155 format: 'dd-MM-yyyy', 156 startView: 2, 157 todayHighlight: true, 158 }); 159 160 $('.date_image_button').click(function() { 161 $(this).closest('div.input-group').find(".datepick").datepicker('show'); //support hide,show and destroy command 162 }); 163 } 164 165 /****** Condition For Date Picker ******/ 166 if ($('div').hasClass('clockpicker')) { 167 $('.clockpicker').clockpicker(); 168 } 169 170 if ($('input').hasClass('timepicki')) { 171 $('.timepicki').timepicki(); 172 } 173 }, 174 giftDeliveryDate: function() { 175 var a = new Date; 176 a.setFullYear(a.getFullYear() - 60), $("input").hasClass("gift_datepick") && ($(".gift_datepick").datepicker({ 177 format: "dd-MM-yyyy", 178 minDate: "0D", 179 maxDate: "+90D", 180 startView: 2, 181 todayHighlight: !0 182 }), $(".date_image_button").click(function() { 183 $(this).closest("div.input-group").find(".datepick").datepicker("show") 184 })) 185 }, 186 validateRecipientForm: function() { 187 $(".readonlydate").keydown(function(a) { 188 a.preventDefault() 189 }), $(".formstyle-hold .float-label input").bind("input propertychange", function(a) { 190 "" !== $(a.target).val() ? $(a.target).parent().find("label").addClass("header-label") : $(a.target).parent().find("label").removeClass("header-label") 191 }), $(".formstyle-hold .float-label textarea").bind("input propertychange", function(a) { 192 "" !== $(a.target).val() ? $(a.target).parent().find("label").addClass("header-label") : $(a.target).parent().find("label").removeClass("header-label") 193 }), $("#StoreCartIndexForm").validate({ 194 ignore: [] 195 }) 196 }, 197 validateTopBottomForm: function() { 198 $(".formstyle-hold .text-left input").bind("input propertychange", function(a) { 199 "" !== $(a.target).val() ? $(a.target).parent().find("label").addClass("header-label") : $(a.target).parent().find("label").removeClass("header-label") 200 }), $(".formstyle-hold .text-left textarea").bind("input propertychange", function(a) { 201 "" !== $(a.target).val() ? $(a.target).parent().find("label").addClass("header-label") : $(a.target).parent().find("label").removeClass("header-label") 202 }), $("#StoreCartIndexForm").validate() 203 }, 204 validateEmail(email) { 205 const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 206 return regex.test(email); 207 }, 208 validateNumeric(str) { 209 return /^[0-9]+$/.test(str); 210 } 211}, 212 213 Theme.Utils.Home = { 214 init: function() { 215 Theme.Utils.Cookie.initCookieMessage(); 216 var a = $("div.cd-cart-trigger"), 217 b = $("#cd-cart"), 218 c = $("#cd-shadow-layer"); 219 a.on("click", function(a) { 220 a.preventDefault(), Theme.Utils.Home.toggglePanelVisibility(b, c, $("body")) 221 }), c.on("click", function() { 222 c.removeClass("is-visible"), b.hasClass("speed-in") ? b.removeClass("speed-in").on("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() { 223 $("body").removeClass("overflow-hidden panel-cart-icon") 224 }) : b.removeClass("speed-in") 225 }) 226 Theme.Utils.Home.cartMultiVariantRemove(); 227 228 //Shipping Zone Wise City Location 229 let store_shipping_zone_city_name = $("form#formCityLocation").find("input#store_shipping_zone_city_name").val(); 230 if(store_shipping_zone_city_name != '') { 231 localStorage.setItem('store_shipping_zone_city_name', store_shipping_zone_city_name); 232 } else { 233 localStorage.removeItem("store_shipping_zone_city_name"); 234 } 235 236 if(localStorage.getItem('store_shipping_zone_city_name') === null) { 237 $('div#geoLocationModal').modal('show'); 238 } 239 240 //In Housing Shipping Postal Code 241 let store_inhouse_shipping_pincode = $("form#formCityLocation").find("input#store_inhouse_shipping_pincode").val(); 242 if(store_inhouse_shipping_pincode != '') { 243 localStorage.setItem('store_inhouse_shipping_pincode', store_inhouse_shipping_pincode); 244 } else { 245 localStorage.removeItem("store_inhouse_shipping_pincode"); 246 } 247 248 if(localStorage.getItem('store_inhouse_shipping_pincode')
248=== null) { 249 $('div#geoLocationModal').modal('show'); 250 } 251 252 if(typeof $("input#citylocation") !== 'undefined') { 253 $("input#citylocation").autocomplete({ 254 source: function(a, b) { 255 var c = a.term; 256 $.ajax({ 257 type: "POST", 258 async: !0, 259 cache: !1, 260 url: "/stores/getZoneWiseCity", 261 dataType: "json", 262 data: { 263 "search": c 264 }, 265 beforeSend: function() {}, 266 success: function(a) { 267 b($.map(a, function(item) { 268 return { 269 label: item.name, 270 value: item.id 271 } 272 })) 273 }, 274 error: function(a) { 275 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 276 } 277 }) 278 }, 279 select: function(a, b) { 280 $("input#citylocation").val(b.item.label); 281 $("form#formCityLocation").submit(); 282 a.preventDefault(); 283 }, 284 focus: function(a, b) { 285 a.preventDefault(), $("input#citylocation").val(b.item.label) 286 } 287 }); 288 } 289 290 //View Form Answer Details 291 $(document).on("click", ".view-form-details", function() { 292 var order_id = $(this).data('orderId'); 293 var order_product_id = $(this).data('orderProductId'); 294 var form_answer_id = $(this).data('formAnswerId'); 295 296 var FormData = "data[StoreOrderProduct][order_id]="+ order_id +"&data[StoreOrderProduct][order_product_id]="+ order_product_id +"&data[StoreOrderProduct][form_answer_id]="+ form_answer_id ; 297 $.ajax({
298 type: "POST", 299 async: true, 300 cache: false, 301 url: "/store_order_products/getProductFormAnswerDetails", 302 dataType: "html", 303 data: FormData, 304 beforeSend: function(XMLHttpRequest) { 305 //$("button .verify-otp-code").addClass("disabled").attr("disabled", "disabled"); 306 }, 307 complete: function() { 308 //$("button .verify-otp-code").removeClass("disabled").removeAttr("disabled"); 309 }, 310 success: function(data, textStatus) { 311 $('div#div_form_details').html(data); 312 // Open the modal 313 $('div#formDetailsModal').modal('show'); 314 }, 315 error: function(jqXHR, textStatus, errorThrown) { 316 if (jqXHR.status == 500) { 317 alert('Internal error: ' + jqXHR.responseText); 318 } 319 } 320 }); 321 }); 322 }, 323 cartMultiVariantRemove: function() { 324 $(document).on("click", ".cart-multi-variant-remove", function() { 325 var ele = $(this); 326 var product_id = $(this).data('productid'); 327 var product_variantid = $(this).data('productvariantid'); 328 var total_price = $(this).data('totalprice'); 329 var currency_symbol = $(this).data('currency'); 330 331 if(Math.round(product_id) > 0) { 332 var FormData = "data[StoreCart][product_id]=" + product_id + "&data[StoreCart][product_variant_id]=" + product_variantid; 333 $.ajax({
334 type: "POST", 335 async: !0, 336 cache: !1, 337 url: "/store_carts/remove_multi_variant", 338 dataType: "html", 339 data: FormData, 340 beforeSend: function() {}, 341 success: function(a) { 342 a = a.replace(/\s+/g,''); 343 if(a == "success") { 344 ele.remove(); 345 $("#elem_"+product_id).remove(); 346 347 var sub_total = $("#sub_total").val(); 348 sub_total = (parseFloat(sub_total) - parseFloat(total_price)).toFixed(2); 349 $("#sub_total").val(sub_total); 350 351 var currency_symbol_str = $("#currency_symbol").val(); 352 currency_symbol_str = currency_symbol_str.replace(/[0-9.]/g, ''); 353 354 $("#spnTotal").html(currency_symbol_str + ' ' + sub_total); 355 $("#div-drop-cart span.rounded-circle").html(Math.round($("#div-drop-cart span.rounded-circle").html())-1); 356 } else if (a == "empty") { 357 var empty_str = ' <h4 class="text-center text-muted">Cart</h4><div class="col-12 shopping-empty-state ng-scope clearfix"><div class="cart-empty mb-3 mt-2"><div class="text-center"><svg class="bi bi-circle-slash mb-2" width="2em" height="2em" viewBox="0 0 20 20" fill="#ccc" xmlns="https://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10 1.5a8.5 8.5 0 100 17 8.5 8.5 0 000-17zM5.071 4.347a7.5 7.5 0 0110.582 10.582L5.071 4.347zm-.724.724a7.5 7.5 0 0010.582 10.582L4.347 5.071z" clip-rule="evenodd"></path></svg><br>Your shopping cart is empty.</div></div></div>'; 358 $("#targetDiv").html(empty_str); 359 $("#div-drop-cart span.rounded-circle").html('0'); 360 } 361 }, 362 error: function(a) { 363 alert(500 == a.status ? "Internal error: " + a.responseText : "Unexpected error.") 364 } 365 }); 366 } 367 }); 368 }, 369 preventLoginRedirection: function() { 370 /* 371 $(document).on('click', '.top-login-dtp a', function(event){ 372 event.preventDefault(); 373 Theme.Utils.Home.ShowLoginPopup(); 374 //, form#frm_login_modal, form#frm_signup_modal 375 }); 376 */ 377 $(document).on('click', '.btn_login_popup', function(event){ 378 event.preventDefault(); 379 380 $a = $(this); 381 if($a.hasClass('disabled')) { 382 return false; 383 } 384 $a.addClass('disabled'); 385 386 var loginModal = new bootstrap.Modal(document.getElementById('loginModal'), { 387 keyboard: false 388 }); 389 390 $.ajax({
391 type: "POST", 392 async: !0, 393 cache: !1, 394 url: "/customers/ajax_login_register_forgot_password_popup", 395 dataType: "html", 396 data: {}, 397 beforeSend: function() {}, 398 success: function(responseHtml) { 399 //alert(responseHtml); 400 $('#loginModal').find('.modal-body').html(responseHtml); 401 loginModal.toggle(); 402 }, 403 error: function(a) { 404 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 405 } 406 }).done(function(result){ 407 $a.removeClass('disabled'); 408 }); 409 }); 410 411 $(document).on('click', '.btn_forgot_password', function(event){ 412 event.preventDefault(); 413 $("div#modal-login").fadeOut('slow').addClass("d-none"); 414 $("div#modal-signup").fadeOut('slow').addClass("d-none"); 415 $("div#modal-forgot-password").fadeIn('slow').removeClass("d-none"); 416 $("h4#lbl_modal_title").text("Forgot Password"); 417 }); 418 419 $(document).on('click', '.btn_login_back', function(event) { 420 event.preventDefault(); 421 $("div#modal-forgot-password").fadeOut('slow').addClass("d-none"); 422 $("div#modal-signup").fadeOut('slow').addClass("d-none"); 423 $("div#modal-login").fadeIn('slow').removeClass("d-none"); 424 $("h4#lbl_modal_title").text("Login"); 425 }); 426 427 $(document).on('click', '.btn_signup_modal', function(event) { 428 event.preventDefault(); 429 $("div#modal-forgot-password").fadeOut('slow').addClass("d-none"); 430 $("div#modal-login").fadeOut('slow').addClass("d-none"); 431 $("div#modal-signup").fadeIn('slow').removeClass("d-none"); 432 $("h4#lbl_modal_title").text("Register"); 433 }); 434 435 $(document).on('click', '.loginwithpass', function(event) { 436 event.preventDefault(); 437 $("div#loginwithemail").fadeOut('slow').addClass("d-none"); 438 $("div#otpCountainer").fadeOut('slow').addClass("d-none"); 439 $("div#loginwithpass").fadeIn('slow').removeClass("d-none"); 440 }); 441 442 $(document).on('click', '.loginwithemail', function(event) { 443 event.preventDefault(); 444 $("div#loginwithpass").fadeOut('slow').addClass("d-none"); 445 $("div#loginwithemail").fadeIn('slow').removeClass("d-none"); 446 $("div#otpCountainer").fadeOut('slow').addClass("d-none"); 447 }); 448 }, 449 initLoginPopup: function() { 450 if(window.defaultValues !== undefined) { 451 window.phone_intlTel = Theme.Utils.PhoneCountryCode('phone', defaultValues.PhoneISO2); 452 } 453 if($(".show-password").length > 0) { 454 $(document).on("click", ".show-password", function () { 455 if ($(this).hasClass('bi bi-eye')) { 456 $(this).closest("div").find("input").attr('type', 'text'); 457 $(this).removeClass('bi bi-eye').addClass('bi bi-eye-slash'); 458 } else { 459 $(this).closest("div").find("input").attr('type', 'password'); 460 $(this).removeClass('bi bi-eye-slash').addClass('bi bi-eye'); 461 } 462 }); 463 } 464 }, 465 validateLoginPopup: function() { 466 $("form#frm_forgot_password_modal").validate({ 467 submitHandler: function(form) { 468 var forgot_email = $(form).find("input#forgot_email").val(); 469 forgot_email = forgot_email.replace(/\s+/g,''); 470 if(forgot_email.length > 0) { 471 $("button#btn_forgot_password_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 472 473 if(window.googleRecaptchaSiteKey !== 'undefined') { 474 grecaptcha.ready(function () { 475 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'forgot_password'}).then(function (token) { 476 $(form).find('input#recaptcha_response_forgot_password').val(token); 477 }); 478 }); 479 } 480 481 setTimeout(function () { 482 var recaptcha_response = $(form).find("input#recaptcha_response_forgot_password").val(); 483 var z = "forgotemail=" + forgot_email + "&recaptcha_response=" + recaptcha_response; 484 $.ajax({
485 type: "POST", 486 async: !0, 487 cache: !1, 488 url: "/customers/ajax_forgot_password", 489 dataType: "html", 490 data: z, 491 beforeSend: function() { 492 //$("button#btn_forgot_password_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 493 }, 494 success: function(a) { 495 var response_array = a.split("-"); 496 var response_type = response_array[0]; 497 response_type = response_type.replace(/\s+/g,''); 498 $("#modalsuccessmsg").html(''); 499 $("#modalerrormsg").html(''); 500 501 if(response_type == "Success") { 502 $("#modalsuccessmsg").removeClass("d-none"); 503 $("#modalerrormsg").addClass("d-none"); 504 $("#modalsuccessmsg").html(response_array[1]); 505 } else if(response_type == "Error") { 506 $("#modalsuccessmsg").addClass("d-none"); 507 $("#modalerrormsg").removeClass("d-none"); 508 $("#modalerrormsg").html(response_array[1]); 509 } 510 }, 511 error: function(a) { 512 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 513 }, 514 complete: function () { 515 $("button#btn_forgot_password_submit").removeAttr("disabled").find("span.spinner").addClass("d-none"); 516 } 517 }); 518 }, 2000); 519 } 520 return false; 521 } 522 }); 523 524 $("form#frm_login_modal").validate({ 525 submitHandler: function(form) { 526 $("button#btn_login_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 527 528 setTimeout(function () { 529 if(typeof window.googleRecaptchaSiteKey !== 'undefined') { 530 grecaptcha.ready(function () { 531 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'login'}).then(function (token) { 532 $(form).find('input#recaptcha_response_login').val(token); 533 }); 534 }); 535 } 536 }, 1000); 537 538 setTimeout(function () { 539 var formLoginData = $(form).serialize(); 540 $.ajax({
541 type: "POST", 542 async: !0, 543 cache: !1, 544 url: "/customers/ajax_login", 545 dataType: "json", 546 data: formLoginData, 547 beforeSend: function() { 548 //$("button#btn_login_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 549 $("div#login_success").addClass("d-none"); 550 $("div#login_error").addClass("d-none"); 551 }, 552 success: function(responseData) { 553 if(parseInt(responseData.login_status) == 1) { 554 $("div#login_success").removeClass("d-none"); 555 $("span#login_success_message").html(responseData.message); 556 if(typeof window.dataLayer != 'undefined') { 557 dataLayer.push({ customer: null }); 558 dataLayer.push({ 559 "event": "login", 560 'customer': { 561 "email": $(form).find("input#email").val().trim() 562 } 563 }); 564 } 565 setTimeout(function(){ 566 window.location.reload(); 567 }, 1000); 568 } else if(parseInt(responseData.login_status) == 0) { 569 $("div#login_error").removeClass("d-none"); 570 $("span#login_error_message").html(responseData.message); 571 } 572 }, 573 error: function(a) { 574 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 575 }, 576 complete: function () { 577 $("button#btn_login_submit").removeAttr("disabled").find("span.spinner").addClass("d-none"); 578 } 579 }); 580 }, 2000); 581 582 return false; 583 } 584 }); 585 586 $("form#frm_signup_modal").validate({ 587 errorPlacement: function(error, element) { 588 if (element.parent('.checkbox').length) { 589 error.insertAfter(element.parent()); 590 } else { 591 error.insertAfter(element); 592 } 593 }, 594 submitHandler: function(form) { 595 $("button#btn_register_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 596 597 if(window.phone_intlTel !== undefined && $("input[name='data[Customer][phone_isd_code]'").length > 0) { 598 let phone_isd_code = window.phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 599 $("input[name='data[Customer][phone_isd_code]'").val(phone_isd_code); 600 } 601 602 if(window.phone_intlTel !== undefined && $("input[name='data[Customer][phone_iso2_code]'").length > 0) { 603 let phone_iso2_code = window.phone_intlTel.getSelectedCountryData().iso2; 604 $("input[name='data[Customer][phone_iso2_code]'").val(phone_iso2_code.toUpperCase()); 605 } 606 607 if(window.googleRecaptchaSiteKey !== 'undefined') { 608 grecaptcha.ready(function () { 609 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'register'}).then(function (token) { 610 $(form).find('input#recaptcha_response_register').val(token); 611 }); 612 }); 613 } 614 615 setTimeout(function () { 616 var formRegisterData = $(form).serialize(); 617 form.submit(); 618 }, 2000); 619 620 return false; 621 } 622 }); 623 }, 624 ShowLoginPopup: function() { 625 /* 626 $('.modal').on('hidden.bs.modal', function(){ 627 $(".btn_login_back").trigger('click'); 628 $(this).removeData('bs.modal'); 629 }); 630 */ 631 }, 632 toggglePanelVisibility: function(a, b, c) { 633 a.hasClass("speed-in") ? (a.removeClass("speed-in").one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() { 634 c.removeClass("overflow-hidden panel-cart-icon") 635 }), b.removeClass("is-visible")) : (a.addClass("speed-in").one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() { 636 c.addClass("overflow-hidden panel-cart-icon") 637 }), b.addClass("is-visible")) 638 }, 639 initVideo: function() {}, 640 getServiceableAreas: function(store_address_city_id) { 641 $.ajax({
642 type: "POST", 643 async: true, 644 cache: false, 645 url: "/store_addresses/getServiceableAreas", 646 dataType: "html", 647 data: { 648 "data[StoreAddresse][city_id]": store_address_city_id 649 }, 650 beforeSend: function(XMLHttpRequest) { 651 $("select#serviceable_area_id").find("option").not(':first').remove(); 652 }, 653 success: function(data, textStatus) { 654 $("select#serviceable_area_id").append(data); 655 }, 656 error: function(jqXHR, textStatus, errorThrown) { 657 if (jqXHR.status == 500) { 658 alert('Internal error: ' + jqXHR.responseText); 659 } 660 } 661 }); 662 }, 663 changeServiceableCity: function() { 664 if($("select#store_address_city_id").length > 0) { 665 $("select#store_address_city_id").on("change", function(event) { 666 $("option:selected", $(this)).each(function() { 667 let store_address_city_id = $(this).val(); 668 if($("select#store_address_city_id").length > 0) { 669 Theme.Utils.Home.getServiceableAreas(store_address_city_id); 670 return false; 671 } 672 }); 673 }); 674 675 if(sessionStorage.getItem('serviceable_area_id') === null) { 676 $('div#locationSelectPopup').modal('show'); 677 } 678 } 679 680 if($("a.store_address_active").length > 0) { 681 $("a.store_address_active").on("click", function(event) { 682 event.preventDefault(); 683 let store_address_id = $(this).data('storeAddressId'); 684 localStorage.setItem('store_address_id', store_address_id); 685 $(this).closest("form").find("input#store_address_id").val(store_address_id); 686 $(this).closest("form").submit(); 687 }); 688 689 if(localStorage.getItem('store_address_id') === null) { 690 $('div#locationSelectPopup').modal('show'); 691 } 692 } 693 }, 694 }, 695 Theme.Utils.Form = { 696 initFormElement: function() { 697 $('[data-toggle="tooltip"]').tooltip(), $("input, textarea, select").focus(function() { 698 $(this).closest(".field").addClass("field--active") 699 }).blur(function() { 700 $(this).closest(".field").removeClass("field--active") 701 }).on("keyup paste change focus blur keydown", function() { 702 0 != $(this).val().length ? $(this).closest(".field").addClass("field--show-floating-label") : $(this).closest(".field").removeClass("field--show-floating-label") 703 }).each(function() { 704 0 != $(this).val().length ? $(this).closest(".field").addClass("field--show-floating-label") : $(this).closest(".field").removeClass("field--show-floating-label") 705 }) 706 } 707 }, 708 Theme.Utils.Cookie = { 709 initCookieMessage: function() { 710 if ($("div.cookie-message").length > 0) { 711 var a = window.sessionStorage.cookieMessage ? JSON.parse(window.sessionStorage.cookieMessage) : void 0; 712 a && a.hide ? $("div.cookie-message").hide() : ($("div.cookie-message").show(), this.showCookieMessage()) 713 } 714 }, 715 showCookieMessage: function() { 716 $("div.cookie-message").find("button").on("click", function() { 717 window.sessionStorage.cookieMessage = JSON.stringify({ 718 hide: !0 719 }), $(this).css("height", $(this).css("height")), $(this).children().animate({ 720 opacity: 0 721 }, 100), $(this).animate({ 722 height: 0, 723 padding: 0 724 }, 100, "swing", function() { 725 $(this).hide() 726 }) 727 }) 728 }, 729 hideCookieMessage: function() { 730 $("div.cookie-message").hide() 731 } 732 }, 733 Theme.Utils.Search = { 734 init: function() { 735 var a = $("#searchtoggl i"), 736 b = $("#searchbar"); 737 $(".scroll-search a").on("click", function(c) { 738 c.preventDefault(), "searchtoggl" == $(this).attr("id") && (b.is(":visible") ? a.removeClass("fa-times").addClass("fa-search") : a.removeClass("fa-search").addClass("fa-times"), b.slideToggle(300, function() {})) 739 }), $("#searchform").submit(function(a) { 740 a.preventDefault() 741 }); 742 743 if(typeof $("input#keyword") !== 'undefined') { 744 $("input#keyword").autocomplete({ 745 source: function(a, b) { 746 var c = a.term; 747 $.ajax({
748 type: "POST", 749 async: !0, 750 cache: !1, 751 url: "/store_tags/getTagsByKeyword", 752 dataType: "json", 753 data: { 754 "data[StoreProduct][keyword]": c 755 }, 756 beforeSend: function() {}, 757 success: function(a) { 758 b($.map(a, function(a) { 759 return { 760 label: a.tag_name, 761 value: a.slug_url 762 } 763 })) 764 }, 765 error: function(a) { 766 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 767 } 768 }) 769 }, 770 select: function(a, b) { 771 window.location.href = window.storeURL + b.item.value, b.item.value = b.item.label, this.value = b.item.label, a.preventDefault() 772 }, 773 focus: function(a, b) { 774 a.preventDefault(), $("input#keyword").val(b.item.label) 775 } 776 }); 777 } 778 } 779 }, 780 Theme.Utils.BackToTop = { 781 init: function() { 782 $("#back-top").hide(), $(window).scroll(function() { 783 $(this).scrollTop() > 100 ? $("#back-top").fadeIn() : $("#back-top").fadeOut() 784 }), $("#back-top a").click(function() { 785 return $("body,html").animate({ 786 scrollTop: 0 787 }, 400), !1 788 }) 789 } 790 }, 791 Theme.Utils.PopUp = { 792 init: function(a) { 793 var homepagePopupModal = new bootstrap.Modal( 794 document.getElementById('homepagePopupModal'), { 795 keyboard: false 796 }); 797 798 if(typeof a !== "undefined" && parseInt(sessionStorage.getItem("popHome")) != 1) { 799 $(window).on('load', function(){ 800 window.setTimeout(function() { 801 if($("div#exitpopup-modal").length > 0 && $("div#exitpopup-modal").is(":visible")) { 802 $("div#exitpopup-modal").hide(); 803 } 804 805 homepagePopupModal.toggle(); 806 }, 1e3 * parseInt(a)); 807 }); 808 } 809 }, 810 hidePopUp: function() { 811 $("button#btnCloseModal").on("click", function() { 812 $.ajax({
813 type: "POST", 814 async: !0, 815 cache: !1, 816 url: "/stores/hide_popup", 817 dataType: "html", 818 data: { 819 "data[Store][hide_popup]": 1 820 }, 821 beforeSend: function() {}, 822 success: function() {}, 823 error: function(a) { 824 500 == a.status && alert("Internal error: " + a.responseText) 825 } 826 }) 827 }) 828 } 829 }, 830 Theme.Utils.ExitPopUp = { 831 init: function() { 832 $("html").on("mouseout.ouibounce", (function () { 833 function e() { 834 $("#exitPopupModal").modal(); 835 } 836 return function (t) { 837 if (!(t.clientY < 20)) return; 838 e(); 839 $("html").off("mouseout.ouibounce"); 840 }; 841 })() 842 ); 843 } 844 }, 845 Theme.Utils.CountDown = { 846 init: function(a) { 847 $(".countdown").downCount({ 848 date: a, 849 offset: 5 850 }) 851 } 852 }, 853 Theme.Utils.Menu = { 854 init: function() {}, 855 initNavMenu: function() { 856 var html = $('html, body'), 857 navContainer = $('.nav-container'), 858 navToggle = $('.nav-toggle'), 859 navDropdownToggle = $('.has-dropdown'); 860 861 // Nav toggle 862 /* 863 navToggle.on('click', function(e) { 864 var $this = $(this); 865 e.preventDefault(); 866 $this.toggleClass('is-active'); 867 navContainer.toggleClass('nav-menus-wrapper-open'); 868 html.toggleClass('nav-open'); 869 }); 870 */ 871 872 // Nav dropdown toggle 873 navDropdownToggle.on('click', function() { 874 var $this = $(this); 875 $this.toggleClass('is-active').children('ul').toggleClass('is-visible'); 876 }); 877 878 // Prevent click events from firing on children of navDropdownToggle 879 navDropdownToggle.on('click', '*', function(e) { 880 e.stopPropagation(); 881 }); 882 883 // Create a clone of the menu, right next to original. 884 /* 885 if ($(window).width() >= 767) { 886 if ($('#header').length) { 887 $('#header').addClass('original').clone().insertAfter('#header').addClass('cloned').css('position', 'fixed').css('top', '0').css('margin-top', '-1').css('z-index', '500').removeClass('original').hide(); 888 889 function stickIt() { 890 var orgElementPos = $('.original').offset(); 891 orgElementTop = orgElementPos.top; 892 if ($(window).scrollTop() >= (orgElementTop)) { 893 // scrolled past the original position; now only show the cloned, sticky element. 894 895 // Cloned element should always have same left position and width as original element. 896 orgElement = $('.original'); 897 coordsOrgElement = orgElement.offset(); 898 leftOrgElement = coordsOrgElement.left; 899 widthOrgElement = orgElement.css('width'); 900 $('.cloned').css('left', leftOrgElement + 'px').css('top', 0).css('width', widthOrgElement).show(); 901 $('.original').css('visibility', 'hidden'); 902 } else { 903 // not scrolled past the menu; only show the original menu. 904 $('.cloned').hide(); 905 $('.original').css('visibility', 'visible'); 906 } 907 } 908 scrollIntervalID = setInterval(stickIt, 10); 909 } 910 } 911 */ 912 } 913 }, 914 Theme.Utils.Category = { 915 initSort: function() { 916 $("#sort_by, #sort_by_id").on("change", function(event) { 917 event.preventDefault(); 918 var sort_by = $(this).val(); 919 var page_url = window.location.pathname; 920 if($("input#is_infinite_scroll").length == 0 || $("input#is_infinite_scroll").val() === 0) { 921 window.location.href = window.location.pathname + "?" + sort_by; 922 } else { 923 Theme.Utils.Category.buildQueryString(); 924 } 925 return false; 926 }); 927 }, 928 initFilter: function() { 929 $("input.filter_groups").on("click", function(event) { 930 Theme.Utils.Category.buildQueryString(); 931 }); 932 $("input.filter_options").on("click", function(event) { 933 Theme.Utils.Category.buildQueryString(); 934 }); 935 $("input.filter_tags").on("click", function(event) { 936 Theme.Utils.Category.buildQueryString(); 937 }); 938 }, 939 initColorFilter: function() { 940 $(".color-chk").on("click", function() {
941 if (window.BRAND_STORE_ID === 3491 && $(this).is(":checked")) { 942 $(".color-chk").not(this).prop("checked", false); 943 } 944 Theme.Utils.Category.buildQueryString(); 945 }); 946 }, 947 initSizeFilter: function() { 948 $(".color-size").on("click", function() { 949 Theme.Utils.Category.buildQueryString(); 950 }); 951 952 if($(".m_span").length > 0) { 953 $(".m_span").on("click", function(e) { 954 e.preventDefault(); 955 let click_target = $(this).data('id'); 956 if(document.getElementById(click_target).checked == true) { 957 document.getElementById(click_target).checked = false; 958 } else { 959 document.getElementById(click_target).checked = true; 960 } 961 Theme.Utils.Category.buildQueryString(); 962 }); 963 } 964 }, 965 initStockFilter: function() { 966 $("#item_stock").on("click", function() { 967 Theme.Utils.Category.buildQueryString(); 968 }); 969 }, 970 initPriceRangeFilter: function() { 971 $("input.filter_price_ranges").on("click", function() { 972 Theme.Utils.Category.buildQueryString(); 973 }); 974 975 if(typeof wNumb !== 'undefined') { 976 var moneyFormat = wNumb({ 977 decimals: 0, 978 thousand: ',', 979 prefix: '$("#currencysymbol").val()' 980 }); 981 982 if(rangeSlider !== null) { 983 // Set visual min and max values and also update value hidden form inputs 984 rangeSlider.noUiSlider.on('update', function(values, handle) { 985 $("#slider-range-value1").html(moneyFormat.from(values[0])); 986 $("#slider-range-value2").html(moneyFormat.from(values[1])); 987 $("#pricerange").val(moneyFormat.from(values[0])+"-"+moneyFormat.from(values[1])); 988 }); 989 990 rangeSlider.noUiSlider.on('change', function(values, handle) { 991 Theme.Utils.Category.buildQueryString(); 992 }); 993 994 if($('.price-range').length > 0) { 995 $('.price-range').on('change', function() { 996 let minval = $("input#slider-range-value1").val(); 997 let maxval = $("input#slider-range-value2").val(); 998 $("input#pricerange").val(moneyFormat.from(minval)+"-"+moneyFormat.from(maxval)); 999 rangeSlider.noUiSlider.set([moneyFormat.from(minval), moneyFormat.from(maxval)]); 1000 Theme.Utils.Category.buildQueryString(); 1001 }); 1002 } 1003 } 1004 } 1005 }, 1006 applyFilter: function() { 1007 $("button#btnapply").on("click", function() { 1008 if($(".fl-toggle").length > 0) { 1009 $(".fl-toggle").trigger("click"); 1010 } 1011 }); 1012 $("button#btnclear").on("click", function() { 1013 $(this).closest("div.filter-panel").find('input:checkbox').each(function (index, checkbox) { 1014 checkbox.checked = false; 1015 }); 1016 $(this).fadeOut(); 1017 Theme.Utils.Category.buildQueryString(); 1018 }); 1019 }, 1020 initScroll: function() { 1021 let pageNum = 1; 1022 let isLoading = false; 1023 //const container = document.querySelector(".container"); 1024 const container = document.getElementById("div_product_list"); 1025 //const loadingContainer = document.querySelector(".loading-container"); 1026 //const resultContainer = document.querySelector(".result-container"); 1027 1028 $(window).scroll(function(){ 1029 if (isLoading) return; 1030 // console.log($(document).height()); 1031 // console.log($(window).height()); 1032 // console.log($(window).scrollTop()); 1033 //if ($(window).scrollTop() > $("div#divLoading").offset().top - 500) { 1034 //if ($(window).scrollTop() == $(document).height() - $(window).height()) { 1035 if (parseInt($(window).scrollTop()) >= parseInt($(document).height() * 0.70)) { 1036 //alert($(window).scrollTop() + " " + $("div#divLoading").offset().top); 1037 //Math.ceil(container.clientHeight + container.scrollTop) >= container.scrollHeight) { 1038 //pageNum++; 1039 // alert(Math.ceil(container.clientHeight + container.scrollTop)); 1040 // alert(Math.ceil(container.scrollHeight)); 1041 isLoading = true; 1042 Theme.Utils.Category.buildQueryString(isScrolling = 1); 1043 setTimeout(function () {isLoading = false;}, 2000); 1044 } 1045 }); 1046 }, 1047 buildQueryString: function(isScrolling = 0) { 1048 let checkbox_checked = false;
1049 $("div.filter-panel").find('input:checkbox').each(function (index, checkbox) { 1050 if(checkbox.checked) { 1051 checkbox_checked = true; 1052 } 1053 }); 1054 if(checkbox_checked) { 1055 $("button#btnclear").fadeIn(); 1056 } else { 1057 $("button#btnclear").fadeOut(); 1058 } 1059 1060 var page_url = window.location.pathname + "?"; 1061 1062 //Filter Groups Array 1063 var filterArray = {}; 1064 var excludeFilterKeys = []; 1065 $('input.filter_groups:checkbox:checked').each(function(i, e) { 1066 if ($(this).data('filterKey').length > 0 && $(this).data('filterValue').length == 0) { 1067 filterKey = $(this).data('filterKey'); 1068 excludeFilterKeys.push(filterKey); 1069 $('input.filter_groups[data-filter-key=' + filterKey + ']').not(this).prop('checked', false); 1070 } 1071 1072 if ($(this).data('filterKey').length > 0 && typeof $(this).data('filterValue') !== undefined) { 1073 var key = $(this).data('filterKey'); 1074 var value = $(this).data('filterValue'); 1075 1076 if (excludeFilterKeys.indexOf(key) == -1) { 1077 if (key in filterArray == false) { 1078 filterArray[key] = {}; 1079 filterArray[key][i] = value; 1080 } else { 1081 filterArray[key][i] = value; 1082 } 1083 } 1084 } 1085 }); 1086 1087 for (var key in filterArray) { 1088 values = Object.keys(filterArray[key]).map(function(k) { 1089 return filterArray[key][k] 1090 }).join(","); 1091 page_url = page_url + key + "=" + values + "&"; 1092 } 1093 1094 //Filter Options Array 1095 var filterArray = []; 1096 $('input.filter_options:radio:checked').each(function() { 1097 if ($(this).data('optionKey').length > 0 && $(this).data('optionValue').length > 0) { 1098 var key = $(this).data('optionKey'); 1099 var value = $(this).data('optionValue'); 1100 filterArray["" + key + ""] = value; 1101 } 1102 }); 1103 1104 for (var key in filterArray) { 1105 page_url = page_url + key + "=" + filterArray[key] + "&"; 1106 } 1107 1108 //Filter Tags Array 1109 var filterArray = []; 1110 $('input.filter_tags:radio:checked').each(function() { 1111 if ($(this).data('tagKey').length > 0 && $(this).data('tagValue').length > 0) { 1112 var key = $(this).data('tagKey'); 1113 var value = $(this).data('tagValue'); 1114 filterArray["" + key + ""] = value; 1115 } 1116 }); 1117 1118 for (var key in filterArray) { 1119 page_url = page_url + key + "=" + filterArray[key] + "&"; 1120 } 1121 1122 //Search Keyword 1123 var filterArray = []; 1124 var search_keyword = $("#search_keyword").val(); 1125 if(search_keyword !== '' && search_keyword !== 'undefined') { 1126 filterArray["keyword"] = search_keyword; 1127 for (var key in filterArray) { 1128 page_url = page_url + key + "=" + filterArray[key] + "&"; 1129 } 1130 } 1131 1132 //Filter Price Ranges 1133 /* 1134 var filterArray = []; 1135 $('input.filter_price_ranges:radio:checked').each(function() { 1136 if ($(this).data('priceRangeKey').length > 0 && $(this).data('priceRangeMaxValue') > 0) { 1137 var key = $(this).data('priceRangeKey'); 1138 var min_value = $(this).data('priceRangeMinValue'); 1139 var max_value = $(this).data('priceRangeMaxValue'); 1140 filterArray["" + key + ""] = min_value + "-" + max_value; 1141 } 1142 }); 1143 */ 1144 var price_range_value = $("#pricerange").val(); 1145 if (price_range_value != "" && price_range_value != "undefined") { 1146 page_url = page_url + "price_range=" + price_range_value + "&"; 1147 } 1148 1149 //Filter Color Array 1150 var colorArray = []; 1151 $('input.color-chk:checkbox:checked').each(function() { 1152 colorArray.push($(this).val()); 1153 }); 1154 if (colorArray != "" && colorArray != "undefined" && colorArray.length > 0) { 1155 page_url = page_url + "colors=" + colorArray + "&"; 1156 } 1157 1158 //Filter Size Array 1159 var sizeArray = []; 1160 $('input.color-size:checkbox:checked').each(function() { 1161 sizeArray.push($(this).val()); 1162 }); 1163 if (sizeArray != "" && sizeArray != "undefined" && sizeArray.length > 0) { 1164 page_url = page_url + "size=" + sizeArray + "&"; 1165 } 1166 1167 var item_stock = $("input#item_stock:checked").length; 1168 page_url = page_url + "in_stock=" + item_stock + "&"; 1169 1170 var sort_by = $("#sort_by").val(); 1171 if(sort_by != '' && sort_by != 'undefined' && sort_by != 'sort_by=sort_order&order=ASC') { 1172 page_url = page_url + sort_by; 1173 } 1174 1175 if ($("#sort_by_id").length > 0) { 1176 var sort_by_id = $("#sort_by_id").val(); 1177 if(sort_by_id != '' && sort_by_id != 'undefined' && sort_by_id != 'sort_by=sort_order&order=ASC') { 1178 page_url = page_url + sort_by_id; 1179 } 1180 } 1181 1182 if($("input#is_infinite_scroll").length == 0 || $("input#is_infinite_scroll").val() === 0) { 1183 page_url = page_url.replace(/(^\s*&)|(&\s*$)/g, ''); 1184 window.location.href = page_url; 1185 } else { 1186 //Do Not Change This Code 1187 if(parseInt(isScrolling) == 0) { 1188 $('html, body').animate({ 1189 'scrollTop' : $("div#div_product_list").position().top - 160 1190 }); 1191 $('div#div_product_list').html(''); 1192 $("input#total_pages").val(1); 1193 $("input#page_no").val(0); 1194 } 1195 1196 let total_pages = parseInt($("input#total_pages").val()); 1197 let page_no = parseInt($("input#page_no").val()); 1198 page_no++; 1199 page_url = page_url + "&page=" + page_no + ""; 1200 if(parseInt(total_pages) >= parseInt(page_no)) { 1201 $("input#page_no").val(page_no); 1202 this.loadAjaxData(page_url); 1203 } 1204 } 1205 }, 1206 loadAjaxData: function (page_url) { 1207 if(page_url.length > 0) { 1208 if (/categories/i.test(page_url)) { 1209 page_url = page_url.replace('categories/', 'categories/ajax/'); 1210 } else if (/tags/i.test(page_url)) { 1211 page_url = page_url.replace('tags/', 'tags/ajax/'); 1212 } 1213 // page_url = page_url.replace('categories/', 'categories/ajax/'); 1214 // page_url = page_url.replace('tags/', 'tags/ajax/'); 1215 $.ajax({
1216 type: "POST", 1217 async: false, 1218 cache: false, 1219 url: page_url, 1220 //data: dataParam, 1221 dataType: "html", 1222 beforeSend: function() { 1223 $("div#divLoading").show(); 1224 //$('div#div_product_list').html(''); 1225 }, 1226 success: function(responseData) { 1227 if(responseData.length > 0) { 1228 var ajax_total_pages = $($.parseHTML(responseData)).filter("input#ajax_total_pages").val(); 1229 $("input#total_pages").val(ajax_total_pages); 1230 var $container = $(responseData).wrap('<div />').parent(); 1231 $container.find("input#ajax_total_pages").remove(); 1232 $(responseData).appendTo("div#div_product_list").hide().fadeIn(500); 1233 } 1234 }, 1235 error:function (xhr, ajaxOptions, thrownError) { 1236 if(xhr.status == 404) { 1237 //alert(thrownError); 1238 let total_pages = parseInt($("input#total_pages").val()); 1239 $("input#page_no").val(total_pages); 1240 } 1241 }, 1242 complete: function() { 1243 $("div#divLoading").hide(); 1244 } 1245 }).done(function() { 1246 $("div#divLoading").hide(); 1247 //document.documentElement.scrollTop = 0; 1248 //$([document.documentElement, document.body]).animate({ 1249 //scrollTop: $("div#div_product_list").offset().top - 200 1250 //}, 1000); 1251 }); 1252 } 1253 }, 1254 quickView: function() { 1255 var appendThis = ("<div class='modal-overlay js-modal-close'></div>"); 1256 $('body').find(".js-modal-close, .modal-overlay, .modal-backdrop").click(function() { 1257 $('body').find(".quick-modal-box, .modal-overlay").fadeOut(500, function() { 1258 $('body').find('#quickProduct').find(".quick-modal-body").html(''); 1259 $('body').find(".modal-overlay").remove(); 1260 }); 1261 }); 1262 /* 1263 $(window).resize(function() { 1264 $(document).find(".quick-modal-box").css({ 1265 top: ($(window).height() - $(".quick-modal-box").outerHeight()) / 2, 1266 left: ($(window).width() - $(".quick-modal-box").outerWidth()) / 2 1267 }); 1268 }); 1269 1270 $(window).resize(); 1271 */ 1272 1273 $('body').on("click", "span.btnquick", function(event) { 1274 event.preventDefault(); 1275 var productUrl = $(this).data('productUrl'); 1276 var quickProductModal = new bootstrap.Modal(document.getElementById('quickProduct'), { keyboard: false }); 1277 1278 $.ajax({
1279 type: "POST", 1280 async: false, 1281 cache: false, 1282 url: "/products/quick", 1283 dataType: "html", 1284 data: { 1285 "data[StoreProduct][seo_url]": productUrl 1286 }, 1287 beforeSend: function(XMLHttpRequest) { 1288 // $("#quickProduct").hide(); 1289 // $('#quickProduct').show(); 1290 // $('#quickProduct').modal('hide'); 1291 // $('body').removeClass('modal-open'); 1292 // $('.modal-backdrop').remove(); 1293 $('#quickProduct').find(".quick-modal-body").html(''); 1294 }, 1295 success: function(data, textStatus) { 1296 // $("body").append(appendThis); 1297 // $(".modal-overlay").fadeTo(500, 0.7); 1298 $('#quickProduct').find(".quick-modal-body").html(data); 1299 quickProductModal.toggle(); 1300 }, 1301 error: function(jqXHR, textStatus, errorThrown) { 1302 if (jqXHR.status == 500) { 1303 alert('Internal error: ' + jqXHR.responseText); 1304 } 1305 $('#quickProduct').hide(); 1306 } 1307 }); 1308 }); 1309 } 1310 }, 1311 Theme.Utils.Product = { 1312 initProduct: function() { 1313 $(document).find(".videoModalClick").click(function() { 1314 let video_code = $(this).data('videoCode'); 1315 let video_type = $(this).data('videoType'); 1316 let srcPath = ''; 1317 1318 if(parseInt(video_type) == 0) { 1319 srcPath = 'https://www.youtube.com/embed/'+ video_code +''; 1320 } else if(parseInt(video_type) == 1) { 1321 srcPath = 'https://player.vimeo.com/video/'+ video_code +'?title=0&byline=0" frameborder="0" allowfullscreen ></iframe>'; 1322 } 1323 1324 $('#courseVideoModal').on('show.bs.modal', function () { // on opening the modal 1325 // set the video to autostart 1326 $('div#div_course_video').find('iframe').attr('src', srcPath); 1327 }).on('hidden.bs.modal', function (e) { // on closing the modal 1328 // stop the video 1329 $('div#div_course_video').find('iframe').attr('src', null); 1330 }); 1331 1332 $('#courseVideoModal').modal('show'); 1333 }); 1334 1335 $(document).find(".coupon_detail").click(function() { 1336 var coupon_code = $(this).data("couponCode"); 1337 $.ajax({
1338 type: "POST", 1339 async: true, 1340 cache: false, 1341 url: "/store_coupons/get_coupon_details", 1342 accepts: 'application/json', 1343 dataType: "json", 1344 data: "coupon_code="+coupon_code+"", 1345 beforeSend: function(XMLHttpRequest) { 1346 }, 1347 complete: function() { 1348 1349 }, 1350 success: function(data, textStatus) { 1351 if (data !== undefined && data != '') { 1352 $.each(data, function(index, coupons) { 1353 var date = new Date(coupons.expiry_date); 1354 var yyyy = date.getFullYear().toString(); 1355 var mm = (date.getMonth() + 1).toString(); 1356 var dd = date.getDate().toString(); 1357 var dval = dd+"-"+mm+"-"+yyyy; 1358 1359 let strHTML = '<div class="row bg-light">'; 1360 strHTML = strHTML + '<div class="col-sm-6 col-12 border">'; 1361 strHTML = strHTML + '<div class="clearfix p-2 text-center">'; 1362 strHTML = strHTML + '<span class="text-muted py-1 d-block">Use Coupon Code:</span>'; 1363 strHTML = strHTML + '<span class="d-block fs-5 note-highlight">'+coupons.coupon_code+'</span>'; 1364 strHTML = strHTML + '</div>'; 1365 strHTML = strHTML + '</div>'; 1366 strHTML = strHTML + '<div class="col-sm-6 col-12 border border-start-0">'; 1367 strHTML = strHTML + '<div class="clearfix p-2 text-center">'; 1368 strHTML = strHTML + '<span class="text-muted py-1 d-block">Expiry Date:</span>'; 1369 strHTML = strHTML + '<span class="d-block fs-5">'+ dval +'</span></div>'; 1370 strHTML = strHTML + '</div>'; 1371 strHTML = strHTML + '</div>'; 1372 strHTML = strHTML + '<p class="pt-3 fw-bold">'+coupons.short_description+'</p>'; 1373 strHTML = strHTML + '<p class="margin0">'+coupons.terms_and_conditions+'</p>'; 1374 $('#coupon-terms-detail').html(strHTML); 1375 }); 1376 } else { 1377 let strHTML = "<p class=\"text-danger\">There was an error while processing your request. Please try again.</p>"; 1378 $('#coupon-terms-detail').html(strHTML); 1379 } 1380 setTimeout(function() { 1381 $('div#coupon-terms-modal').modal("show"); 1382 }, 300); 1383 }, 1384 error: function(jqXHR, textStatus, errorThrown) { 1385 //console.log(jqXHR.responseText); 1386 if (jqXHR.status == 500) { 1387 alert('Internal error: ' + jqXHR.responseText); 1388 } 1389 } 1390 }); 1391 }); 1392 1393 Theme.Utils.Element.init(), $("#zoom4").length > 0 && $("#zoom4").glassCase({ 1394 widthDisplay: 450, 1395 heightDisplay: 600, 1396 isSlowZoom: !0, 1397 isDownloadEnabled: !1, 1398 captionType: "out", 1399 captionPosition: "bottom", 1400 captionAlignment: "left", 1401 colorIcons: "#000", 1402 colorActiveThumb: "#000", 1403 thumbsPosition: "left" 1404 }), $("#variant_size, #variant_color, #variant_material").on("change", function() { 1405 var a = Theme.Utils.Product.selectedValues(); 1406 b = Theme.Utils.Product.getVariant(a); 1407 console.log("EPA " + a);
1408 Theme.Utils.Product.selectCallback(b, $(this)); 1409 }), $(".variant_size_span").on("click", function() { 1410 //$(".stock-availability").show(); 1411 var a = $(this).parent().find("input:radio[name='variant_size']").val(), b = []; 1412 b.size = a, b.push({size: a}); 1413 var c = Theme.Utils.Product.getVariant(b); 1414 console.log("EP " + a); 1415 Theme.Utils.Product.selectCallback(c, $(this)); 1416 }), $(".variant_size_span_lable").on("click", function() { 1417 var a = $(this).parent().find("input:radio[name='variant_size_lable']").val(); 1418 $("#variant_size").val(a).trigger("change"); 1419 }), $("#productTab").length > 0 && $("#productTab a:first").tab("show"), $("div#diverror").hide(), $(document).on("click", "button#add-to-cart", function(a) { 1420 return a.stopPropagation(), 0 == parseInt(Theme.ProductData.product.variants.length) && parseInt(Theme.ProductData.product.minimum_order_quantity) > 0 && $("input#quantity").val() < parseInt(Theme.ProductData.product.minimum_order_quantity) ? ($("div#diverror").show(), $("div#diverror").find(".label-danger").html("Minimum order quantity must be " + parseInt(Theme.ProductData.product.minimum_order_quantity)), !1) : !0 1421 }), $(".variant_select").off("click").on("click", function(event) { 1422 // Block re-entrant trigger('click') calls from selectCallback 1423 if ($.data(this, 'processing')) return; 1424 $.data(this, 'processing', true); 1425 1426 var $this = $(this); 1427 var self = this; 1428 1429 setTimeout(function() { 1430 var a = Theme.Utils.Product.selectedValues(); 1431 var b = Theme.Utils.Product.getVariant(a); 1432 1433 Theme.Utils.Product.selectCallback(b, $this); 1434 1435 $.data(self, 'processing', false); // Unlock after done 1436 }, 0); 1437 }), this.setDefault() 1438 }, 1439 QuestionForm: function () { 1440 // Handles custom Form Submission 1441 $("#StoreCustomIndexForm").submit(function(e) { 1442 e.preventDefault(); 1443 1444 var ProductId = $(document).find("input#id").val(); 1445 var ProductVariantId = $(document).find("input#product_variant_id").val(); 1446 var FullName = $(this).find("input#full_name").val(); 1447 var Email = $(this).find("input#email").val(); 1448 var MobileNo = $(this).find("input#mobile_no").val(); 1449 var Question= $(this).find("#question").val(); 1450 1451 if (FullName.length == 0 || Email.length == 0 || MobileNo.length == 0) { 1452 alert("Please fill all required information"); 1453 return false; 1454 } 1455 var FormData = "product_id=" + ProductId + "&product_variant_id=" + ProductVariantId + "&full_name=" + FullName + "&email=" + Email + "&mobile_no=" + MobileNo + "&question=" + escape(Question); 1456 1457 1458 $.ajax({
1459 type: "POST", 1460 async: true, 1461 cache: false, 1462 url: "/store_products/customformsave", 1463 accepts: 'application/json', 1464 dataType: "json", 1465 data: FormData, 1466 beforeSend: function (XMLHttpRequest) { 1467 //$("#payment_city_id").find("option").not(':first').remove(); 1468 1469 }, 1470 complete: function () { 1471 1472 }, 1473 success: function (data, textStatus) { 1474 if(data.notify_status == 1) { 1475 $("#successmsg").removeClass("d-none"); 1476 1477 $("#full_name").val(''); 1478 $("#email").val(''); 1479 $("#mobile_no").val(''); 1480 $("#question").val(''); 1481 setTimeout(function() { 1482 $("#successmsg").addClass("d-none"); 1483 }, 3000); 1484 } 1485 }, 1486 error: function (jqXHR, textStatus, errorThrown) { 1487 console.log(jqXHR.responseText); 1488 if (jqXHR.status == 500) { 1489 alert('Internal error: ' + jqXHR.responseText); 1490 } 1491 } 1492 }); 1493 }); 1494 }, 1495 selectedValues: function() { 1496 var currValues = []; 1497 currValues['size'] = ($("#variant_size").length > 0) ? $("#variant_size").val() : null; 1498 currValues['color'] = ($("#variant_color").length > 0) ? $("#variant_color").val() : null; 1499 currValues['material'] = ($("#variant_material").length > 0) ? $("#variant_material").val() : null; 1500 1501 1502 if ($("#variant_size").length > 0) { 1503 currValues.push({ 1504 "size": $("#variant_size").val() 1505 }); 1506 } 1507 if ($("#variant_color").length > 0) { 1508 currValues.push({ 1509 "color": $("#variant_color").val() 1510 }); 1511 } 1512 if ($("#variant_material").length > 0) { 1513 currValues.push({ 1514 "material": $("#variant_material").val() 1515 }); 1516 } 1517 1518 //New Process for Square Boxes 1519 if($("div#div_variant_selection").length > 0) { 1520 var currValues = []; 1521 currValues['size'] = null; 1522 currValues['color'] = null; 1523 currValues['material'] = null; 1524 1525 if($("div#div_variant_selection").find("input:radio[name='variant_size']").length > 0) { 1526 currValues['size'] = $("div#div_variant_selection").find("input:radio[name='variant_size']:checked").val(); 1527 currValues.push({"size": $("div#div_variant_selection").find("input:radio[name='variant_size']:checked").val()}); 1528 } 1529 if($("div#div_variant_selection").find("input:radio[name='variant_color']").length > 0) { 1530 currValues['color'] = $("div#div_variant_selection").find("input:radio[name='variant_color']:checked").val(); 1531 currValues.push({"color": $("div#div_variant_selection").find("input:radio[name='variant_color']:checked").val()}); 1532 } 1533 if($("div#div_variant_selection").find("input:radio[name='variant_material']").length > 0) { 1534 currValues['material'] = $("div#div_variant_selection").find("input:radio[name='variant_material']:checked").val(); 1535 currValues.push({"material": $("div#div_variant_selection").find("input:radio[name='variant_material']:checked").val()}); 1536 } 1537 } 1538 1539 return currValues; 1540 }, 1541 getVariant: function(selectedValues) { 1542 // return the variant object if exists with given values, otherwise return null 1543 var found = null; 1544 if (selectedValues.length != Theme.ProductData.product.options.length) { 1545 return found; 1546 } 1547 1548 var variants = Theme.ProductData.product.variants;
1549 1550 $.each(variants, function(index, variant) { 1551 var satisfied = true; 1552 var j = selectedValues.length; 1553 1554 var size = (selectedValues.hasOwnProperty("size")) ? selectedValues.size : null; 1555 var color = (selectedValues.hasOwnProperty("color")) ? selectedValues.color : null; 1556 var material = (selectedValues.hasOwnProperty("material")) ? selectedValues.material : null; 1557 1558 if ((variant.size != size) || (variant.color != color) || (variant.material != material)) { 1559 satisfied = false; 1560 } 1561 1562 if (satisfied == true) { 1563 found = variant; 1564 return; 1565 } 1566 }); 1567 return found; 1568 }, 1569 setDefault: function() { 1570 var Language = (typeof window.app.BRAND_STORE_LANGUAGE !== 'undefined') ? window.app.BRAND_STORE_LANGUAGE : "en"; 1571 var Translator = new Theme.Language.ParseLanguage(Language); 1572 let input_quantity = ($("input#quantity").length > 0) ? $("input#quantity").val() : 1; 1573 1574 //Auto-select first available variant on page load. 1575 if (Theme.ProductData.product.variants.length > 0) { 1576 var variants = Theme.ProductData.product.variants; 1577 var inStock = 0; 1578 var showMain = 0; 1579 var defaultVariant = {}; 1580 $.each(variants, function(index, variantData) { 1581 if (variantData.hasOwnProperty("show_as_main") && parseInt(variantData.show_as_main) == 1 && variantData.available == true) { 1582 showMain = 1; 1583 defaultVariant = variantData; 1584 } 1585 }); 1586 1587 //New Code Implemented On 13-03-2018 1588 if (parseInt(showMain) === 1) { 1589 inStock = 1; 1590 Theme.Utils.Product.setDefaultVariant(defaultVariant); 1591 } else { 1592 $.each(variants, function(index, variantData) { 1593 if (variantData.available === true) { 1594 Theme.Utils.Product.setDefaultVariant(variantData); 1595 //Break Loop in case of available 1596 inStock = 1; 1597 return false; 1598 } 1599 }); 1600 } 1601 1602 if (parseInt(inStock) == 0) { 1603 $("button#add-to-cart").addClass("disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); // set add-to-cart button to unavailable class and disable button 1604 $("a#login_to_buy").addClass("disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); 1605 $("button.btn-buynow").addClass("disabled").attr("disabled", true).hide(); 1606 $("#btnnotify").css("display", "block"); 1607 1608 //Set Variant ID In Case of Variant 1609 var currValues = Theme.Utils.Product.selectedValues(); // get current values 1610 if (currValues.length > 0) { 1611 var variant = Theme.Utils.Product.getVariant(currValues); 1612 if(variant !== null) { 1613 $("#StoreCartProductVariantId").val(variant.id); 1614 } 1615 1616 //Incase of Gold Rate 1617 if(parseInt(window.Store.AppConfig.is_gold_rate) == 1) { 1618 if(variant !== null) { 1619 Theme.Utils.Product.getProductComponentPrice(variant.product_id, variant.id); 1620 } else { 1621 $.each(variants, function(index, variantData) { 1622 if (variantData.hasOwnProperty("show_as_main") && parseInt(variantData.show_as_main) == 1) { 1623 console.log("STP " + variantData.product_id + " " + variantData.id); 1624 1625 Theme.Utils.Product.getProductComponentPrice(variantData.product_id, variantData.id); 1626 } 1627 }); 1628 } 1629 } 1630 } 1631 } 1632 } else if (Theme.ProductData.product.available == false) { 1633 $("button#add-to-cart").addClass("disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); // set add-to-cart button to unavailable class and disable button 1634 $("a#login_to_buy").addClass("d-none disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); 1635 $("button.btn-buynow").addClass("disabled").attr("disabled", true).hide(); 1636 $("#btnnotify").css("display", "block"); 1637 //var message = "Sold Out"; 1638 //$("#price-preview").text(message); 1639 //$("#divclose").css("display", "block"); // set add-to-cart button to unavailable class and disable button 1640 } else if (Theme.ProductData.product.available == true) { 1641 if ($("#estimated_shipping_days").length > 0) { 1642 //if (Theme.ProductData.product.track_inventory && parseInt(Theme.ProductData.product.quantity) == 0 && Theme.ProductData.product.allow_purchase) {} 1643 if (parseInt(Theme.ProductData.product.track_inventory) == 1 && parseInt(Theme.ProductData.product.allow_purchase) == 1) { 1644 if (parseInt(Theme.ProductData.product.actual_quantity) < parseInt(input_quantity)) { 1645 shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 1646 //shipping_days += (parseInt(shipping_days) > 1) ? " days" : " day"; 1647 shipping_days = (parseInt(shipping_days) == 1) ? "24 hours" : shipping_days + " business days."; 1648 $("#estimated_shipping_days").html(shipping_days); 1649 } 1650 } 1651 } 1652 1653 //Shipping Days Message 1654 if($("#estimated_shipping_days_msg").length > 0) { 1655 let estimated_shipping_days = estimated_outofstock_shipping_days = 0; 1656 let estimated_shipping_days_minus_1 = estimated_shipping_days_plus_1 = 0; 1657 let estimated_outofstock_shipping_weeks_minus_1 = estimated_outofstock_shipping_weeks_plus_1 = 0; 1658 let estimated_shipping_days_msg = ''; 1659 let input_quantity = ($("input#quantity").length > 0) ? $("input#quantity").val() : 1; 1660 1661 if (parseInt(Theme.ProductData.product.track_inventory) == 1 && parseInt(Theme.ProductData.product.allow_purchase) == 0) { 1662 if (parseInt(Theme.ProductData.product.quantity) > 0) { 1663 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 1664 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 1665 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 1666 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 1667 } else { 1668 estimated_outofstock_shipping_days = parseInt(Theme.ProductData.product.estimated_outofstock_shipping_days); 1669 estimated_outofstock_shipping_weeks = Math.round(estimated_outofstock_shipping_days / 7); 1670 estimated_outofstock_shipping_weeks_minus_1 = parseInt(estimated_outofstock_shipping_weeks) - 1; 1671 estimated_outofstock_shipping_weeks_plus_1 = parseInt(estimated_outofstock_shipping_weeks) + 1; 1672 estimated_shipping_days_msg = "Made to Order (Ships in "+ estimated_outofstock_shipping_weeks_minus_1 +" to "+ estimated_outofstock_shipping_weeks_plus_1 +" weeks)"; 1673 } 1674 } else if (parseInt(Theme.ProductData.product.track_inventory) == 1 && parseInt(Theme.ProductData.product.allow_purchase) == 1) { 1675 //if (parseInt(Theme.ProductData.product.quantity) > 0 && parseInt(Theme.ProductData.product.quantity) != 999999) { 1676 if (parseInt(Theme.ProductData.product.actual_quantity) >= parseInt(input_quantity)) { 1677 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 1678 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 1679 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 1680 1681 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 1682 } else { 1683 estimated_outofstock_shipping_days = parseInt(Theme.ProductData.product.estimated_outofstock_shipping_days); 1684 estimated_outofstock_shipping_weeks = Math.round(estimated_outofstock_shipping_days / 7); 1685 estimated_outofstock_shipping_weeks_minus_1 = parseInt(estimated_outofstock_shipping_weeks) - 1; 1686 estimated_outofstock_shipping_weeks_plus_1 = parseInt(estimated_outofstock_shipping_weeks) + 1; 1687 1688 estimated_shipping_days_msg = "Made to Order (Ships in "+ estimated_outofstock_shipping_weeks_minus_1 +" to "+ estimated_outofstock_shipping_weeks_plus_1 +" weeks)"; 1689 } 1690 } else if (parseInt(Theme.ProductData.product.track_inventory) == 0) { 1691 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 1692 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 1693 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 1694 1695 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 1696 } 1697 1698 $("#estimated_shipping_days_msg").html(estimated_shipping_days_msg); 1699 } 1700 1701 if (Theme.ProductData.product.track_inventory && parseInt(Theme.ProductData.product.quantity) == 0 && Theme.ProductData.product.allow_purchase) { 1702 $("#outstockdivdays").removeClass("d-none"); 1703 $("#instockdivdays").addClass("d-none"); 1704 } else { 1705 $("#outstockdivdays").addClass("d-none"); 1706 $("#instockdivdays").removeClass("d-none"); 1707 } 1708 1709 if(parseInt(window.Store.TemplateConfig.is_b2b_quantity_multiple) == 1) { 1710 $("#StoreCartAddForm").closest('form').find(".quantity").data("incrementQuantity", Theme.ProductData.product.minimum_order_quantity); 1711 $("#StoreCartAddForm").closest('form').find(".quantity").val(Theme.ProductData.product.minimum_order_quantity); 1712 } 1713 } 1714 }, 1715 setDefaultVariant: function(variantData) {
1716 if(window.disable_auto_select_default_variant == 0) { 1717 if (typeof variantData.size != 'undefined') { 1718 if (variantData.hasOwnProperty("size")) { 1719 1720 //Check Whether Select Dropdown Option Exists 1721 if ($("#variant_size").length > 0) { 1722 $("#variant_size").val(variantData.size).trigger("change"); 1723 } 1724 1725 //Check Whether Circle Label Option Exists 1726 if ($(".variant_size_span").length > 0) { 1727 $('.variant_size_span').each(function(i) { 1728 if ($(this).parent().find("input:radio[name='variant_size']").is(':enabled')) { 1729 $(this).trigger("click"); 1730 return false; 1731 } 1732 }); 1733 } 1734 1735 //Check Whether Square Label Option Exists 1736 if($("div#div_variant_selection").length > 0) { 1737 if($("div#div_variant_selection").find("input:radio[name='variant_size']").length > 0) { 1738 //First: Select Radio Button 1739 $("div#div_variant_selection").find("input:radio[name='variant_size'][value='" + variantData.size + "']").prop('checked', true); 1740 1741 $("div#div_variant_selection").find("input:radio[name='variant_size']").each(function(i) { 1742 if ($(this).is(':enabled') && $(this).is(':checked') && $(this).closest(".variant_select").length > 0) { 1743 $(this).closest(".variant_select").trigger('click'); 1744 return false; 1745 } 1746 }); 1747 1748 //$("div#div_variant_selection").find("input:radio[name='variant_size'][value='" + variantData.size + "']").prop('checked', true); 1749 //$(".variant_select").trigger('click'); 1750 //$(".quantity").data("quantity", variantData.quantity); 1751 } 1752 } 1753 } 1754 } 1755 1756 if (typeof variantData.color != 'undefined') { 1757 if (variantData.hasOwnProperty("color")) { 1758 //Check Whether Select Dropdown Option Exists 1759 if ($("#variant_color").length > 0) { 1760 $("#variant_color").val(variantData.color).trigger("change"); 1761 } 1762 1763 //Check Whether Square Label Option Exists 1764 if($("div#div_variant_selection").length > 0) { 1765 if($("div#div_variant_selection").find("input:radio[name='variant_color']").length > 0) { 1766 $("div#div_variant_selection").find("input:radio[name='variant_color'][value='" + variantData.color + "']").prop('checked', true); 1767 } 1768 } 1769 } 1770 } 1771 1772 if (typeof variantData.material != 'undefined') { 1773 if (variantData.hasOwnProperty("material")) { 1774 //Check Whether Select Dropdown Option Exists 1775 if ($("#variant_material").length > 0) { 1776 $("#variant_material").val(variantData.material).trigger("change"); 1777 } 1778 1779 //Check Whether Square Label Option Exists 1780 if($("div#div_variant_selection").length > 0) { 1781 if($("div#div_variant_selection").find("input:radio[name='variant_material']").length > 0) { 1782 $("div#div_variant_selection").find("input:radio[name='variant_material'][value='" + variantData.material + "']").prop('checked', true); 1783 //For AURA Theme 1784 if($("div#div_variant_selection").find('.aq_epdtitle span.size_expand_label').length > 0) { 1785 $("div#div_variant_selection").find('.aq_epdtitle span.size_expand_label').text(variantData.material); 1786 } 1787 } 1788 } 1789 } 1790 } 1791 1792 //Set product_variant_id of Cart Form 1793 $("#StoreCartProductVariantId").val(variantData.id); 1794 1795 if (variantData.available == true) { 1796 //Set Estimated Shipping Days IN case track inventory true, Quantity in stock is Zero and allow_purchase is true 1797 if ($("#estimated_shipping_days").length > 0) { 1798 if (Theme.ProductData.product.track_inventory && parseInt(variantData.quantity) == 0 && Theme.ProductData.product.allow_purchase) { 1799 shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 1800 } else { 1801 shipping_days = Theme.ProductData.product.estimated_shipping_days; 1802 } 1803 //shipping_days += (parseInt(shipping_days) > 1) ? " days" : " day"; 1804 shipping_days = (parseInt(shipping_days) == 1) ? "24 hours" : shipping_days + " business days."; 1805 $("#estimated_shipping_days").html(shipping_days); 1806 } 1807 1808 //Set Estimated Shipping Days IN case track inventory true, Quantity in stock is Zero and allow_purchase is true 1809 if ($("#div_product_weight").length > 0) { 1810 product_weight = variantData.product_weight; 1811 $("#span_product_weight").html(product_weight); 1812 } 1813 } 1814 1815 if(variantData !== null) { 1816 Theme.Utils.Product.setShippingDate(variantData); 1817 if(parseInt(window.Store.AppConfig.is_gold_rate) == 1) { 1818 console.log("ST " + variantData.product_id + " " + variantData.id); 1819 Theme.Utils.Product.getProductComponentPrice(variantData.product_id, variantData.id); 1820 } 1821 } 1822 1823 return true; 1824 } else { 1825 $(".stock-availability").hide(); 1826 if($("div#div_product_questions").length > 0) { 1827 $("div#div_product_questions").addClass("d-none"); 1828 } 1829 } 1830 }, 1831 selectCallback: function(variant, selector) { 1832 var Language = (typeof window.app.BRAND_STORE_LANGUAGE !== 'undefined') ? window.app.BRAND_STORE_LANGUAGE : "en"; 1833 var Translator = new Theme.Language.ParseLanguage(Language); 1834 1835 if (variant) { 1836 if (variant.image_id > 0) { 1837 selected_id = variant.image_id; 1838 // For Desktop View 1839 if ($("#product-zoom").length > 0) { 1840 var product_zoom = document.getElementById("product-zoom"); 1841 var product_list = product_zoom.getElementsByTagName("li"); 1842 for (j = 0; j < product_list.length; j++) { 1843 li_image = product_list[j].getElementsByTagName("img"); 1844 li_img = (li_image.length > 0) ? li_image[0] : {}; 1845 if(Object.keys(li_img).length > 0) { 1846 li_img_src = li_img.src; 1847 li_img_src = li_img_src.split("?param="); 1848 li_img_param = (li_img_src.length > 1) ? li_img_src[1] : 0; 1849 if (parseInt(li_img_param) == parseInt(selected_id)) { 1850 product_list[j].setAttribute("id", "li_" + selected_id); 1851 } 1852 } 1853 } 1854 1855 // 1. Pehle glassCase initialize karo 1856 $("#product-zoom").glassCase({ 1857 'firstThumbSelected': Math.round(selected_id) - 1, 1858 'isAutoPlayDisplay': false 1859 }); 1860 1861 // 2. Plugin settle hone ke baad click trigger karo 1862 setTimeout(function () { 1863 var m_control = "#li_" + selected_id + " div.gc-display-container"; 1864 $(m_control).trigger("click"); 1865 }, 100); 1866 1867 // console.log(selected_id); 1868 // var m_control = "#li_" + selected_id + " div.gc-display-container"; 1869 // $(m_control).trigger("click"); 1870 // $("#product-zoom").glassCase({ 1871 // 'firstThumbSelected': Math.round(selected_id) - 1, 1872 // 'isAutoPlayDisplay': false 1873 // }); 1874 } 1875 1876 if ($(".photo-gallery").length > 0) { 1877 $('a.img_1').attr("href", variant.big_image); 1878 $('img#img_1').attr("src", variant.big_image); 1879 $('img#img_1').attr("data-tmbLarge", variant.big_image); 1880 } 1881 1882 // For Mobile View 1883 if (selected_id > 0) { 1884 var coll = document.getElementsByClassName("carousel-item"); 1885 for (x = 0; x < coll.length; x++) { 1886 var m_item_id = coll.item(x).id; 1887 if (typeof m_item_id !== "undefined" && m_item_id.length > 0) { 1888 $("#" + m_item_id).removeClass("active"); 1889 } 1890 } 1891 $("#m_item_" + selected_id).addClass("active"); 1892 $('.carousel').carousel('pause'); 1893 } 1894 } 1895 1896 if(parseInt(variant.show_size_dropdown) == 1) { 1897 if($("div#SizeDiv").length > 0) { 1898 $("div#SizeDiv").removeClass("d-none"); 1899 } 1900 } else { 1901 if($("div#SizeDiv").length > 0) { 1902 $("div#SizeDiv").addClass("d-none"); 1903 } 1904 } 1905 1906 if(parseInt(variant.show_custom_form) == 1) { 1907 if($("div#MeasurementDiv").length > 0) { 1908 $("div#MeasurementDiv").removeClass("d-none"); 1909 $("select#saved_measurement").addClass("required"); 1910 } 1911 1912 if($("div#div_product_questions").length > 0) { 1913 $("div#div_product_questions").removeClass("d-none"); 1914 } 1915 } else { 1916 if($("div#MeasurementDiv").length > 0) { 1917 $("div#MeasurementDiv").addClass("d-none"); 1918 $("select#saved_measurement").removeClass("required"); 1919 } 1920 1921 if($("div#div_product_questions").length > 0) { 1922 $("div#div_product_questions").addClass("d-none"); 1923 } 1924 } 1925 1926 if(parseInt(variant.show_size_dropdown) == 1) { 1927 $("input#selection_type").val(1); 1928 } else if(parseInt(variant.show_custom_form) == 1) { 1929 $("input#selection_type").val(2); 1930 } else { 1931 $("input#selection_type").val(0); 1932 } 1933 } 1934 1935 if(variant && parseFloat(variant.product_weight) > 0) { 1936 $(".product-weight").html('Gross Weight: <span id="span_product_weight">'+ variant.product_weight +'</span> Kg.'); 1937 } else { 1938 $(".product-weight").html(''); 1939 } 1940 1941 if (variant && variant.available) { 1942 $("button.add-to-cart").removeAttr("disabled").removeClass("disabled btn-outstock").html(Theme.Language.getStr("AddToCart")).css("display", "block"); // set add-to-cart button to unavailable class and disable button 1943 $("button.btn-buynow").removeAttr("disabled").removeClass("disabled").show(); 1944 $("#btnnotify").css("display", "none"); 1945
1946 if(window.BRAND_STORE_CURRENCY_SYMBOL_POSTFIX == 1) { 1947 if (variant.product_price < variant.compare_at_price) { 1948 $("#price-preview").html("<div class=\"cut-price\"><span style=\"text-decoration: line-through;\">" + Brand.formatMoney(variant.compare_at_price, "{{amount}}") + window.app.BRAND_STORE_CURRENCY + "</span></div> \n <div class=\"me-2 product-price text-danger\">" + Brand.formatMoney(variant.product_price, "{{amount}}") + window.app.BRAND_STORE_CURRENCY + " </div>"); 1949 if(window.Store.TemplateConfig.show_discount_percent_on_product == 1) { 1950 if(window.Store.TemplateConfig.show_discount_percent_on_product_round_off == 1) { 1951 var discount_percent = parseFloat(parseInt((parseFloat(variant.compare_at_price - variant.product_price) / parseFloat(variant.compare_at_price)) * 10000) / 100).toFixed(0); 1952 } else { 1953 var discount_percent = parseFloat(parseFloat((parseFloat(variant.compare_at_price - variant.product_price) / parseFloat(variant.compare_at_price)) * 10000) / 100).toFixed(2); 1954 } 1955 if(discount_percent > 0) { 1956 $("#price-preview").append("<div class=\"me-2 badge align-self-center border border-danger small text-danger off-price-product\">"+ discount_percent +"% Off</div>"); 1957 } 1958 } 1959 } else { 1960 $("#price-preview").html("<div class=\"product-price\">" + Brand.formatMoney(variant.product_price, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY + " </div>"); 1961 } 1962 } else { 1963 if (variant.product_price < variant.compare_at_price) { 1964 $("#price-preview").html("<div class=\"cut-price\"><span style=\"text-decoration: line-through;\">" + window.app.BRAND_STORE_CURRENCY + Brand.formatMoney(variant.compare_at_price, "{{amount}}") + "</span></div> \n <div class=\"me-2 product-price text-danger\">" + window.app.BRAND_STORE_CURRENCY + Brand.formatMoney(variant.product_price, "{{amount}}") + " </div>"); 1965 1966 if(window.Store.TemplateConfig.show_discount_percent_on_product == 1) { 1967 if(window.Store.TemplateConfig.show_discount_percent_on_product_round_off == 1) { 1968 var discount_percent = parseFloat(parseInt((parseFloat(variant.compare_at_price - variant.product_price) / parseFloat(variant.compare_at_price)) * 10000) / 100).toFixed(0); 1969 } else { 1970 var discount_percent = parseFloat(parseFloat((parseFloat(variant.compare_at_price - variant.product_price) / parseFloat(variant.compare_at_price)) * 10000) / 100).toFixed(2); 1971 } 1972 if(discount_percent > 0) { 1973 $("#price-preview").append("<div class=\"me-2 badge align-self-center border border-danger small text-danger off-price-product\">"+ discount_percent +"% Off</div>"); 1974 } 1975 } 1976 } else { 1977 $("#price-preview").html("<div class=\"product-price\">" + window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(variant.product_price, "{{amount}}") + " </div>"); 1978 } 1979 } 1980 1981 if (Theme.ProductData.user.is_wholesaler && $("div#retail-price-preview") !== undefined) { 1982 if (variant.retail_net_price > variant.product_price) { 1983 $("#retail-price-preview").removeClass("hidden"); 1984 if(window.BRAND_STORE_CURRENCY_SYMBOL_POSTFIX == 1) { 1985 $("#retail-net-price").html(Brand.formatMoney(variant.retail_net_price, "{{amount}}") + " " +window.app.BRAND_STORE_CURRENCY); 1986 } else { 1987 $("#retail-net-price").html(window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(variant.retail_net_price, "{{amount}}")); 1988 } 1989 } else { 1990 $("#retail-price-preview").addClass("hidden"); 1991 } 1992 } else if ($("div#retail-price-preview") !== undefined) { 1993 $("#retail-price-preview").addClass("hidden"); 1994 } 1995 1996 $("#StoreCartProductVariantId").val(variant.id); 1997 if ($("#StoreCartAddForm #StoreCartProductVariantId")) { 1998 $("#StoreCartAddForm #StoreCartProductVariantId").val(variant.id); 1999 } 2000 2001 $("#product-sku").html(variant.sku); 2002 $(".quantity").data("quantity", variant.quantity); 2003 //$(this).closest("form").find("input.quantity").data('quantity',variant.quantity) 2004 if(parseInt(window.Store.TemplateConfig.is_b2b_quantity_multiple) == 1) { 2005 $("#StoreCartAddForm").closest('form').find(".quantity").data("incrementQuantity", variant.minimum_order_quantity); 2006 $("#StoreCartAddForm").closest('form').find(".quantity").val(variant.minimum_order_quantity); 2007 } else { 2008 $("#StoreCartAddForm").closest('form').find(".quantity").data("incrementQuantity", 1); 2009 $("#StoreCartAddForm").closest('form').find(".quantity").val(1); 2010 } 2011 2012 var totalStock = $("label#instock"); 2013 2014 var is_fabric = $("input#is_fabric").val(); 2015 if (typeof totalStock != 'undefined') { 2016 $(".stock-availability").show(); 2017 if(is_fabric == 1) { 2018 totalStock.html(variant.actual_quantity + " meter in stock"); 2019 } else{ 2020 totalStock.html(variant.actual_quantity + " in stock"); 2021 } 2022 } 2023 2024 var earnRewardPoints = $("span#earn_reward_points"); 2025 if (typeof earnRewardPoints != 'undefined') { 2026 earnRewardPoints.html(variant.earn_reward_points); 2027 } 2028 2029 var spendRewardPoints = $("span#spend_reward_points"); 2030 if (typeof spendRewardPoints != 'undefined') { 2031 spendRewardPoints.html(variant.spend_reward_points); 2032 } 2033 } else if (variant && !variant.available) { 2034 $("button.add-to-cart").addClass("disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); // set add-to-cart button to unavailable class and disable button 2035 $("button.btn-buynow").addClass("disabled").attr("disabled", true).hide(); 2036 $("#btnnotify").css("display", "block"); 2037 2038 var message = ''; 2039 if (variant && !variant.available) {
2040 if(window.BRAND_STORE_CURRENCY_SYMBOL_POSTFIX == 1) { 2041 if (variant.product_price < variant.compare_at_price) { 2042 $("#price-preview").html("<div class=\"cut-price\"><span style=\"text-decoration: line-through;\">" + Brand.formatMoney(variant.compare_at_price, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY + "</span></div> \n <div class=\"product-price text-danger\"> " + Brand.formatMoney(variant.product_price, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY + " </div>"); 2043 } else { 2044 $("#price-preview").html("<div class=\"product-price\">" + Brand.formatMoney(variant.product_price, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY + " </div>"); 2045 } 2046 } else { 2047 if (variant.product_price < variant.compare_at_price) { 2048 $("#price-preview").html("<div class=\"cut-price\"><span style=\"text-decoration: line-through;\">" + window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(variant.compare_at_price, "{{amount}}") + "</span></div> \n <div class=\"product-price text-danger\"> " + window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(variant.product_price, "{{amount}}") + " </div>"); 2049 } else { 2050 $("#price-preview").html("<div class=\"product-price\">" + window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(variant.product_price, "{{amount}}") + " </div>"); 2051 } 2052 } 2053 2054 $("#StoreCartProductVariantId").val(variant.id); 2055 2056 $("#product-sku").html(variant.sku); 2057 2058 var totalStock = $("label#instock"); 2059 2060 if (typeof totalStock != 'undefined') { 2061 totalStock.html("0 in stock"); 2062 } 2063 2064 var earnRewardPoints = $("span#earn_reward_points"); 2065 if (typeof earnRewardPoints != 'undefined') { 2066 earnRewardPoints.html(variant.earn_reward_points); 2067 } 2068 2069 var spendRewardPoints = $("span#spend_reward_points"); 2070 if (typeof spendRewardPoints != 'undefined') { 2071 spendRewardPoints.html(variant.spend_reward_points); 2072 } 2073 } else { 2074 $("#price-preview").text("Unavailable"); 2075 $("#StoreCartProductVariantId").val(0); 2076 } 2077 } 2078 2079 if(variant !== null) { 2080 Theme.Utils.Product.setShippingDate(variant); 2081 if(parseInt(window.Store.AppConfig.is_gold_rate) == 1) { 2082 console.log("S " + variant.product_id + " " + variant.id); 2083 Theme.Utils.Product.getProductComponentPrice(variant.product_id, variant.id); 2084 } 2085 } 2086 2087 //Reset Quantity 2088 //$(".quantity").val(1); 2089 $("div#diverror").hide().find(".label-danger").html(""); 2090 }, 2091 setShippingDate: function(variant) { 2092 var Language = (typeof window.app.BRAND_STORE_LANGUAGE !== 'undefined') ? window.app.BRAND_STORE_LANGUAGE : "en"; 2093 var Translator = new Theme.Language.ParseLanguage(Language); 2094 2095 //Set Estimated Shipping Days IN case track inventory true, Quantity in stock is Zero and allow_purchase is true 2096 if ($("#estimated_shipping_days").length > 0) { 2097 if (Theme.ProductData.product.track_inventory && parseInt(variant.actual_quantity) == 0 && Theme.ProductData.product.allow_purchase) { 2098 shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 2099 } else { 2100 shipping_days = Theme.ProductData.product.estimated_shipping_days; 2101 } 2102 2103 // if($("#estimated_shipping_days").parent("div.freeship-panel").length == 0) { 2104 // shipping_days += (parseInt(shipping_days) > 1) ? " days" : " day"; 2105 // } 2106 shipping_days = (parseInt(shipping_days) == 1) ? "24 hours" : shipping_days + " business days."; 2107 $("#estimated_shipping_days").html(shipping_days); 2108 } 2109 2110 if ($("#estimated_dispateched_date").length > 0) { 2111 if (Theme.ProductData.product.track_inventory == 1 && Theme.ProductData.product.allow_purchase == 0 ){ 2112 if (parseInt(variant.quantity) > 0) { 2113 var shipping_days = Theme.ProductData.product.estimated_shipping_days; 2114 } else { 2115 var shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 2116 } 2117 } else if (Theme.ProductData.product.track_inventory == 1 && Theme.ProductData.product.allow_purchase == 1 ){ 2118 if (parseInt(variant.quantity) > 0 && parseInt(variant.quantity) != 999999) { 2119 var shipping_days = Theme.ProductData.product.estimated_shipping_days; 2120 } else { 2121 var shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 2122 } 2123 } 2124 2125 var month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 2126 var date = new Date(); 2127 date.setDate(date.getDate() + (parseInt(shipping_days) - 1)); 2128 var dispatch_day1 = date.getDate() +" "+ month_names[date.getMonth()];
2129 2130 var date = new Date(); 2131 date.setDate(date.getDate() + (parseInt(shipping_days) + 1)); 2132 var dispatch_day2 = date.getDate() +" "+ month_names[date.getMonth()]; 2133 2134 $("#estimated_dispateched_date").html(dispatch_day1+"-"+dispatch_day2); 2135 } 2136 2137 if ($("#estimated_delivered_date").length > 0) { 2138 if (Theme.ProductData.product.track_inventory == 1 && Theme.ProductData.product.allow_purchase == 0 ){ 2139 if (parseInt(variant.quantity) > 0) { 2140 var shipping_days = Theme.ProductData.product.estimated_shipping_days; 2141 } else { 2142 var shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 2143 } 2144 } else if (Theme.ProductData.product.track_inventory == 1 && Theme.ProductData.product.allow_purchase == 1 ){ 2145 if (parseInt(variant.quantity) > 0 && parseInt(variant.quantity) != 999999) { 2146 var shipping_days = Theme.ProductData.product.estimated_shipping_days; 2147 } else { 2148 var shipping_days = Theme.ProductData.product.estimated_outofstock_shipping_days; 2149 } 2150 } 2151 2152 var month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 2153 var date1 = new Date(); 2154 date1.setDate(date1.getDate() + (parseInt(shipping_days) + 7)); 2155 var dispatch_day1 = date1.getDate() +" "+ month_names[date1.getMonth()]; 2156 2157 var date2 = new Date(); 2158 date2.setDate(date2.getDate() + (parseInt(shipping_days) + 9)); 2159 var dispatch_day2 = date2.getDate() +" "+ month_names[date2.getMonth()]; 2160 2161 $("#estimated_delivered_date").html(dispatch_day1+"-"+dispatch_day2); 2162 } 2163 2164 if($("#estimated_shipping_days_msg").length > 0) { 2165 let estimated_shipping_days = estimated_outofstock_shipping_days = 0; 2166 let estimated_shipping_days_minus_1 = estimated_shipping_days_plus_1 = 0; 2167 let estimated_outofstock_shipping_weeks_minus_1 = estimated_outofstock_shipping_weeks_plus_1 = 0; 2168 let estimated_shipping_days_msg = ''; 2169 let input_quantity = ($("input#quantity").length > 0) ? $("input#quantity").val() : 1; 2170 2171 if (Theme.ProductData.product.track_inventory == 1 && parseInt(Theme.ProductData.product.allow_purchase) == 0) { 2172 if (parseInt(variant.quantity) > 0) { 2173 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 2174 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 2175 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 2176 2177 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 2178 $("button.add-to-cart, button.btncart").removeClass("disabled btn-outstock").attr("disabled", false).html(Theme.Language.getStr("AddToCart")); 2179 $("button.btn-buynow").removeClass("disabled").attr("disabled", false).text(Theme.Language.getStr("BuyNow")).show(); 2180 } else { 2181 // estimated_outofstock_shipping_days = parseInt(Theme.ProductData.product.estimated_outofstock_shipping_days); 2182 // estimated_outofstock_shipping_weeks = Math.round(estimated_outofstock_shipping_days / 7); 2183 // estimated_outofstock_shipping_weeks_minus_1 = parseInt(estimated_outofstock_shipping_weeks) - 1; 2184 // estimated_outofstock_shipping_weeks_plus_1 = parseInt(estimated_outofstock_shipping_weeks) + 1; 2185 2186 // estimated_shipping_days_msg = "Made to Order (Ships in "+ estimated_outofstock_shipping_weeks_minus_1 +" to "+ estimated_outofstock_shipping_weeks_plus_1 +" weeks)"; 2187 $("button.add-to-cart, button.btncart").addClass("disabled btn-outstock").attr("disabled", true).text(Theme.Language.getStr("SoldOut")); 2188 $("button.btn-buynow").removeClass("disabled").attr("disabled", true).text(Theme.Language.getStr("SoldOut")).hide(); 2189 } 2190 } else if (Theme.ProductData.product.track_inventory == 1 && Theme.ProductData.product.allow_purchase == 1) { 2191 //if (parseInt(variant.quantity) > 0 && parseInt(variant.quantity) != 999999) { 2192 if (parseInt(variant.actual_quantity) >= parseInt(input_quantity)) { 2193 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 2194 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 2195 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 2196 2197 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 2198 $("button.add-to-cart,button.btncart").removeClass("disabled btn-outstock").attr("disabled", false).html(Theme.Language.getStr("AddToCart")); 2199 $("button.btn-buynow").removeClass("disabled").attr("disabled", false).text(Theme.Language.getStr("BuyNow")).show(); 2200 } else { 2201 if(parseInt(window.Store.StoreConfig.id) == 4038) { 2202 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 2203 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 2204 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 2205 2206 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 2207 $("button.add-to-cart,button.btncart").removeClass("disabled btn-outstock").attr("disabled", false).html(Theme.Language.getStr("AddToCart")); 2208 $("button.btn-buynow").removeClass("disabled").attr("disabled", false).text(Theme.Language.getStr("BuyNow")).show(); 2209 } else { 2210 estimated_outofstock_shipping_days = parseInt(Theme.ProductData.product.estimated_outofstock_shipping_days); 2211 estimated_outofstock_shipping_weeks = Math.round(estimated_outofstock_shipping_days / 7); 2212 estimated_outofstock_shipping_weeks_minus_1 = parseInt(estimated_outofstock_shipping_weeks) - 1; 2213 estimated_outofstock_shipping_weeks_plus_1 = parseInt(estimated_outofstock_shipping_weeks) + 1; 2214 2215 estimated_shipping_days_msg = "Made to Order (Ships in "+ estimated_outofstock_shipping_weeks_minus_1 +" to "+ estimated_outofstock_shipping_weeks_plus_1 +" weeks)"; 2216 $("button.add-to-cart,button.btncart").removeClass("disabled btn-outstock").attr("disabled", false).text(Theme.Language.getStr("MadeToOrder")); 2217 } 2218 } 2219 } else if (Theme.ProductData.product.track_inventory == 0 && Theme.ProductData.product.allow_purchase == 0) { 2220 estimated_shipping_days = parseInt(Theme.ProductData.product.estimated_shipping_days); 2221 estimated_shipping_days_minus_1 = (parseInt(estimated_shipping_days) > 1) ? parseInt(estimated_shipping_days) - 1 : 1; 2222 estimated_shipping_days_plus_1 = parseInt(estimated_shipping_days) + 1; 2223 2224 estimated_shipping_days_msg = "Ready to Ship (Ships in "+ estimated_shipping_days_minus_1 +" to "+ estimated_shipping_days_plus_1 +" days)"; 2225 //$("button.add-to-cart,button.btncart").removeClass("disabled btn-outstock").attr("disabled", false).html(Theme.Language.getStr("AddToCart")); 2226 $("button.add-to-cart").removeClass("disabled btn-outstock").attr("disabled", false).html(Theme.Language.getStr("AddToCart")); 2227 $("button.btn-buynow").removeClass("disabled").attr("disabled", false).text(Theme.Language.getStr("BuyNow")).show(); 2228 } 2229 2230 $("#estimated_shipping_days_msg").html(estimated_shipping_days_msg); 2231 } 2232 }, 2233 getProductComponentPrice: function(ProductId, ProductVariantId) { 2234 if (this._isFetching) return; // Prevent multiple calls 2235 2236 if (ProductId != 'undefined' && ProductVariantId != 'undefined') { 2237 this._isFetching = true; // Lock 2238 2239 var FormData = "product_id=" + ProductId + "&product_variant_id=" + ProductVariantId; 2240 $.ajax({
2241 type: "POST", 2242 async: true, 2243 cache: false, 2244 url: "/store_products/get_components_by_product_id", 2245 dataType: "html", 2246 data: FormData, 2247 complete: function() { 2248 this._isFetching = false; // Unlock after request completes 2249 }.bind(this), 2250 success: function(response) { 2251 if (response.length > 0) { 2252 let strHTML = $("<div>").html(response); 2253 let div1 = strHTML.find("#div1").html(); 2254 let div2 = strHTML.find("#div2").html(); 2255 $('#goldItemDiv').html(div1); 2256 $('#priceBreakupDiv').html(div2); 2257 } 2258 }, 2259 error: function(jqXHR, textStatus, errorThrown) { 2260 console.log(jqXHR.responseText); 2261 if (jqXHR.status == 500) { 2262 alert('Internal error: ' + jqXHR.responseText); 2263 } 2264 } 2265 }); 2266 } 2267 }, 2268 socialSharing: function() { 2269 $('.prettySocial').prettySocial(); 2270 }, 2271 setNotify: function() { 2272 $("#btnnotify").on("click", function(event) { 2273 event.preventDefault(); 2274 2275 if($("form#StoreCartIndexForm").length > 0) { 2276 var product_variant_id = $("form#StoreCartIndexForm").find("input#StoreCartProductVariantId").val(); 2277 } else if($("form#StoreCartAddForm").length > 0) { 2278 var product_variant_id = $("form#StoreCartAddForm").find("input#StoreCartProductVariantId").val(); 2279 } 2280 2281 $("form#StoreProductNotifyIndexForm").find("input#product_variant_id").val(product_variant_id); 2282 //return false; 2283 }); 2284 2285 $("button#btnnotifysubmit").on("click", function(event) { 2286 //Stop the form from submitting the normal way and refreshing the page 2287 event.preventDefault(); 2288 2289 let FormID = $(this).closest("form").attr('id'); 2290 2291 let ProductId = $("form#" + FormID).find("input#id").val(); 2292 let ProductVariantId = $("form#" + FormID).find("input#product_variant_id").val(); 2293 let FullName = $("form#" + FormID).find("input#full_name").val(); 2294 let Email = $("form#" + FormID).find("input#email").val(); 2295 let MobileNo = $("form#" + FormID).find("input#mobile_no").val(); 2296 let CustomerID = $("form#" + FormID).find("input#customer_id").val(); 2297 2298 if(typeof window.googleRecaptchaSiteKey !== 'undefined') { 2299 if (typeof fired === 'undefined') { 2300 var fired = false; 2301 var recaptchaScript = document.createElement('script'); 2302 recaptchaScript.src = 'https://www.google.com/recaptcha/api.js?render='+ window.googleRecaptchaSiteKey; 2303 recaptchaScript.defer = true; 2304 document.body.appendChild(recaptchaScript); 2305 fired = true; 2306 } 2307 2308 setTimeout(function() { 2309 grecaptcha.ready(function () { 2310 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'notify_available'}).then(function (token) { 2311 $("form#" + FormID).find('input#recaptcha_response_notify').val(token); 2312 }); 2313 }); 2314 }, 1000); 2315 } 2316 2317 2318 2319 setTimeout(function () { 2320 let RecaptchaResponse = $("form#" + FormID).find('input#recaptcha_response_notify').val(); 2321 let FormData = "data[Product][id]=" + ProductId + "&data[Product][product_variant_id]=" + ProductVariantId + "&data[Product][full_name]=" + FullName + "&data[Product][email]=" + Email + "&data[Product][mobile_no]=" + MobileNo + "&data[Product][customer_id]=" + CustomerID + "&data[Product][recaptcha_response]=" + RecaptchaResponse + ""; 2322 if (FullName.length == 0 || Email.length == 0 || MobileNo.length == 0) { 2323 alert("Please fill all required information"); 2324 return false; 2325 } else { 2326 $.ajax({
2327 type: "POST", 2328 async: true, 2329 cache: false, 2330 url: "/store_products/notify", 2331 accepts: 'application/json', 2332 dataType: "json", 2333 data: FormData, 2334 beforeSend: function(XMLHttpRequest) { 2335 $("button#btnnotifysubmit").addClass("disabled").attr("disabled", "disabled"); 2336 }, 2337 complete: function() { 2338 $("button#btnnotifysubmit").removeClass("disabled").removeAttr("disabled"); 2339 }, 2340 success: function(data, textStatus) { 2341 if (data.notify_status !== undefined && data.notify_status == 1) { 2342 let strHTML = "<p class=\"text-success h5\">You asked to notify you when the product " + data.product_name + " in our store.</p> \r\n"; 2343 strHTML = strHTML + "<p>Thanks for your interest in our products.</p>"; 2344 $('#notifyModalBody').html(strHTML); 2345 $("button#btnnotifysubmit").addClass("hidden"); 2346 setTimeout(function() { 2347 $("#btnnotifyclose").trigger("click"); 2348 }, 2000); 2349 } else { 2350 let strHTML = "<p class=\"text-danger\">There was an error while processing your request. Please try again.</p>"; 2351 $('#notifyModalBody').prepend(strHTML); 2352 } 2353 }, 2354 error: function(jqXHR, textStatus, errorThrown) { 2355 console.log(jqXHR.responseText); 2356 if (jqXHR.status == 500) { 2357 alert('Internal error: ' + jqXHR.responseText); 2358 } 2359 } 2360 }); 2361 } 2362 }, 2000); 2363 return false; //stop the actual form post !important! 2364 }); 2365 }, 2366 setAttributes: function() { 2367 $(document).on("click", ".swatches-title a", function(event) { 2368 event.preventDefault(); 2369 var attributeId = $(this).data("attributeId"); 2370 var slideID = $(this).data('slideId'); 2371 $('.swatches-details').each(function() { 2372 if (parseInt($(this).data("attributeId")) == parseInt(attributeId)) { 2373 $(this).css('display', "block"); 2374 } else { 2375 $(this).css('display', "none"); 2376 } 2377 }); 2378 $("#swatch_details_" + attributeId + " li#" + slideID).show().siblings("li").hide(); 2379 $("#swatchesModal" + attributeId + "").modal('show'); 2380 return false; 2381 }); 2382 2383 2384 $(document).on("click", ".swatches a", function(event) { 2385 event.preventDefault(); 2386 var attributeId = $(this).data("attributeId"); 2387 $('.swatches-details').each(function() { 2388 if (parseInt($(this).data("attributeId")) == parseInt(attributeId)) { 2389 $(this).css('display', "block"); 2390 } else { 2391 $(this).css('display', "none"); 2392 } 2393 }); 2394 2395 //$('html,body').animate({ scrollTop: $("#swatch_details_"+ attributeId +"").offset().top - 190}, 1000); 2396 var slideID = $(this).attr('id'); 2397 //$(this).next("#swatch_details li#"+slideID).show().siblings("li").hide(); 2398 $("#swatch_details_" + attributeId + " li#" + slideID).show().siblings("li").hide(); 2399 $("#swatchesModal" + attributeId + "").modal('show'); 2400 return false; 2401 }); 2402 2403 $(".swatches-details a#next").on("click", function() { 2404 if ($(".swatches-details ul li.newboxes:visible").next().length != 0) { 2405 $(".swatches-details ul li.newboxes:visible").next().show().prev().hide(); 2406 } else { 2407 $(".swatches-details ul li.newboxes:visible").hide(); 2408 $(".swatches-details ul li.newboxes:first").show(); 2409 } 2410 return false; 2411 }); 2412 2413 $(".swatches-details a#prev").on("click", function() { 2414 if ($(".swatches-details ul li.newboxes:visible").prev().length != 0) 2415 $(".swatches-details ul li.newboxes:visible").prev().show().next().hide(); 2416 else { 2417 $(".swatches-details ul li.newboxes:visible").hide(); 2418 $(".swatches-details ul li.newboxes:last").show(); 2419 } 2420 return false; 2421 }); 2422 2423 $("a#btn_swatch_close").on('click', function(event) { 2424 event.preventDefault(); 2425 $("div.swatches-details").hide(); 2426 }); 2427 }, 2428 setReview: function() { 2429 $('#rating').rating({ 2430 min: 1, 2431 max: 5, 2432 step: 1, 2433 size: 'xs', 2434 showCaption: false, 2435 showClear: false 2436 }); 2437 2438 $('#rating-input').on('rating.change', function() { 2439 alert($('#rating-input').val()); 2440 }); 2441 2442 $("#StoreProductReviewIndexForm").validate({ 2443 ignore: [], 2444 errorPlacement: function(error, element) { 2445 if (element.parent('.rating-container').length) { 2446 error.insertAfter(element.parent('.rating-container')); 2447 } else { 2448 error.insertAfter(element); 2449 } 2450 }, 2451 submitHandler: function(form) { 2452 var ProductId = $(form).find("input#id").val(); 2453 var CustomerId = $(form).find("input#customer_id").val(); 2454 var FullName = $(form).find("input#full_name").val(); 2455 var Email = $(form).find("input#email").val(); 2456 var Subject = $(form).find("input#subject").val(); 2457 var Comment = $(form).find("textarea#comment").val(); 2458 var Rating = $(form).find("input#rating").val(); 2459 var ReviewImages = $(form).find("input#review_images").val(); 2460 var FormData = "data[Product][id]=" + ProductId + "&data[Product][customer_id]=" + CustomerId + "&data[Product][full_name]=" + FullName + "&data[Product][email]=" + Email + "&data[Product][subject]=" + Subject + "&data[Product][comment]=" + Comment + "&data[Product][rating]=" + Rating + "&data[Product][review_images]=" + ReviewImages + ""; 2461 //var FormData = "data[Product][id]=" + ProductId + "&data[Product][customer_id]=" + CustomerId + "&data[Product][full_name]=" + FullName + "&data[Product][email]=" + Email + "&data[Product][subject]=" + Subject + "&data[Product][comment]=" + Comment + "&data[Product][rating]=" + Rating + ""; 2462 2463 $.ajax({
2464 type: "POST", 2465 async: true, 2466 cache: false, 2467 url: "/store_products/review", 2468 accepts: 'application/json', 2469 dataType: "json", 2470 data: FormData, 2471 beforeSend: function(XMLHttpRequest) { 2472 $("button#btnreviewsubmit").addClass("disabled").attr("disabled", "disabled"); 2473 }, 2474 complete: function() { 2475 $(form).trigger("reset"); 2476 //$('html,body').animate({ scrollTop: $("#divreview").offset().top - 60}, 1000); 2477 $("button#btnreviewsubmit").removeClass("disabled").removeAttr("disabled"); 2478 $("#reviewform").toggle(); 2479 }, 2480 success: function(data, textStatus) { 2481 if (data.review_status !== undefined && data.review_status == 1) { 2482 $("#review_err").hide(); 2483 $("#review_success").show(); 2484 } else { 2485 $("#review_err").show(); 2486 $("#review_success").hide(); 2487 } 2488 }, 2489 error: function(jqXHR, textStatus, errorThrown) { 2490 console.log(jqXHR); 2491 if (jqXHR.status == 500) { 2492 alert('Internal error: ' + jqXHR.responseText); 2493 } 2494 } 2495 }); 2496 return false; // blocks redirect after submission via ajax 2497 } 2498 }); 2499 2500 $(".reviewscroll").click(function() { 2501 $("html,body").animate({ 2502 scrollTop: $(".review-rate-block").offset().top 2503 }, "slow"), $('[href="#reviewtab"]').tab("show") 2504 }), $(".product-desc-tab ul.nav a").click(function() { 2505 window.location.hash = this.hash 2506 }), $("#show-password").click(function() { 2507 $(this).hasClass("fa-eye") ? ($("#password").attr("type", "text"), $(this).removeClass("fa-eye"), $(this).addClass("fa-eye-slash")) : ($("#password").attr("type", "password"), $(this).removeClass("fa-eye-slash"), $(this).addClass("fa-eye")) 2508 }); 2509 2510 var a = window.location.hash; 2511 if($(".product-desc-tab").length > 0) { 2512 "" != a && ($("html,body").animate({ 2513 scrollTop: $(".product-desc-tab").offset().top 2514 }, "slow"), $('ul.nav a[href="' + a + '"]').tab("show")); 2515 } 2516 2517 var b = []; 2518 2519 $("body").on("change", ".picupload", function(a) { 2520 if (b.length < 5) 2521 for (var c = a.target.files, f = (document.getElementById("media-list"), 0); f < c.length; f++) { 2522 var g = c[f], 2523 h = new FileReader, 2524 i = new FormData; 2525 i.append("data[Product][image_file]", g), $.ajax({ 2526 type: "POST", 2527 url: "/store_products/review_images", 2528 accepts: "application/json", 2529 dataType: "json", 2530 cache: !1, 2531 async: !1, 2532 processData: !1, 2533 contentType: !1, 2534 data: i, 2535 beforeSend: function() {}, 2536 complete: function() {}, 2537 success: function(a) { 2538 "undefined" !== typeof a.review_status && 1 == a.review_status ? (b.push(a.message), h.fileName = g.name, h.fileName = h.fileName.replace(/\_/g, ""), h.addEventListener("load", function(a) { 2539 var b = a.target, 2540 c = document.createElement("li"); 2541 c.innerHTML = "<img src='" + b.result + "'title='" + h.fileName + "'/><div class='post-thumb'><div class='inner-post-thumb'><a href='javascript:void(0);' data-id='" + a.target.fileName + "' class='remove-pic'><i class='fa fa-times' aria-hidden='true'></i></a><div></div>", $("#media-list").prepend(c) 2542 }), h.readAsDataURL(g), console.log(a)) : ("undefined" !== typeof a.review_status || "failure" === a.review_status || 0 === a.review_status) && (console.log(a), alert(a.message)) 2543 }, 2544 error: function(a) { 2545 console.log(a) 2546 } 2547 }) 2548 } else alert("You can upload maximum 5 photos."); 2549 $("#review_images").val(JSON.stringify(b)) 2550 }); 2551 2552 $("body").on("click", ".remove-pic", function() { 2553 $(this).parent().parent().parent().remove(); 2554 var a = $(this).attr("data-id"), 2555 c = b.indexOf(a); - 1 != c && b.splice(c, 1), $("#review_images").val(JSON.stringify(b)) 2556 }); 2557 }, 2558 getReviews: function() { 2559 setTimeout(function() { 2560 let queryString = ''; 2561 let product_id = Theme.ProductData.product.id; 2562 queryString = "product_id="+ product_id; 2563 Theme.Utils.Product.ajaxReviews(queryString); 2564 }, 1000); 2565 2566 $("ul.pagination").find("a").on("click", function(event){ 2567 event.preventDefault(); 2568 event.stopImmediatePropagation(); 2569 let queryString = $(this).prop('href').split("?")[1]; 2570 2571 Theme.Utils.Product.ajaxReviews(queryString); 2572 }); 2573 }, 2574 ajaxReviews: function(queryString) { 2575 if(queryString.indexOf('product_id') != -1) { 2576 $.ajax({
2577 type: "GET", 2578 async: !0, 2579 cache: !1, 2580 url: "/store_product_reviews/list_view?" + queryString, 2581 dataType: "html", 2582 data: FormData, 2583 beforeSend: function() {}, 2584 success: function(responseHtml) { 2585 $('div#divreview').html(responseHtml); 2586 }, 2587 error: function(a) { 2588 alert(500 == a.status ? "Internal error: " + a.responseText : "Unexpected error.") 2589 } 2590 }).done(function() { 2591 Theme.Utils.PhotoGallery.initPhotoGallery(); 2592 }); 2593 } 2594 }, 2595 checkCODAvailable: function() { 2596 $("button#btncodsubmit").on("click", function(event) { 2597 event.stopImmediatePropagation(); 2598 event.preventDefault(); 2599 2600 var pincode = $(this).closest("form").find("input#cod_pincode").val(); 2601 $('.cod_error').css({ 2602 'display': 'none' 2603 }); 2604 $('#cod_message').html(''); 2605 2606 if (pincode === '') { 2607 $('#cod_pincode').val('').addClass('required').attr('placeholder', 'Enter valid pincode'); 2608 $('.cod_error').css({ 2609 'display': 'block' 2610 }); 2611 return false; 2612 } 2613 if (pincode.length < 6) { 2614 $('#cod_pincode').val('').addClass('required').attr('placeholder', 'Enter valid pincode'); 2615 $('.cod_error').css({ 2616 'display': 'block' 2617 }); 2618 return false; 2619 } 2620 if (pincode.length > 8) { 2621 $('#cod_pincode').val('').addClass('required').attr('placeholder', 'Enter valid pincode'); 2622 $('.cod_error').css({ 2623 'display': 'block' 2624 }); 2625 return false; 2626 } 2627 if (isNaN(pincode)) { 2628 $('#cod_pincode').val('').addClass('required').attr('placeholder', 'Enter valid pincode'); 2629 $('.cod_error').css({ 2630 'display': 'block' 2631 }); 2632 return false; 2633 } 2634 2635 var ajaxLoading = false; 2636 2637 if (!ajaxLoading) { 2638 ajaxLoading = true; 2639 2640 var CODPincode = $(this).closest("form").find("input#cod_pincode").val(); 2641 var cod_enable = $(this).closest("form").find("input#cod_enable").val(); 2642 var delivery_enable = $(this).closest("form").find("input#delivery_enable").val(); 2643 var assembly_enable = $(this).closest("form").find("input#assembly_enable").val(); 2644 2645 if($(this).closest("form").find("input#product_estimated_shipping_days").length > 0) { 2646 var product_estimated_shipping_days = parseInt($(this).closest("form").find("input#product_estimated_shipping_days").val()); 2647 } else { 2648 var product_estimated_shipping_days = 0; 2649 } 2650 //console.log(product_estimated_shipping_days); 2651 2652 var FormData = "data[shipping_pincode]=" + CODPincode + "&data[assembly_enable]=" + assembly_enable + "&data[product_estimated_shipping_days]=" + product_estimated_shipping_days + ""; 2653 2654 $.ajax({
2655 type: "POST", 2656 async: true, 2657 cache: false, 2658 url: "/store_orders/check_delivery_cod_available", 2659 accepts: 'application/json', 2660 dataType: "json", 2661 data: FormData, 2662 beforeSend: function(XMLHttpRequest) { 2663 $("button#btncodsubmit").addClass("disabled").attr("disabled", "disabled"); 2664 }, 2665 complete: function() { 2666 ajaxLoading = false; 2667 $("button#btncodsubmit").removeClass("disabled").removeAttr("disabled"); 2668 }, 2669 success: function(data, textStatus) { 2670 var strHTML = "<div class=\"cod_message_panel\">\r\n"; 2671 strHTML = strHTML + "<div class=\"row\">\r\n"; 2672 if(data.delivery_status !== undefined && data.delivery_status == 1 ) { 2673 if(parseInt(delivery_enable) == 1 && parseInt(cod_enable) == 1) { 2674 if(data.assembly_status == 1) { 2675 strHTML = strHTML + "<div class=\"col-md-12 col-sm-12 col-xs-12\"><strong>Delivery & Assembly Services</strong> <br/> This item can be available for <span class=\"text-success\">Delivered & Assembly</span> Services</div>\r\n"; 2676 } else { 2677 strHTML = strHTML + "<div class=\"col-md-6 col-sm-12 col-xs-12\"><strong>Delivery</strong> <br/> This item can be <span class=\"text-success\">Delivered</span> to your location.</div>\r\n"; 2678 } 2679 } else if(parseInt(delivery_enable) == 1) { 2680 if(data.assembly_status == 1) { 2681 strHTML = strHTML + "<div class=\"col-md-12 col-sm-12 col-xs-12\"><strong>Delivery & Assembly Services</strong> <br/> This item can be available for <span class=\"text-success\">Delivered & Assembly</span> to your location.</div>\r\n"; 2682 } else { 2683 strHTML = strHTML + "<div class=\"col-md-6 col-sm-12 col-xs-12\"><strong>Delivery</strong> <br/> This item can be <span class=\"text-success\">Delivered</span> to your location.</div>\r\n"; 2684 } 2685 } 2686 2687 if(parseInt(cod_enable) == 1) { 2688 if(data.cod_status !== undefined && data.cod_status == 1) { 2689 strHTML = strHTML + "<div class=\"col-md-6 col-sm-12 col-xs-12\"><strong>COD</strong> <br/> is <span class=\"text-success\">available</span> for this item.</div>\r\n"; 2690 } else { 2691 strHTML = strHTML + "<div class=\"col-md-6 col-sm-12 col-xs-12\"><strong>COD</strong> <br/> is <span class=\"text-danger\">not available</span> for this item.</div>\r\n"; 2692 } 2693 } 2694 } else if(data.assembly_status == 1) { 2695 strHTML = strHTML + "<div class=\"col-md-12 col-sm-12 col-xs-12\"><strong>Assembly services</strong> <br/> is <span class=\"text-success\">available</span> for this item.</div>\r\n"; 2696 } else { 2697 strHTML = strHTML + "<div class=\"col-md-12 col-sm-12 col-xs-12\"><strong>Delivery</strong> <br/> <span class=\"text-danger\">This item can't be delivered to your location.</span></div>\r\n"; 2698 } 2699 2700 if(data.estimated_delivery_date !== undefined && data.estimated_delivery_date !== '') { 2701 strHTML = strHTML + "<div class=\"col-md-6 col-sm-12 col-xs-12\"><strong>Estimated Delivery Date</strong> is <span class=\"text-success\">"+ data.estimated_delivery_date +"</span> for this item.</div>\r\n"; 2702 } 2703 2704 strHTML = strHTML + "</div>"; 2705 strHTML = strHTML + "</div>"; 2706 2707 $('#cod_message').html(strHTML); 2708 }, 2709 error: function(jqXHR, textStatus, errorThrown) { 2710 console.log(jqXHR); 2711 if (jqXHR.status == 500) { 2712 alert('Internal error: ' + jqXHR.responseText); 2713 } 2714 } 2715 }); 2716 } 2717 //return false; //stop the actual form post !important! 2718 }); 2719 }, 2720 saveWishlist: function() { 2721 $("#btn-addtowishlist").on("click", function(event) { 2722 // event.preventDefault(); 2723 var ProductId = $(this).data("product-id"); 2724 var LoggedIn = $(this).data("logged-in"); 2725 2726 if (LoggedIn == "" || LoggedIn == 0) { 2727 alert("Please login"); 2728 //window.location("/customers/login") ; 2729 //return 2730 } else { 2731 var FormData = "data[Product][id]=" + ProductId + ""; 2732 $.ajax({
2733 type: "POST", 2734 async: true, 2735 cache: false, 2736 url: "/store_products/wishlist", 2737 accepts: 'application/json', 2738 dataType: "json", 2739 data: FormData, 2740 beforeSend: function(XMLHttpRequest) { 2741 // $("button#btnreviewsubmit").addClass("disabled").attr("disabled", "disabled"); 2742 }, 2743 complete: function() { 2744 // $('html,body').animate({ scrollTop: $("#divreview").offset().top - 60}, 1000); 2745 // $("button#btnreviewsubmit").removeClass("disabled").removeAttr("disabled"); 2746 }, 2747 success: function(data, textStatus) { 2748 // console.log(data); 2749 if (data.wishlist_status !== undefined && data.wishlist_status == 1) { 2750 $("#span-add-to-wishlist").hide(); 2751 $("#span-added-to-wishlist").show(); 2752 2753 //$("#wishlist_err").hide(); 2754 //$("#wishlist_success").show(); 2755 } else { 2756 $("#span-add-to-wishlist").show(); 2757 $("#span-added-to-wishlist").hide(); 2758 2759 //$("#wishlist_err").show(); 2760 //$("#wishlist_success").hide(); 2761 } 2762 }, 2763 error: function(jqXHR, textStatus, errorThrown) { 2764 //console.log(errorThrown); 2765 if (jqXHR.status == 500) { 2766 alert('Internal error: ' + jqXHR.responseText); 2767 } 2768 } 2769 }).done(function(data) { 2770 Conversion.Utils.setConversion('AddToWishlist'); 2771 }); 2772 return false; // blocks redirect after submission via ajax 2773 } 2774 }); 2775 }, 2776 saveAjax: function() { 2777 $(document).on("click", "button.add-to-cart", function(event) { 2778 $("#StoreCartAddForm").validate(); 2779 event.preventDefault(); 2780 if (parseInt(Theme.ProductData.product.variants.length) == 0 && parseInt(Theme.ProductData.product.minimum_order_quantity) > 0) { 2781 if ($(this).closest('form').find("input#quantity").val() < parseInt(Theme.ProductData.product.minimum_order_quantity)) { 2782 $("div#diverror").show().find(".label-danger").html("Minimum order quantity must be " + parseInt(Theme.ProductData.product.minimum_order_quantity)); 2783 return false; 2784 } else { 2785 $("div#diverror").hide(); 2786 } 2787 } else { 2788 $("div#diverror").hide(); 2789 } 2790 2791 //Check Variant Quantity 2792 var allowAdd = 1; 2793 var quickView = $(this).data("quickView"); 2794 var currValues = Theme.Utils.Product.selectedValues(); // get current values 2795 var variant = Theme.Utils.Product.getVariant(currValues); 2796 var inputQuantity = $("form#StoreCartIndexForm").find("input#quantity").val(); 2797 2798 if ((variant && !variant.available) || (variant && variant.available && Theme.ProductData.product.track_inventory && !Theme.ProductData.product.allow_purchase && (parseFloat(variant.quantity) < parseFloat(inputQuantity)))) { 2799 allowAdd = 0; 2800 } else if (Theme.ProductData.product.options.length == 0) { 2801 if (Theme.ProductData.product.available == false || (Theme.ProductData.product.available && Theme.ProductData.product.track_inventory && !Theme.ProductData.product.allow_purchase && (parseFloat(Theme.ProductData.product.quantity) < parseFloat(inputQuantity)))) { 2802 allowAdd = 0; 2803 } 2804 } 2805 2806 //Now Process To Add 2807 if (parseInt(allowAdd) == 1) { 2808 //Check Form Process 2809 var FormID = $(this).closest("form").attr('id'); 2810 var ProductId = $(this).closest("form").find("input#StoreCartId").val(); 2811 var ProductVariantId = $(this).closest("form").find("input#StoreCartProductVariantId").val(); 2812 var ProductQuantity = $(this).closest("form").find("input#quantity").val(); 2813 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][product_variant_id]=" + ProductVariantId + "&data[StoreCart][quantity]=" + ProductQuantity; 2814 2815 //New Code Developed For Custom Fields 2816 if ($(this).closest("form").find("select#title").length > 0 && $(this).closest("form").find("select#title").is(":visible")) { 2817 FormData = FormData + "&data[StoreCart][title]=" + $(this).closest("form").find("select#title").val(); 2818 } 2819 if ($(this).closest("form").find("input#full_name").length > 0 && $(this).closest("form").find("input#full_name").is(":visible")) { 2820 FormData = FormData + "&data[StoreCart][full_name]=" + $(this).closest("form").find("input#full_name").val(); 2821 } 2822 if ($(this).closest("form").find("input#date_of_birth").length > 0 && $(this).closest("form").find("input#date_of_birth").is(":visible")) { 2823 FormData = FormData + "&data[StoreCart][date_of_birth]=" + $(this).closest("form").find("input#date_of_birth").val(); 2824 } 2825 if ($(this).closest("form").find("input#time_of_birth").length > 0 && $(this).closest("form").find("input#time_of_birth").is(":visible")) { 2826 FormData = FormData + "&data[StoreCart][time_of_birth]=" + $(this).closest("form").find("input#time_of_birth").val(); 2827 } 2828 if ($(this).closest("form").find("input#place_of_birth").length > 0 && $(this).closest("form").find("input#place_of_birth").is(":visible")) { 2829 FormData = FormData + "&data[StoreCart][place_of_birth]=" + $(this).closest("form").find("input#place_of_birth").val(); 2830 } 2831 if ($(this).closest("form").find("select#gender").length > 0 && $(this).closest("form").find("select#gender").is(":visible")) { 2832 FormData = FormData + "&data[StoreCart][gender]=" + $(this).closest("form").find("select#gender").val(); 2833 } 2834 if ($(this).closest("form").find("select#marital_status").length > 0 && $(this).closest("form").find("select#marital_status").is(":visible")) { 2835 FormData = FormData + "&data[StoreCart][marital_status]=" + $(this).closest("form").find("select#marital_status").val(); 2836 } 2837 if ($(this).closest("form").find("textarea#other_information").length > 0 && $(this).closest("form").find("textarea#other_information").is(":visible")) { 2838 FormData = FormData + "&data[StoreCart][other_information]=" + $(this).closest("form").find("textarea#other_information").val(); 2839 } 2840 if ($(this).closest("form").find("input#waist").length > 0 && $(this).closest("form").find("input#waist").is(":visible")) { 2841 FormData = FormData + "&data[StoreCart][waist]=" + $(this).closest("form").find("input#waist").val(); 2842 } 2843 if ($(this).closest("form").find("input#hip").length > 0 && $(this).closest("form").find("input#hip").is(":visible")) { 2844 FormData = FormData + "&data[StoreCart][hip]=" + $(this).closest("form").find("input#hip").val(); 2845 } 2846 if ($(this).closest("form").find("input#length").length > 0 && $(this).closest("form").find("input#length").is(":visible")) { 2847 FormData = FormData + "&data[StoreCart][length]=" + $(this).closest("form").find("input#length").val(); 2848 } 2849 2850 $.ajax({
2851 type: "POST", 2852 async: true, 2853 cache: false, 2854 url: "/store_carts/ajax_add", 2855 dataType: "html", 2856 data: FormData, 2857 beforeSend: function(XMLHttpRequest) { 2858 2859 }, 2860 success: function(data, textStatus) { 2861 $("#cd-cart").html(data); 2862 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 2863 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 2864 //Theme.Utils.Home.init(); 2865 /*var body = $("html, body"); 2866 body.animate({scrollTop: 0}, '1000', 'swing'); 2867 $("div#div-drop-cart").empty().append(data).find('.dropdown-menu').first().slideDown('slow').delay(5000).slideUp('fast'); 2868 $("div#div-drop-cart-xs").empty().append(data); 2869 if (parseInt(quickView) == 1) { 2870 $(document).find(".quick-modal-box, .modal-overlay").fadeOut(500, function () { 2871 $(document).find('#quickProduct').find(".quick-modal-body").html(''); 2872 $(document).find(".modal-overlay").remove(); 2873 $(document).find(".modal-backdrop").remove(); 2874 }); 2875 }*/ 2876 }, 2877 error: function(jqXHR, textStatus, errorThrown) { 2878 if (jqXHR.status == 500) { 2879 alert('Internal error: ' + jqXHR.responseText); 2880 } 2881 } 2882 }).done(function(data) { 2883 Conversion.Utils.setConversion('AddToCart', ProductQuantity); 2884 }); 2885 //Stop the form from submitting the normal way and refreshing the page 2886 return false; 2887 } else { 2888 alert("SORRY, THIS VARIANT COMBINATION IS SOLD OUT, PLEASE CHOOSE ANOTHER COMBINATION"); 2889 return false; //stop the actual form post !important! 2890 } 2891 }); 2892 }, 2893 setAddonPrice: function() { 2894 $(".product_addon_value").on("change", function() { 2895 var addonprice = 0; 2896 addonprice = $('.product_addon_value').find(':selected').data('addonprice'); 2897 //$("#div-addon-price").html(window.app.BRAND_STORE_CURRENCY + ' ' + addonprice); 2898 }); 2899 }, 2900 saveAssemblChargeAjax: function() { 2901 $(document).on("click", "button#btnassemblycharge", function(event) { 2902 event.preventDefault(); 2903 if($("#assembly_charges").prop('checked') == true){ 2904 //Check Variant Quantity 2905 var allowAdd = 0; 2906 var ProductId = 0; 2907 ProductId = $("#product_id").val(); 2908 var ProductQuantity = $(this).closest("form").find("input#quantity").val(); 2909 if (ProductId) { 2910 allowAdd = 1; 2911 } else if (!ProductId) { 2912 allowAdd = 0; 2913 } 2914 2915 //Now Process To Add 2916 if (parseInt(allowAdd) == 1) { 2917 //Check Form Process 2918 var FormID = $(this).closest("form").attr('id'); 2919 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][remove]= 0"; 2920 2921 $.ajax({
2922 type: "POST", 2923 async: true, 2924 cache: false, 2925 url: "/store_carts/ajax_assembly_charge", 2926 dataType: "html", 2927 data: FormData, 2928 beforeSend: function(XMLHttpRequest) { 2929 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 2930 }, 2931 success: function(data, textStatus) { 2932 if (data.length > 0 && data.trim() !== "failure") { 2933 //alert("Assembly services added successfully"); 2934 $("#cd-cart").html(data); 2935 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 2936 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 2937 2938 } else { 2939 $('#assembly_charges').prop('checked', false); 2940 alert("Please add this product to your cart before choosing the assembly services."); 2941 } 2942 }, 2943 error: function(jqXHR, textStatus, errorThrown) { 2944 if (jqXHR.status == 500) { 2945 alert('Internal error: ' + jqXHR.responseText); 2946 } 2947 } 2948 }).done(function(data) { 2949 Conversion.Utils.setConversion('AddToCart', ProductQuantity); 2950 }); 2951 2952 // stop the form from submitting the normal way and refreshing the page 2953 return false; 2954 } else { 2955 alert("Sorry, you need to select a addon from the given list"); 2956 ev.preventDefault(); 2957 return false; //stop the actual form post !important! 2958 } 2959 } else { 2960 $("$assembly_message").html("Please check checkbox"); 2961 return false; 2962 } 2963 }); 2964 }, 2965 removeAssemblChargeAjax: function() { 2966 $(document).on("click", ".assembly-charges-remove", function(event) { 2967 //Check Variant Quantity 2968 var allowAdd = 0; 2969 var ProductId = 0; 2970 var ProductvariantId = 0; 2971 var PageId = 0; 2972 ProductId = $(this).data('productid'); 2973 ProductvariantId = $(this).data('productvariantid'); 2974 PageId = $(this).data('pageid'); 2975 var ProductQuantity = $(this).closest("form").find("input#quantity").val(); 2976 if (ProductId) { 2977 allowAdd = 1; 2978 } else if (!ProductId) { 2979 allowAdd = 0; 2980 } 2981 2982 //Now Process To Add 2983 if (parseInt(allowAdd) == 1) { 2984 //Check Form Process 2985 var FormID = $(this).closest("form").attr('id'); 2986 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][productvariantid]=" + ProductvariantId + "&data[StoreCart][remove]= 1"; 2987 2988 $.ajax({
2989 type: "POST", 2990 async: true, 2991 cache: false, 2992 url: "/store_carts/ajax_assembly_charge", 2993 dataType: "html", 2994 data: FormData, 2995 beforeSend: function(XMLHttpRequest) { 2996 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 2997 }, 2998 success: function(data, textStatus) { 2999 if (data.length > 0 && data.trim() !== "failure") { 3000 if(PageId == 1) { 3001 $("#cd-cart").html(data); 3002 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 3003 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 3004 } else if(PageId == 2) { 3005 window.location.reload(); 3006 } 3007 } else { 3008 $('#assembly_charges').prop('checked', false); 3009 alert("Please add this product to your cart before choosing the assembly services."); 3010 } 3011 }, 3012 error: function(jqXHR, textStatus, errorThrown) { 3013 if (jqXHR.status == 500) { 3014 alert('Internal error: ' + jqXHR.responseText); 3015 } 3016 } 3017 }).done(function(data) { 3018 Conversion.Utils.setConversion('AddToCart', ProductQuantity); 3019 }); 3020 3021 // stop the form from submitting the normal way and refreshing the page 3022 return false; 3023 } else { 3024 alert("Sorry, you need to select a addon from the given list"); 3025 ev.preventDefault(); 3026 return false; //stop the actual form post !important! 3027 } 3028 }); 3029 }, 3030 saveAddonAjax: function() { 3031 $("button.btnaddoncart").on("click", function(ev) { 3032 //Check Variant Quantity 3033 var allowAdd = 0; 3034 var ProductId = 0; 3035 var ProductAddonValueId = 0; 3036 ProductId = $("#product_id").val(); 3037 ProductAddonValueId = $("#product_addon_value_id").val(); 3038 3039 if (ProductId && ProductAddonValueId) { 3040 allowAdd = 1; 3041 } else if (!ProductId || !ProductAddonValueId) { 3042 allowAdd = 0; 3043 } 3044 3045 //Now Process To Add 3046 if (parseInt(allowAdd) == 1) { 3047 //Check Form Process 3048 var FormID = $(this).closest("form").attr('id'); 3049 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][product_addon_value_id]=" + ProductAddonValueId; 3050 3051 $.ajax({
3052 type: "POST", 3053 async: true, 3054 cache: false, 3055 url: "/store_carts/ajax_addon", 3056 dataType: "html", 3057 data: FormData, 3058 beforeSend: function(XMLHttpRequest) { 3059 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 3060 }, 3061 success: function(data, textStatus) { 3062 if (data.length > 0 && data.trim() !== "failure") { 3063 alert("Addon added successfully"); 3064 } else { 3065 alert("Please add this product to your cart before choosing the addon."); 3066 } 3067 }, 3068 error: function(jqXHR, textStatus, errorThrown) { 3069 if (jqXHR.status == 500) { 3070 alert('Internal error: ' + jqXHR.responseText); 3071 } 3072 } 3073 }); 3074 3075 // stop the form from submitting the normal way and refreshing the page 3076 return false; 3077 3078 } else { 3079 alert("Sorry, you need to select a addon from the given list"); 3080 ev.preventDefault(); 3081 return false; //stop the actual form post !important! 3082 } 3083 }); 3084 }, 3085 saveMultipleAjax: function() { 3086 $("button.btnattribute").on("click", function(ev) { 3087 ev.preventDefault(); 3088 if ($('.chkproduct:checked').length > 0) { 3089 //Check Form Process 3090 var FormData = $("form#StoreAttributeValueIndexForm").serialize(); 3091 $.ajax({
3092 type: "POST", 3093 async: true, 3094 cache: false, 3095 url: "/store_carts/ajax_multiple_add", 3096 dataType: "html", 3097 data: FormData, 3098 beforeSend: function(XMLHttpRequest) { 3099 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 3100 }, 3101 success: function(data, textStatus) { 3102 if (data.length > 0 && data.trim() !== "failure") { 3103 $("#cd-cart").html(data); 3104 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 3105 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 3106 } 3107 }, 3108 error: function(jqXHR, textStatus, errorThrown) { 3109 if (jqXHR.status == 500) { 3110 alert('Internal error: ' + jqXHR.responseText); 3111 } else { 3112 alert('Unexpected error.'); 3113 } 3114 } 3115 }); 3116 } else { 3117 alert("Please check at least one checkbox"); 3118 } 3119 return false; 3120 }); 3121 }, 3122 setProductQuantity: function() { 3123 // Count Input (Quantity) 3124 //------------------------------------------------------------------------------ 3125 // if(parseInt(window.Store.TemplateConfig.is_b2b_quantity_multiple) == 1) { 3126 // $(document).off("click", ".incr-btn").on("click", ".incr-btn", function(event) { 3127 // event.preventDefault(); 3128 // event.stopPropagation(); // â Add this too 3129 3130 // if ($(this).data("disabled")) { return false; } 3131 3132 // var $button = $(this); 3133 // var $form = $button.closest('form'); 3134 // var $qtyInput = $form.find('.quantity'); 3135 // var is_fabric = $form.find('input.is_fabric').val(); 3136 3137 // // Get increment value from data attribute 3138 // var incval = parseFloat($qtyInput.data("incrementQuantity")) || 1; 3139 // var moq = incval; // minimum order quantity = increment value 3140 3141 3142 // if (parseFloat(is_fabric) == 1) { incval = 0.5; } 3143 3144 // var oldValue = parseFloat($qtyInput.val()) || 0; 3145 // var minValue = parseFloat($qtyInput.attr("min")) || moq; 3146 // var maxValue = parseFloat($qtyInput.data("quantity")); 3147 // var newVal = 0; 3148 // $form.find('.incr-btn[data-action="decrease"]').removeClass('inactive'); 3149 3150 // if(oldValue == moq && $button.data('action') == "decrease") { 3151 // return false; 3152 // } 3153 3154 // if ($button.data('action') == "increase") { 3155 // newVal = oldValue + incval; 3156 3157 // // â Ensure newVal is always a multiple of incval 3158 // newVal = Math.round(newVal / incval) * incval; 3159 3160 // } else { 3161 // // Decrease 3162 // if (oldValue > moq) { 3163 // newVal = oldValue - incval; 3164 3165 // // â Ensure newVal is always a multiple of incval 3166 // newVal = Math.round(newVal / incval) * incval; 3167 3168 // // Ensure not below moq 3169 // if (newVal < moq) { newVal = moq; } 3170 // } else { 3171 // newVal = 0; 3172 // $button.addClass('inactive'); 3173 // } 3174 // } 3175 3176 // // â Round to avoid floating point issues e.g. 0.1 + 0.2 = 0.30000000004 3177 // newVal = parseFloat(newVal.toFixed(2)); 3178 3179 // if (newVal <= maxValue) { 3180 // $("div#diverror").hide().find(".label-danger").html(""); 3181 // $qtyInput.val(newVal); 3182 // $button.data("disabled", false); 3183 // } else { 3184 // $("div#diverror").show().find(".label-danger").html( 3185 // Theme.Language.getStr('MaxOrderQuantityTxt') + parseInt(maxValue) 3186 // ); 3187 // $button.data("disabled", true); 3188 // return false; 3189 // } 3190 3191 // if (parseInt(is_fabric) == 1) { 3192 // let orderQuantity = newVal * 2; 3193 // $form.find('input#quantity').val(orderQuantity); 3194 // } 3195 3196 // // === When new quantity is 0 or below minimum order quantity === 3197 // if (newVal <= 0 || newVal < moq) { 3198 // if ($('.cart-item-remove').length > 0) { 3199 // let targetProductId = $form.find('input[name="data[StoreCart][id]"]').val(); 3200 // let targetProductVariantId = $form.find('input[name="data[StoreCart][product_variant_id]"], select[name="data[StoreCart][product_variant_id]"]').val(); 3201 // if ($.isNumeric(targetProductId) && $.isNumeric(targetProductVariantId)) { 3202 // $('.cart-item-remove[data-productid=' + targetProductId + '][data-productvariantid=' + targetProductVariantId + ']').trigger('click'); 3203 // } 3204 // } 3205 // $form.find('.btncart').attr('disabled', false).show(); 3206 // $form.find('.div-add-cart-hold').show();
3207 // //$form.find('.btn-cart-qty,.qty-hold').hide(); 3208 // $qtyInput.val(moq); // Reset to minimum order quantity 3209 // } else { 3210 // // // Update + Add Cart 3211 // // $button.data("disabled", true); 3212 // // $form.find('.btncart').trigger('click'); 3213 // // $button.data("disabled", false); 3214 // $button.data("disabled", true); 3215 // $button.prop("disabled", true); 3216 3217 // //$form.find('.btncart').trigger('click'); 3218 3219 // // Watch for any DOM change that signals cart update is done 3220 // // e.g. cart count updates, loader disappears, etc. 3221 // var observer = new MutationObserver(function(mutations) { 3222 // // Re-enable button once DOM settles 3223 // $button.data("disabled", false); 3224 // $button.prop("disabled", false); 3225 // observer.disconnect(); 3226 // }); 3227 3228 // // Observe the cart total/count element 3229 // var cartTarget = document.querySelector('.cart-count') || document.querySelector('.cart-total') || document.querySelector('#cart-summary'); 3230 3231 // if (cartTarget) { 3232 // observer.observe(cartTarget, { 3233 // childList: true, 3234 // subtree: true, 3235 // characterData: true 3236 // }); 3237 // } else { 3238 // // Fallback â re-enable after reasonable timeout 3239 // setTimeout(function() { 3240 // $button.data("disabled", false); 3241 // $button.prop("disabled", false); 3242 // }, 1500); 3243 // } 3244 // } 3245 // }); 3246 // } else { 3247 // $(document).unbind().on("click", ".incr-btn", function(event) { 3248 // event.preventDefault(); 3249 // var $button = $(this); 3250 // var incval = 1; 3251 3252 // var is_fabric = $button.closest('form').find('input.is_fabric').val(); 3253 // if(parseFloat(is_fabric) == 1) { incval = 0.5; } 3254 3255 // var inputQuantity = $button.closest('form').find('.quantity'); 3256 // var oldValue = inputQuantity.val(); 3257 // var minValue = inputQuantity.attr("min"); 3258 // var maxValue = parseFloat(inputQuantity.data("quantity")); 3259 // var index = $button.closest('form').find('.quantity').data("index"); 3260 3261 // $button.closest('form').find('.incr-btn[data-action="decrease"]').removeClass('inactive'); 3262 // if ($button.data('action') == "increase") { 3263 // var newVal = parseFloat(oldValue) + incval; 3264 // } else { 3265 // // Don't allow decrementing below 1 3266 // if (minValue != null) { 3267 // if (oldValue > minValue) { 3268 // var newVal = parseFloat(oldValue) - incval; 3269 // } else { 3270 // newVal = minValue; 3271 // $button.addClass('inactive'); 3272 // } 3273 // } else { 3274 // if (oldValue > 1) { 3275 // var newVal = parseFloat(oldValue) - incval; 3276 // } else { 3277 // newVal = incval; 3278 // $button.addClass('inactive'); 3279 // } 3280 // } 3281 // } 3282 3283 // if (Math.round(newVal) <= Math.round(maxValue)) { 3284 // $("div#diverror").hide().find(".label-danger").html(""); 3285 // $button.closest('form').find('.quantity').val(newVal); 3286 // } else { 3287 // $("div#diverror").show().find(".label-danger").html(Theme.Language.getStr('MaxOrderQuantityTxt') + parseInt(maxValue) + ""); 3288 // } 3289 3290 // if(parseInt(is_fabric) == 1) { 3291 // let orderQuantity = parseFloat(newVal) * 2; 3292 // $button.closest('form').find('input#quantity').val(orderQuantity); 3293 // } 3294 // }); 3295 // } 3296 3297 // Count Input (Quantity) 3298 //------------------------------------------------------------------------------ 3299 if (parseInt(window.Store.TemplateConfig.is_b2b_quantity_multiple) == 1) { 3300 3301 $(document).off("click.incr", ".incr-btn").on("click.incr", ".incr-btn", function(event) { 3302 event.preventDefault(); 3303 event.stopPropagation(); 3304 3305 var $button = $(this); 3306 var $form = $button.closest('form'); 3307 var $qtyInput = $form.find('.quantity'); 3308 var is_fabric = $form.find('input.is_fabric').val(); 3309 3310 // Get increment value from data attribute 3311 var incval = parseFloat($qtyInput.data("incrementQuantity")) || 1; 3312 var moq = incval; // minimum order quantity = increment value 3313 3314 if (parseFloat(is_fabric) == 1) { incval = 0.5; } 3315 3316 var oldValue = parseFloat($qtyInput.val()) || 0; 3317 var maxValue = parseFloat($qtyInput.data("quantity")); 3318 var newVal = 0; 3319 3320 $form.find('.incr-btn[data-action="decrease"]').removeClass('inactive'); 3321 3322 if (oldValue == moq && $button.data('action') == "decrease") { 3323 return false; 3324 } 3325 3326 if ($button.data('action') == "increase") { 3327 newVal = oldValue + incval; 3328 newVal = Math.round(newVal / incval) * incval; 3329 } else { 3330 // Decrease 3331 if (oldValue > moq) { 3332 newVal = oldValue - incval; 3333 newVal = Math.round(newVal / incval) * incval; 3334 if (newVal < moq) { newVal = moq; } 3335 } else { 3336 newVal = 0; 3337 $button.addClass('inactive'); 3338 } 3339 } 3340 3341 // Round to avoid floating point issues e.g. 0.1 + 0.2 = 0.30000000004 3342 newVal = parseFloat(newVal.toFixed(2)); 3343 3344 if (newVal <= maxValue) { 3345 $("div#diverror").hide().find(".label-danger").html(""); 3346 $qtyInput.val(newVal); 3347 } else { 3348 $("div#diverror").show().find(".label-danger").html( 3349 Theme.Language.getStr('MaxOrderQuantityTxt') + parseInt(maxValue) 3350 ); 3351 return false; 3352 } 3353 3354 if (parseInt(is_fabric) == 1) { 3355 var orderQuantity = newVal * 2; 3356 $form.find('input#quantity').val(orderQuantity); 3357 } 3358 3359 // === When new quantity is 0 or below minimum order quantity === 3360 if (newVal <= 0 || newVal < moq) { 3361 if ($('.cart-item-remove').length > 0) { 3362 var targetProductId = $form.find('input[name="data[StoreCart][id]"]').val(); 3363 var targetProductVariantId = $form.find('input[name="data[StoreCart][product_variant_id]"], select[name="data[StoreCart][product_variant_id]"]').val(); 3364 if ($.isNumeric(targetProductId) && $.isNumeric(targetProductVariantId)) { 3365 $('.cart-item-remove[data-productid=' + targetProductId + '][data-productvariantid=' + targetProductVariantId + ']').trigger('click'); 3366 } 3367 } 3368 $form.find('.btncart').attr('disabled', false).show(); 3369 $form.find('.div-add-cart-hold').show(); 3370 $qtyInput.val(moq); // Reset to minimum order quantity 3371 } else { 3372 // Quantity is valid â value already set above. No locking needed. 3373 $qtyInput.val(newVal); 3374 3375 // If you want each click to auto-sync to the cart, debounce instead of locking: 3376 // 3377 // clearTimeout($form.data('cartSyncTimer')); 3378 // $form.data('cartSyncTimer', setTimeout(function () { 3379 // $form.find('.btncart').trigger('click'); 3380 // }, 400)); 3381 } 3382 }); 3383 3384 } else { 3385
3386 $(document).off("click.incr", ".incr-btn").on("click.incr", ".incr-btn", function(event) { 3387 event.preventDefault(); 3388 3389 var $button = $(this); 3390 var $form = $button.closest('form'); 3391 var incval = 1; 3392 3393 var is_fabric = $form.find('input.is_fabric').val(); 3394 if (parseFloat(is_fabric) == 1) { incval = 0.5; } 3395 3396 var $qtyInput = $form.find('.quantity'); 3397 var oldValue = parseFloat($qtyInput.val()) || 0; 3398 var minValue = $qtyInput.attr("min"); 3399 var maxValue = parseFloat($qtyInput.data("quantity")); 3400 var newVal = 0; 3401 3402 $form.find('.incr-btn[data-action="decrease"]').removeClass('inactive'); 3403 3404 if ($button.data('action') == "increase") { 3405 newVal = oldValue + incval; 3406 } else { 3407 // Don't allow decrementing below the minimum 3408 if (minValue != null && minValue !== "") { 3409 if (oldValue > parseFloat(minValue)) { 3410 newVal = oldValue - incval; 3411 } else { 3412 newVal = parseFloat(minValue); 3413 $button.addClass('inactive'); 3414 } 3415 } else { 3416 if (oldValue > 1) { 3417 newVal = oldValue - incval; 3418 } else { 3419 newVal = incval; 3420 $button.addClass('inactive'); 3421 } 3422 } 3423 } 3424 3425 if (Math.round(newVal) <= Math.round(maxValue)) { 3426 $("div#diverror").hide().find(".label-danger").html(""); 3427 $qtyInput.val(newVal); 3428 } else { 3429 $("div#diverror").show().find(".label-danger").html( 3430 Theme.Language.getStr('MaxOrderQuantityTxt') + parseInt(maxValue) + "" 3431 ); 3432 } 3433 3434 if (parseInt(is_fabric) == 1) { 3435 var orderQuantity = parseFloat(newVal) * 2; 3436 $form.find('input#quantity').val(orderQuantity); 3437 } 3438 }); 3439 } 3440 3441 $(document).on("click", ".incr-qty-btn", function(event) { 3442 var $button = $(this); 3443 var incval = 1; 3444 var action = $button.data("action"); 3445 var product_id = $button.data("productId"); 3446 3447 $button.closest('form').find(".product-variant-"+product_id).each(function() { 3448 var totalqty = parseFloat($(this).data("quantity")); 3449 var moqqty = parseFloat($(this).data("moqQuantity")); 3450 var variant_id = parseInt($(this).data("variantId")); 3451 var old_qty = parseFloat($button.closest('form').find("#quantity_"+product_id+"_"+variant_id).val()); 3452 3453 if(action == 'increase') { 3454 if(totalqty != 0 && old_qty < totalqty) { 3455 old_qty = old_qty + incval; 3456 $button.closest('form').find("#quantity_"+product_id+"_"+variant_id).val(old_qty); 3457 } 3458 } else { 3459 if(totalqty != 0 && old_qty > moqqty) { 3460 old_qty = old_qty - incval; 3461 $button.closest('form').find("#quantity_"+product_id+"_"+variant_id).val(old_qty); 3462 } 3463 } 3464 }); 3465 }); 3466 3467 //Aditya Laces ctp file 3468 $(document).on("click", ".incr-qty-single-row-btn", function(event) { 3469 var $button = $(this); 3470 var incval = 1; 3471 var action = $button.data("action"); 3472 var product_id = $button.data("productId"); 3473 var product_variant_id = $button.data("productVariantId"); 3474 3475 3476 let totalqty = parseFloat($("#quantity_"+product_id+"_"+product_variant_id+"").data("quantity")); 3477 let moqqty = parseFloat($("#quantity_"+product_id+"_"+product_variant_id+"").data("moqQuantity")); 3478 let old_qty = parseFloat($button.closest('form').find("#quantity_"+product_id+"_"+product_variant_id).val()); 3479 3480 if(action == 'increase') { 3481 if(totalqty != 0 && old_qty < totalqty) { 3482 old_qty = old_qty + incval; 3483 $button.closest('form').find("#quantity_"+product_id+"_"+product_variant_id).val(old_qty); 3484 } 3485 } else { 3486 if(totalqty != 0 && old_qty > moqqty) { 3487 old_qty = old_qty - incval; 3488 $button.closest('form').find("#quantity_"+product_id+"_"+product_variant_id).val(old_qty); 3489 } 3490 } 3491 }); 3492 }, 3493 preventWishlistLoginRedirection: function() { 3494 $(".wishlistLoginPopup").on("click", function(b) { 3495 b.preventDefault(); 3496 }); 3497 }, 3498 addToWishlistFromList: function() { 3499 $("span.addtowishlistfromlist").on("click", function() { 3500 3501 var b = $(this).data("product-id"), c = $(this).data("logged-in"); 3502 if ("" != c && 0 != c) { 3503 var d = "data[Product][id]=" + b; 3504 return $.ajax({
3505 type: "POST", 3506 async: true, 3507 cache: true, 3508 url: "/store_products/wishlist", 3509 accepts: "application/json", 3510 dataType: "json", 3511 data: d, 3512 beforeSend: function() {}, 3513 complete: function() {}, 3514 success: function(a) { 3515 void 0 !== a.wishlist_status && 1 == a.wishlist_status ? ($("#mywishlistadd" + b).hide(), $("#mywishlistadded" + b).show()) : ($("#mywishlistadd" + b).show(), $("#mywishlistadded" + b).hide()) 3516 }, 3517 error: function(a) { 3518 500 == a.status && alert("Internal error: " + a.responseText) 3519 }, 3520 complete: function() { 3521 Conversion.Utils.setConversion('AddToWishlist', 1); 3522 } 3523 }), !1 3524 } 3525 alert("Please login") 3526 }); 3527 3528 $(document).on("click", ".addtowishlistfromlist_qc", function() { 3529 var b = $(this).data("product-id"), c = $(this).data("logged-in"); 3530 if ("" != c && 0 != c) { 3531 var d = "data[Product][id]=" + b; 3532 return $.ajax({ 3533 type: "POST", 3534 async: !0, 3535 cache: !1, 3536 url: "/store_products/wishlist", 3537 accepts: "application/json", 3538 dataType: "json", 3539 data: d, 3540 beforeSend: function() {}, 3541 3542 success: function(a) { 3543 void 0 !== a.wishlist_status && 1 == a.wishlist_status ? ($("#mywishlistadd_qc" + b).hide(), $("#mywishlistadded_qc" + b).show()) : ($("#mywishlistadd_qc" + b).show(), $("#mywishlistadded_qc" + b).hide()) 3544 }, 3545 error: function(a) { 3546 500 == a.status && alert("Internal error: " + a.responseText) 3547 }, 3548 complete: function(){ 3549 Conversion.Utils.setConversion('AddToWishlist', 1); 3550 } 3551 }), !1 3552 } 3553 alert("Please login") 3554 }); 3555 }, 3556 removeFromWishlist: function() { 3557 $(document).on("click", ".removerromwishlist", function() { 3558 var b = $(this).data("product-id"), 3559 c = $(this).data("logged-in"); 3560 if ("" != c && 0 != c) { 3561 var d = "data[Product][id]=" + b; 3562 return $.ajax({ 3563 type: "POST", 3564 async: !0, 3565 cache: !1, 3566 url: "/store_product_wishlists/removefromwishlist", 3567 accepts: "application/json", 3568 dataType: "json", 3569 data: d, 3570 beforeSend: function() {}, 3571 complete: function() {}, 3572 success: function(a) { 3573 void 0 !== a.wishlist_status && 1 == a.wishlist_status ? ($("#mywishlistadd" + b).show(), $("#mywishlistadded" + b).hide()) : ($("#mywishlistadd" + b).hide(), $("#mywishlistadded" + b).show()) 3574 }, 3575 error: function(a) { 3576 500 == a.status && alert("Internal error: " + a.responseText) 3577 } 3578 }), !1 3579 } 3580 alert("Please login") 3581 }); 3582 $(document).on("click", ".removerromwishlist_qc", function() { 3583 var b = $(this).data("product-id"), 3584 c = $(this).data("logged-in"); 3585 if ("" != c && 0 != c) { 3586 var d = "data[Product][id]=" + b; 3587 return $.ajax({
3588 type: "POST", 3589 async: !0, 3590 cache: !1, 3591 url: "/store_product_wishlists/removefromwishlist", 3592 accepts: "application/json", 3593 dataType: "json", 3594 data: d, 3595 beforeSend: function() {}, 3596 complete: function() {}, 3597 success: function(a) { 3598 void 0 !== a.wishlist_status && 1 == a.wishlist_status ? ($("#mywishlistadd_qc" + b).show(), $("#mywishlistadded_qc" + b).hide()) : ($("#mywishlistadd_qc" + b).hide(), $("#mywishlistadded_qc" + b).show()) 3599 }, 3600 error: function(a) { 3601 500 == a.status && alert("Internal error: " + a.responseText) 3602 } 3603 }), !1 3604 } 3605 alert("Please login") 3606 }); 3607 }, 3608 addToFavoriteFromList: function() { 3609 $(document).on("click", "span.addtofavoritefromlist, a.addtofavoritefromlist", function() { 3610 var product_id = $(this).data("product-id"); 3611 3612 if (product_id != '') { 3613 var d = "data[Product][id]=" + product_id; 3614 return $.ajax({ 3615 type: "POST", 3616 async: !0, 3617 cache: !1, 3618 url: "/store_products/addtofavorite", 3619 accepts: "application/json", 3620 dataType: "json", 3621 data: d, 3622 beforeSend: function() {}, 3623 success: function(a) { 3624 if(a.status == 1) { 3625 window.location.href = "/product-enquiry"; 3626 } 3627 }, 3628 error: function(a) { 3629 500 == a.status && alert("Internal error: " + a.responseText) 3630 }, 3631 complete: function(){ 3632 Conversion.Utils.setConversion('AddToWishlist', 1); 3633 } 3634 }), !1 3635 } 3636 3637 }); 3638 }, 3639 addToQuote: function() { 3640 $(document).on("click", "a.add_to_quote", function() { 3641 var allowAdd = 1; 3642 //Now Process To Add 3643 if (parseInt(allowAdd) == 1) { 3644 //Check Form Process 3645 var FormID = $(this).closest("form").attr('id'); 3646 var ProductId = $(this).closest("form").find("input#StoreCartId").val(); 3647 var ProductVariantId = $(this).closest("form").find("input#StoreCartProductVariantId").val(); 3648 var ProductQuantity = $(this).closest("form").find("input#quantity").val(); 3649 3650 var ProductName = Theme.ProductData.product.product_name; 3651 var ProductUrl = Theme.ProductData.product.seo_url; 3652 var ProductSku = Theme.ProductData.product.sku; 3653 var ProductBarcode = Theme.ProductData.product.barcode; 3654 var ProductImage = ''; 3655 3656 var FormData = "data[Product][id]=" + ProductId + "&data[Product][product_variant_id]=" + ProductVariantId + "&data[Product][quantity]=" + ProductQuantity+ "&data[Product][product_name]=" + ProductName+ "&data[Product][seo_url]=" + ProductUrl+ "&data[Product][sku]=" + ProductSku+ "&data[Product][barcode]=" + ProductBarcode; 3657 3658 $.ajax({
3659 type: "POST", 3660 async: !0, 3661 cache: !1, 3662 url: "/store_quote_requests/add_to_quto", 3663 accepts: "application/json", 3664 dataType: "json", 3665 data: FormData, 3666 beforeSend: function() {}, 3667 success: function(a) { 3668 if(a.status == 1) { 3669 window.location.href = "/quote_request"; 3670 } 3671 }, 3672 error: function(a) { 3673 //500 == a.status && alert("Internal error: " + a.responseText) 3674 }, 3675 complete: function(){ 3676 3677 } 3678 }); 3679 } 3680 }); 3681 3682 $(document).on("click", "a.quote-item-remove", function() { 3683 var allowAdd = 1; 3684 //Now Process To Add 3685 if (parseInt(allowAdd) == 1) { 3686 //Check Form Process 3687 var Id = $(this).data('id'); 3688 var QuoteRequestId = $(this).data('quoteRequestId'); 3689 var ProductId = $(this).data("productId"); 3690 var ProductVariantId = $(this).data("productVariantId"); 3691 var FormData = "data[Quote][id]=" + Id + "&data[Quote][quote_request_id]=" + QuoteRequestId + "&data[Quote][product_id]=" + ProductId + "&data[Quote][product_variant_id]=" + ProductVariantId ; 3692 3693 $.ajax({
3694 type: "POST", 3695 async: !0, 3696 cache: !1, 3697 url: "/store_quote_requests/remove_quto_request", 3698 accepts: "application/json", 3699 dataType: "json", 3700 data: FormData, 3701 beforeSend: function() {}, 3702 success: function(data) { 3703 if(data.status == 1) { 3704 3705 $("#quote_item_"+Id+"").remove(); 3706 $("#flashMsg").delay(100).html("Quote request removed successfully."); 3707 $("#flashMsg").fadeIn().delay(3000).fadeOut(); 3708 3709 } 3710 }, 3711 error: function(a) { 3712 //500 == a.status && alert("Internal error: " + a.responseText) 3713 }, 3714 complete: function(){ 3715 3716 } 3717 }); 3718 } 3719 }); 3720 }, 3721 setConversion: function(actionName) { 3722 if(actionName == "AddToCart") { 3723 if(typeof fbq !== 'undefined') { 3724 fbq('track', 'AddToCart', { 3725 content_name: ''+ Theme.ProductData.product.product_name.replace(/'/g, '\\') +'', 3726 content_ids: [''+ Theme.ProductData.product.sku +''], 3727 content_type: 'product', 3728 contents: [{"id": ""+ Theme.ProductData.product.sku +"", "quantity": 1, "item_price": Brand.formatMoney(parseFloat(Theme.ProductData.product.net_price), "{{amount}}")}], 3729 currency: ''+ window.app.BrandGlobals.store_currency +'', 3730 value: ''+ Brand.formatMoney(parseFloat(Theme.ProductData.product.net_price), "{{amount}}") +'' 3731 }); 3732 } 3733 } else if(actionName == "AddToWishlist") { 3734 if(typeof fbq !== 'undefined') { 3735 fbq('track', 'AddToWishlist', { 3736 content_name: ''+ Theme.ProductData.product.product_name.replace(/'/g, '\\') +'', 3737 content_ids: [''+ Theme.ProductData.product.sku +''], 3738 content_type: 'product', 3739 contents: [{"id": ""+ Theme.ProductData.product.sku +"", "quantity": 1, "item_price": Brand.formatMoney(parseFloat(Theme.ProductData.product.net_price), "{{amount}}")}], 3740 //currency: ''+ window.app.BrandGlobals.store_currency +'', 3741 value: ''+ Brand.formatMoney(parseFloat(Theme.ProductData.product.net_price), "{{amount}}") +'' 3742 }); 3743 } 3744 } 3745 }, 3746 setImageSize: function() { 3747 const getMeta = async (url) => { 3748 const img = new Image(); 3749 img.src = url; 3750 await img.decode(); 3751 return img 3752 }; 3753 setTimeout(function() { 3754 if (window.proImgJson.length > 0) { 3755 let proImgArr = JSON.parse(window.proImgJson); 3756 proImgArr.forEach(function (item, index) { 3757 if(parseInt(item.is_processed) === 0) { 3758 getMeta(item.big_image_url).then(img => { 3759 var FormData = "data[StoreProductImage][id]=" + item.id + "&data[StoreProductImage][store_id]=" + item.store_id + "&data[StoreProductImage][image_width]=" + img.naturalWidth + "&data[StoreProductImage][image_height]=" + img.naturalHeight + ""; 3760 $.ajax({
3761 type: "POST", 3762 async: true, 3763 cache: false, 3764 url: "/store_product_images/rest_image_dimension_update.json", 3765 dataType: "json", 3766 data: FormData, 3767 beforeSend: function(XMLHttpRequest) { 3768 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 3769 }, 3770 success: function(data, textStatus) { 3771 // if (data.length > 0 && data.trim() !== "failure") { 3772 // alert("Addon added successfully"); 3773 // } else { 3774 // alert("Please add this product to your cart before choosing the addon."); 3775 // } 3776 }, 3777 error: function(jqXHR, textStatus, errorThrown) { 3778 if (jqXHR.status == 500) { 3779 alert('Internal error: ' + jqXHR.responseText); 3780 } 3781 } 3782 }); 3783 //console.log(item); 3784 //console.log(img.naturalWidth, img.naturalHeight); 3785 }); 3786 } 3787 }); 3788 } 3789 }, 1000); 3790 }, 3791 shopTheLookProduct: function() { 3792 if($("button#btn_shop_the_look").length > 0) { 3793 var shopthelookModal = new bootstrap.Modal(document.getElementById('shopthelookModal'), { backdrop: 'static', keyboard: false }); 3794 3795 $("button#btn_shop_the_look").on("click", function(event) { 3796 event.preventDefault(); 3797 var product_id = $(this).data("productId"); 3798 if (parseInt(product_id) > 0) { 3799 var FormData = "product_id=" + product_id + ""; 3800 $.ajax({
3801 type: "POST", 3802 async: true, 3803 cache: false, 3804 url: "/store_products/get_shop_the_look_products_by_product_id", 3805 dataType: "html", 3806 data: FormData, 3807 beforeSend: function(XMLHttpRequest) { 3808 3809 }, 3810 complete: function() { 3811 3812 }, 3813 success: function(data, textStatus) { 3814 $("div#shop_the_look_products").html(data); 3815 shopthelookModal.show(); 3816 }, 3817 error: function(jqXHR, textStatus, errorThrown) { 3818 if (jqXHR.status == 500) { 3819 alert('Internal error: ' + jqXHR.responseText); 3820 } 3821 } 3822 }); 3823 } 3824 }); 3825 3826 //On Modal Close, Clear Modal Body 3827 document.getElementById('shopthelookModal').addEventListener('hidden.bs.modal', function (event) { 3828 $("div#shop_the_look_products").html(""); 3829 }); 3830 } 3831 }, 3832 validateEnquiryForm: function() { 3833 window.mobile1_intlTel = Theme.Utils.PhoneCountryCode('mobile_no', "IN"); 3834 window.mobile2_intlTel = Theme.Utils.PhoneCountryCode('mobile_no2', "IN"); 3835 window.mobile3_intlTel = Theme.Utils.PhoneCountryCode('mobile_no3', "IN"); 3836 $("form#StoreProductEnquiryForm").validate({ 3837 submitHandler: function(form) { 3838 event.preventDefault(); 3839 3840 $('#btnEnquryForm').prop("disabled", true); 3841 let mobile1_isd_code = window.mobile1_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 3842 3843 if(window.googleRecaptchaSiteKey !== undefined) { 3844 grecaptcha.ready(function () { 3845 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'customer_login'}).then(function (token) { 3846 $(form).find('input#recaptcha_ajax_enquiry_response').val(token); 3847 }); 3848 }); 3849 } 3850 3851 var FormID = $(this).closest("form").attr('id'); 3852 var ProductId = $("input.product_id").val(); 3853 ProductId = (ProductId != undefined) ? ProductId : 0; 3854 3855 var FormData = "data[product_id]=" + ProductId; 3856 3857 //New Code Developed For Custom Fields 3858 if ($("input#product_name").length > 0) { 3859 FormData = FormData + "&data[product_name]=" + $("input#product_name").val(); 3860 } 3861 if ($("input#enquiry_type").length > 0) { 3862 FormData = FormData + "&data[title]=" + $("input#enquiry_type").val(); 3863 } 3864 if ($("input#full_name").length > 0) { 3865 FormData = FormData + "&data[full_name]=" + $("input#full_name").val(); 3866 } 3867 if ($("input#email").length > 0) { 3868 FormData = FormData + "&data[email]=" + $("input#email").val(); 3869 } 3870 if ($("input#mobile_no").length > 0) { 3871 FormData = FormData + "&data[mobile_no]=" + $("input#mobile_no").val(); 3872 } 3873 if (mobile1_isd_code.length > 0) { 3874 FormData = FormData + "&data[mobile1_isd_code]=" + mobile1_isd_code; 3875 } 3876 if ($("textarea#question").length > 0) { 3877 FormData = FormData + "&data[question]=" + $("textarea#question").val(); 3878 } 3879 if ($("select#country_id").length > 0) { 3880 FormData = FormData + "&data[country_id]=" + $("select#country_id").val(); 3881 } 3882 if($("input#recaptcha_ajax_enquiry_response").length > 0) { 3883 FormData = FormData + "&data[recaptcha_response]=" + $("input#recaptcha_ajax_enquiry_response").val(); 3884 } 3885 3886 setTimeout(function() { 3887 $.ajax({
3888 type: "POST", 3889 async: true, 3890 cache: false, 3891 url: "/store_products/ajax_enquiry_form_save", 3892 dataType: "json", 3893 data: FormData, 3894 beforeSend: function(XMLHttpRequest) { 3895 3896 }, 3897 success: function(data, textStatus) { 3898 if(data.status == 1){ 3899 $("#create_success_alert").show(); 3900 $('#btnEnquryForm').removeAttr('disabled'); 3901 $("form#StoreProductEnquiryForm")[0].reset(); 3902 } 3903 setTimeout(function() { 3904 $("#create_success_alert").hide(); 3905 }, 2000); 3906 }, 3907 error: function(jqXHR, textStatus, errorThrown) { 3908 if (jqXHR.status == 500) { 3909 alert('Internal error: ' + jqXHR.responseText); 3910 } 3911 } 3912 }).done(function(data) { 3913 $('#btnEnquryForm').removeAttr('disabled'); 3914 }); 3915 }, 2000); 3916 3917 return false; 3918 } 3919 }); 3920 3921 $("form#DemoClassRequestEnquiryForm").validate({ 3922 submitHandler: function(form) { 3923 event.preventDefault(); 3924 3925 $('#demoClassRequest').prop("disabled", true); 3926 let mobile2_isd_code = window.mobile2_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 3927 3928 if(window.googleRecaptchaSiteKey !== undefined) { 3929 grecaptcha.ready(function () { 3930 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'customer_login'}).then(function (token) { 3931 $(form).find('input#recaptcha_demo_class_enquiry_response').val(token); 3932 }); 3933 }); 3934 } 3935 3936 var FormID = $(this).closest("form").attr('id'); 3937 var ProductId = $("input.product_id").val(); 3938 3939 var FormData = "data[product_id]=" + ProductId; 3940 3941 //New Code Developed For Custom Fields 3942 if ($("input#product_name").length > 0) { 3943 FormData = FormData + "&data[product_name]=" + $("input#product_name").val(); 3944 } 3945 if ($("input#demo_enquiry_type").length > 0) { 3946 FormData = FormData + "&data[title]=" + $("input#demo_enquiry_type").val(); 3947 } 3948 if ($("input#demo_full_name").length > 0) { 3949 FormData = FormData + "&data[full_name]=" + $("input#demo_full_name").val(); 3950 } 3951 if ($("input#demo_email").length > 0) { 3952 FormData = FormData + "&data[email]=" + $("input#demo_email").val(); 3953 } 3954 if ($("input#mobile2_no").length > 0) { 3955 FormData = FormData + "&data[mobile_no]=" + $("input#mobile_no2").val(); 3956 } 3957 if (mobile2_isd_code.length > 0) { 3958 FormData = FormData + "&data[mobile1_isd_code]=" + mobile2_isd_code; 3959 } 3960 if($("input#recaptcha_demo_class_enquiry_response").length > 0) { 3961 FormData = FormData + "&data[recaptcha_response]=" + $("input#recaptcha_demo_class_enquiry_response").val(); 3962 } 3963 3964 setTimeout(function() { 3965 $.ajax({
3966 type: "POST", 3967 async: true, 3968 cache: false, 3969 url: "/store_products/ajax_enquiry_form_save", 3970 dataType: "json", 3971 data: FormData, 3972 beforeSend: function(XMLHttpRequest) { 3973 3974 }, 3975 success: function(data, textStatus) { 3976 if(data.status == 1) { 3977 $("#create_demo_request_alert").show(); 3978 $('#demoClassRequest').removeAttr('disabled'); 3979 $("form#DemoClassRequestEnquiryForm")[0].reset(); 3980 } 3981 setTimeout(function() { 3982 $("#create_demo_request_alert").hide(); 3983 }, 2000); 3984 }, 3985 error: function(jqXHR, textStatus, errorThrown) { 3986 if (jqXHR.status == 500) { 3987 alert('Internal error: ' + jqXHR.responseText); 3988 } 3989 } 3990 }).done(function(data) { 3991 $('#demoClassRequest').removeAttr('disabled'); 3992 }); 3993 }, 2000); 3994 3995 return false; 3996 } 3997 }); 3998 3999 $("form#offerRequestEnquiryForm").validate({ 4000 submitHandler: function(form) { 4001 event.preventDefault(); 4002 4003 $('#offerRequest').prop("disabled", true);; 4004 let mobile3_isd_code = window.mobile3_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 4005 4006 if(window.googleRecaptchaSiteKey !== undefined) { 4007 grecaptcha.ready(function () { 4008 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'customer_login'}).then(function (token) { 4009 $(form).find('input#recaptcha_offer_request_enquiry_response').val(token); 4010 }); 4011 }); 4012 } 4013 4014 var FormID = $(this).closest("form").attr('id'); 4015 var ProductId = $("input.product_id").val(); 4016 4017 var FormData = "data[product_id]=" + ProductId; 4018 4019 //New Code Developed For Custom Fields 4020 if ($("input#product_name").length > 0) { 4021 FormData = FormData + "&data[product_name]=" + $("input#product_name").val(); 4022 } 4023 if ($("input#offer_enquiry_type").length > 0) { 4024 FormData = FormData + "&data[title]=" + $("input#offer_enquiry_type").val(); 4025 } 4026 if ($("input#offer_full_name").length > 0) { 4027 FormData = FormData + "&data[full_name]=" + $("input#offer_full_name").val(); 4028 } 4029 if ($("input#offer_email").length > 0) { 4030 FormData = FormData + "&data[email]=" + $("input#offer_email").val(); 4031 } 4032 if ($("input#mobile3_no").length > 0) { 4033 FormData = FormData + "&data[mobile_no]=" + $("input#mobile_no3").val(); 4034 } 4035 if (mobile3_isd_code.length > 0) { 4036 FormData = FormData + "&data[mobile1_isd_code]=" + mobile3_isd_code; 4037 } 4038 if($("input#recaptcha_offer_request_enquiry_response").length > 0) { 4039 FormData = FormData + "&data[recaptcha_response]=" + $("input#recaptcha_offer_request_enquiry_response").val(); 4040 } 4041 4042 setTimeout(function() { 4043 $.ajax({
4044 type: "POST", 4045 async: true, 4046 cache: false, 4047 url: "/store_products/ajax_enquiry_form_save", 4048 dataType: "json", 4049 data: FormData, 4050 beforeSend: function(XMLHttpRequest) { 4051 4052 }, 4053 success: function(data, textStatus) { 4054 if(data.status == 1){ 4055 $("#create_offer_request_alert").show(); 4056 $('#offerRequest').removeAttr('disabled'); 4057 $("form#offerRequestEnquiryForm")[0].reset(); 4058 } 4059 setTimeout(function() { 4060 $("#create_offer_request_alert").hide(); 4061 }, 2000); 4062 }, 4063 error: function(jqXHR, textStatus, errorThrown) { 4064 if (jqXHR.status == 500) { 4065 alert('Internal error: ' + jqXHR.responseText); 4066 } 4067 } 4068 }).done(function(data) { 4069 $('#offerRequest').removeAttr('disabled'); 4070 }); 4071 }, 2000); 4072 4073 return false; 4074 } 4075 }); 4076 } 4077 }, 4078 Theme.Utils.CategoryProduct = { 4079 initCategoryProduct: function() { 4080 $('body').on("click", "button.addtoprerunsize", function(event) { 4081 var product_id = $(this).data("productId"); 4082 var size_type = $(this).data("sizeType"); 4083 //console.log(product_id); 4084 $(this).closest('form').find(".qty-box").each(function() { 4085 $(this).val(''); 4086 }); 4087 4088 $(this).closest('form').find(".qty-box").each(function() { 4089 4090 if($(this).data("quantity") > 0) { 4091 var sizeid = $(this).data("sizeId"); 4092 if(size_type == 1 && (sizeid == 1 || sizeid == 2 || sizeid == 3 || sizeid == 4 || sizeid == 5 || sizeid == 6)){ 4093 //var qty = ($(this).data("totalQuantity") > 18) ? 18: $(this).data("totalQuantity"); 4094 $(this).val(1); 4095 } 4096 if(size_type == 2 && (sizeid == 2 || sizeid == 3 || sizeid == 4 || sizeid == 5)){ 4097 //var qty = ($(this).data("totalQuantity") > 16) ? 16: $(this).data("totalQuantity"); 4098 $(this).val(1); 4099 } 4100 if(size_type == 3 && (sizeid == 2 || sizeid == 3 || sizeid == 4 || sizeid == 5 || sizeid == 6)){ 4101 //var qty = ($(this).data("totalQuantity") > 18) ? 18: $(this).data("totalQuantity"); 4102 $(this).val(1); 4103 } 4104 4105 if(size_type == 4 && (sizeid == 3 || sizeid == 4 || sizeid == 5 || sizeid == 6 || sizeid == 7)){ 4106 //var qty = ($(this).data("totalQuantity") > 20) ? 20: $(this).data("totalQuantity"); 4107 $(this).val(1); 4108 } 4109 4110 if(size_type == 5 && (sizeid == 1 || sizeid == 2 || sizeid == 3 || sizeid == 4 || sizeid == 5)){ 4111 //var qty = ($(this).data("totalQuantity") > 18) ? 18: $(this).data("totalQuantity"); 4112 $(this).val(1); 4113 } 4114 } 4115 }); 4116 4117 }); 4118 4119 $('body').on("click", ".btn-product-color", function(event) { 4120 event.preventDefault(); 4121 var product_id = $(this).data("productId"); 4122 var div_index = $(this).data("divIndex"); 4123 let that = $(this); 4124 let FormData = "data[StoreProduct][id]=" + product_id + "&data[StoreProduct][div_index]=" + div_index; 4125 delayTime = 2000; 4126 $.ajax({
4127 type: "POST", 4128 async: true, 4129 cache: false, 4130 url: "/store_products/list_view", 4131 dataType: "html", 4132 data: FormData, 4133 beforeSend: function(XMLHttpRequest) { 4134 //that.closest("div#div_product_"+ div_index).last().append("<div>Please Wait Loading</div>"); 4135 4136 that.closest("div#div_product_"+ div_index).find('img').attr('src', '/img/x.gif'); 4137 }, 4138 success: function(responseData, textStatus) { 4139 that.closest("div#div_product_"+ div_index).empty().html(responseData); 4140 }, 4141 error: function(jqXHR, textStatus, errorThrown) { 4142 if (jqXHR.status == 500) { 4143 alert('Internal error: ' + jqXHR.responseText); 4144 } 4145 } 4146 }); 4147 }); 4148 4149 $('body').on("change", ".product_variant", function(event) { 4150 //event.preventDefault(); 4151 $(this).closest("form").find("input.quantity").val(1); 4152 4153 var trackInventory = $(this).closest("form").find("input#StoreCartTrackInventory").val(); 4154 if(trackInventory > 0) { 4155 var product_variant_quantity = $(this).closest("form").find(':selected').data('productvariantquantity'); 4156 $(this).closest("form").find("input.quantity").data('quantity', product_variant_quantity); 4157 } 4158 4159 let $form = $(this).closest("form"); 4160 let minimum_order_quantity = $form.find('select.product_variant option:selected').data('productVariantMoq'); 4161 4162 if(parseInt(window.Store.TemplateConfig.is_b2b_quantity_multiple) == 1) { 4163 $form.find("input.quantity").attr("min", minimum_order_quantity) 4164 .attr("data-increment-quantity", minimum_order_quantity) 4165 .data("incrementQuantity", minimum_order_quantity) 4166 .val(minimum_order_quantity) 4167 .attr("value", minimum_order_quantity); 4168 } else { 4169 $form.find("input.quantity").attr("min", minimum_order_quantity) 4170 .attr("data-increment-quantity", 1) 4171 .data("incrementQuantity", 1) 4172 .val(minimum_order_quantity) 4173 .attr("value", minimum_order_quantity); 4174 } 4175 4176 var product_variant_id = $(this).val(); 4177 var product_price = $(this).closest("form").find(':selected').data('productprice'); 4178 var discount = $(this).closest("form").find(':selected').data('discount'); 4179 var net_price = $(this).closest("form").find(':selected').data('netprice'); 4180 var currency = $(this).closest("form").find(':selected').data('currency'); 4181 var quantity = $(this).closest("form").find(':selected').data('quantity'); 4182 4183 var price_row = ""; 4184 if (discount > 0) { 4185 price_row = '<span class="cut-price">' + product_price + '</span> <span class="price text-danger" itemprop="price">' + net_price + '</span>'; 4186 } else { 4187 price_row = '<span class="actual-price" itemprop="price">' + net_price + '</span>'; 4188 } 4189 var product_id = $(this).closest("form").find("input#StoreCartId").val(); 4190 4191 $('#price-hold-' + product_id + '').empty(); 4192 $('#price-hold-' + product_id + '').html(price_row) 4193 }); 4194 4195 $('select.product_variant').each(function(index, item) { 4196 //if(index == 0){ 4197 $(item).trigger("change"); 4198 //} 4199 }); 4200 4201 $('body').on("change", ".product_variant_image", function(event) { 4202 var product_id = $(this).closest("form").find("input#StoreCartId").val(); 4203 var product_variant_id = $(this).val(); 4204 // Onchane variant product image change 4205 var imageIndex = $(this).closest("form").find(':selected').data('imageIndex'); 4206 if(imageIndex > 0) { 4207 Theme.Utils.CategoryProduct.ajaxChangeProductVariantImage(product_id, product_variant_id, imageIndex); 4208 } 4209 }); 4210 }, 4211 ajaxChangeProductVariantImage: function(product_id = 0, product_variant_id = 0, image_index = 0) { 4212 //alert(product_id+"="+product_variant_id+"="+image_index); 4213 let FormData = "data[StoreProduct][id]=" + product_id + "&data[StoreProduct][product_variant_id]=" + product_variant_id + "&data[StoreProduct][image_index]=" + image_index; 4214 $.ajax({
4215 type: "POST", 4216 async: true, 4217 cache: false, 4218 url: "/store_products/get_variant_image_by_index", 4219 accepts: 'application/json', 4220 dataType: "json", 4221 data: FormData, 4222 beforeSend: function(XMLHttpRequest) { 4223 //$("button#btnnotifysubmit").addClass("disabled").attr("disabled", "disabled"); 4224 }, 4225 complete: function() { 4226 //$("button#btnnotifysubmit").removeClass("disabled").removeAttr("disabled"); 4227 }, 4228 success: function(data, textStatus) { 4229 if(data.status !== undefined && data.status == 1) { 4230 $('#img_'+product_id).attr('data-src', data.medium_image_path).attr('src', data.medium_image_path); 4231 } 4232 }, 4233 error: function(jqXHR, textStatus, errorThrown) { 4234 console.log(jqXHR.responseText); 4235 if (jqXHR.status == 500) { 4236 alert('Internal error: ' + jqXHR.responseText); 4237 } 4238 } 4239 }); 4240 }, 4241 ajaxAddCategoryProduct: function() { 4242 var m_count = 0; 4243 $('body').on("click", ".btncart, .btn-cart, .btn-buynow, .btn-subscribe", function(a) { 4244 a.preventDefault(); 4245 a.stopImmediatePropagation(); 4246 4247 $(this).attr('disabled', true); 4248 4249 var is_buy_now = $(this).hasClass("btn-buynow"); 4250 var is_subscribe = $(this).hasClass("btn-subscribe"); 4251 let product_id = $(this).closest("form").find("input#StoreCartId").val(); 4252 let delayTime = 0; //2000; //2 seconds = 2000 microseconds 4253 4254 if ($("div#diverror").length > 0) { 4255 var a = Theme.Utils.Product.selectedValues(); 4256 b = Theme.Utils.Product.getVariant(a); 4257 if(b == null) { 4258 var minimum_order_quantity = Theme.ProductData.product.minimum_order_quantity; 4259 } else { 4260 var minimum_order_quantity = b.minimum_order_quantity; 4261 } 4262 4263 if (parseInt(minimum_order_quantity) > 0 && $("input#quantity").val() < parseInt(minimum_order_quantity)) { 4264 $("div#diverror").show().find(".label-danger").html("Minimum order quantity must be " + parseInt(minimum_order_quantity) + ""); 4265 $(this).attr('disabled', false); 4266 return; 4267 } else { 4268 $("div#diverror").hide().find(".label-danger").html(''); 4269 } 4270 } 4271 4272 // New Code for adding custom form starts 4273 // Custom Form Fields 23-08-2022 4274 let all_fields = []; 4275 let string_fields = ''; 4276 4277 //Perform Validation Check 4278 if($("div#div_product_questions").length > 0 && $("div#div_product_questions").is(":visible")) { 4279 //Perform Validation Check 4280 let isValid = true; 4281 let errorMessage = []; 4282 4283 if ($("div#div_product_questions").is(":visible")) { 4284 // Find all required inputs inside the visible div 4285 //$("div#div_product_questions input[required], div#div_product_questions select[required]").each(function () { 4286 // $("div#div_product_questions input[required]:visible, div#div_product_questions select[required]:visible").each(function () { 4287 // let fieldType = $(this).attr("type"); 4288 // let fieldName = $(this).attr("name") || "required field"; 4289 // let labelText = $(this).closest("div").parent("div").find("label").first().text().trim(); // Find closest label 4290 4291 // // if (fieldType === "radio" || fieldType === "checkbox") { 4292 // // if ($(`input[name="${fieldName}"]:checked`).length === 0) { 4293 // // errorMessage += `Please select an option for ${labelText}.\n`; 4294 // // isValid = false; 4295 // // } 4296 // // } else if ($(this).val().trim() === "") { 4297 // // errorMessage += `Please fill in the ${labelText}.\n`; 4298 // // isValid = false; 4299 // // } 4300 4301 // if (fieldType !== "radio" && fieldType !== "checkbox" && $(this).val().trim() === "") { 4302 // errorMessage.push(`Please fill in the ${labelText}.`); 4303 // isValid = false; 4304 // } 4305 // }); 4306 4307 $("div#div_product_questions input[required]:visible, div#div_product_questions select[required]:visible, div#div_product_questions textarea[required]:visible").each(function () { 4308 let fieldType = $(this).attr("type") || $(this).prop("tagName").toLowerCase(); // Handle textarea 4309 let fieldName = $(this).attr("name") || "required field"; 4310 4311 // Better label finding logic 4312 let labelText = ""; 4313 4314 // Method 1: Check for associated label using 'for' attribute 4315 let fieldId = $(this).attr("id"); 4316 if (fieldId) { 4317 labelText = $(`label[for="${fieldId}"]`).text().trim(); 4318 } 4319 4320 // Method 2: Find label within parent structure if not found 4321 if (!labelText) { 4322 labelText = $(this).closest("div").find("label").first().text().trim(); 4323 } 4324 4325 // Method 3: Look in parent or previous sibling 4326 if (!labelText) { 4327 labelText = $(this).parent().find("label").first().text().trim(); 4328 } 4329 4330 // Method 4: Check previous sibling label 4331 if (!labelText) { 4332 labelText = $(this).prev("label").text().trim(); 4333 } 4334 4335 // Fallback to placeholder or name 4336 if (!labelText) { 4337 labelText = $(this).attr("placeholder") || fieldName; 4338 } 4339 4340 // Remove any asterisks or special characters from label 4341 labelText = labelText.replace(/\*/g, '').trim(); 4342 4343 // Validate non-radio/checkbox fields 4344 if (fieldType !== "radio" && fieldType !== "checkbox" && $(this).val().trim() === "") { 4345 errorMessage.push(`Please fill in the ${labelText}.`); 4346 isValid = false; 4347 } 4348 }); 4349 4350 // Validate radio buttons (at least one checked per name group) 4351 let radioGroups = {}; 4352 $("div#div_product_questions input[type='radio']:visible").each(function () { 4353 let name = $(this).attr("name"); 4354 if (!radioGroups[name]) { 4355 radioGroups[name] = false; 4356 } 4357 if ($(`input[name="${name}"]:checked`).length > 0) { 4358 radioGroups[name] = true; 4359 } 4360 }); 4361 4362 $.each(radioGroups, function (name, isChecked) { 4363 if (!isChecked) { 4364 // console.log($(`input[name="${name}"]`).closest("div") // Start from the current input's parent div 4365 // .prevAll("div")); 4366 // let labelText = $(`input[name="${name}"]`).closest("div") // Start from the current input's parent div 4367 // .prevAll("div") // Traverse to previous divs 4368 // .has("label span.text-danger") // Find label containing span with class 'text-danger' 4369 // .last() // Get the first matching label 4370 // .text().trim(); 4371 let labelText = $(`input[name="${name}"]`).closest("div").parent("div").parent("div").find("label").first().text().trim(); 4372 errorMessage.push(`Please select an option for ${labelText}.`); 4373 isValid = false; 4374 } 4375 }); 4376 4377 // Validate radio buttons (at least one checked per name group) 4378 let checkboxGroups = {}; 4379 $("div#div_product_questions input[type='checkbox']:visible").each(function () { 4380 let name = $(this).attr("name"); 4381 if (!checkboxGroups[name]) { 4382 checkboxGroups[name] = false; 4383 } 4384 if ($(`input[name="${name}"]:checked`).length > 0) { 4385 checkboxGroups[name] = true; 4386 } 4387 }); 4388 4389 $.each(checkboxGroups, function (name, isChecked) { 4390 if (!isChecked) { 4391 let labelText = $(`input[name="${name}"]`).closest("div").parent("div").parent("div").find("label").first().text().trim(); 4392 errorMessage.push(`Please select an checkbox for ${labelText}.`); 4393 isValid = false; 4394 } 4395 }); 4396 4397 // // Validate at least one checkbox selected (if checkboxes exist) 4398 // if ($("div#div_product_questions input[type='checkbox']:visible").length > 0 && $("div#div_product_questions input[type='checkbox']:checked").length === 0) { 4399 // errorMessage.push("Please select at least one option from the checkboxes."); 4400 // isValid = false; 4401 // } 4402 4403 // Prevent form submission if validation fails 4404 if (!isValid) { 4405 //e.preventDefault(); 4406 alert(errorMessage.join("\n")); 4407 $(this).attr('disabled', false); 4408 return false; 4409 } 4410 } 4411 4412 //Upload Files and Get Name 4413 var formData = new FormData($("div#div_product_questions").parents('form')[0]); 4414 var postFormData = new FormData(); 4415 for (const pair of formData.entries()) { 4416 if(pair[0].toLowerCase().indexOf("data") === -1) { 4417 postFormData.append(pair[0], pair[1]); 4418 } 4419 } 4420 4421 // let resArr = Array.from(postFormData.entries(), ([key, prop]) => ({ 4422 // [key]: { 4423 // "ContentLength": typeof prop === "string" ? prop.length : prop.size 4424 // } 4425 // })); 4426 let resArr = Array.from(postFormData.entries(), ([key, prop]) => ({"ContentLength": typeof prop === "string" ? prop.length : prop.size})); 4427 if(resArr.length > 0) { 4428 arrayLength = resArr.length; 4429 for (var index = 0; index < arrayLength; index++) { 4430 let contentLength = resArr[index]['ContentLength']; 4431 //console.log(contentLength); 4432 //delayTime = (parseInt(contentLength) > 1048576) ? parseInt(contentLength/1048576) * 1000 : 1000; 4433 //if(parseInt(contentLength) > 1048576 && parseInt(contentLength/1048576) > 5) { 4434 let newDelayTime = (parseInt(contentLength) > 200000) ? parseInt(contentLength/200000) * 1000 : 1000; 4435 if(parseInt(contentLength) > 200000 && parseInt(contentLength/200000) > 30) { 4436 alert("Max file size upload allowed is 5 MB"); 4437 $(this).attr('disabled', false); 4438 return false; 4439 } 4440 4441 if(parseInt(delayTime) < parseInt(newDelayTime)) { 4442 delayTime = newDelayTime; 4443 } 4444 } 4445 } 4446 4447 // let input_fields = ($("div#div_product_questions :input").length > 0) ? $("div#div_product_questions input:file") : ''; 4448 // jQuery.each(jQuery('#form_field_')[0].files, function(i, file) { 4449 // data.append('file-'+i, file); 4450 // }); 4451 4452 // let input_fields = ($("div#div_product_questions :input").length > 0) ? $("div#div_product_questions :input").serialize() : ''; 4453 // if(input_fields.length > 0) { 4454 // all_fields.push(input_fields); 4455 // } 4456 4457 // let select_fields = ($("div#div_product_questions select").length > 0) ? $("div#div_product_questions select").serialize() : ''; 4458 // if(select_fields.length > 0) { 4459 // all_fields.push(select_fields); 4460 // } 4461 4462 // let textarea_fields = ($("div#div_product_questions textarea").length > 0) ? $("div#div_product_questions textarea").serialize() : ''; 4463 // if(textarea_fields.length > 0) { 4464 // all_fields.push(textarea_fields); 4465 // } 4466 4467 // string_fields = all_fields.join("&"); 4468 4469 // //Set Product ID 4470 // string_fields = string_fields + "&product_id=" + product_id; 4471 // if(string_fields.length > 1) { 4472 4473 if(postFormData) { 4474 postFormData.append("product_id", product_id); 4475 //let FormData = string_fields; 4476 $.ajax({
4477 type: "POST", 4478 async: true, 4479 cache: false, 4480 url: "/store_carts/ajax_add_form_answers", 4481 dataType: "json", 4482 data: postFormData, 4483 contentType: false, 4484 processData: false, 4485 beforeSend: function(XMLHttpRequest) { 4486 4487 }, 4488 success: $.proxy(function(responseData, textStatus) { 4489 if(responseData.success == true) { 4490 let form_answer_id = responseData.data.form_answer_id; 4491 $(this).closest("form").find("input#form_answer_id").val(form_answer_id); 4492 } 4493 }, this), 4494 error: function(jqXHR, textStatus, errorThrown) { 4495 if (jqXHR.status == 500) { 4496 alert('Internal error: ' + jqXHR.responseText); 4497 } 4498 } 4499 }); 4500 } 4501 } 4502 // New Code for adding custom form ends 4503 4504 setTimeout($.proxy(function() { 4505 var c = ($(this).closest("form").find("input#StoreCartId").val(), $(this).closest("form").find("input#StoreCartTrackInventory").val()), 4506 d = parseInt($(this).closest("form").find("input#StoreCartAllowPurchase").val()), 4507 e = parseInt($(this).closest("form").find("input#StoreCartProductQuantity").val()), 4508 f = parseInt($(this).closest("form").find("input#quantity").val()), 4509 g = parseInt($(this).closest("form").find("input#quantity").attr("min")), 4510 h = ($(this).closest("form").find("input#StoreCartVariantExist").length > 0) ? parseInt($(this).closest("form").find("input#StoreCartVariantExist").val()) : 0, 4511 i = ($(this).closest("form").find(".product_variant").length > 0) ? parseInt($(this).closest("form").find(".product_variant").find(":selected").data("productvariantquantity")) : 0, 4512 j = 0; 4513 4514 if (null != g && g > f) return alert("Product minimum order quantity is " + g + "."), $(this).attr('disabled', false), !1; 4515 if (1 == c && 0 == d && (h > 0 ? f > i && f > 0 && (j = 1) : f > e && f > 0 && (j = 1)), 1 == j) alert(j), $("#inventoryModal").modal("show"); 4516 else { 4517 let isValid2 = true; 4518 let errorMessage2 = []; 4519 4520 if($(this).closest("form").find("select#title").length > 0 && $(this).closest("form").find("select#title").is(":visible")) { 4521 if((typeof $(this).closest("form").find("select#title").val() == 'undefined') || ($(this).closest("form").find("select#title").val()).length <= 0 ) { 4522 errorMessage2.push(`Please select title.`); 4523 isValid2 = false; 4524 } 4525 } 4526 4527 if($(this).closest("form").find("input#full_name").length > 0 && $(this).closest("form").find("input#full_name").is(":visible")) { 4528 if((typeof $(this).closest("form").find("input#full_name").val() == 'undefined') || ($(this).closest("form").find("input#full_name").val()).length <= 0 ) { 4529 errorMessage2.push(`Please enter fullname.`); 4530 isValid2 = false; 4531 } 4532 } 4533 4534 if($(this).closest("form").find("input#place_of_birth").length > 0 && $(this).closest("form").find("input#place_of_birth").is(":visible")) { 4535 if((typeof $(this).closest("form").find("input#place_of_birth").val() == 'undefined') || ($(this).closest("form").find("input#place_of_birth").val()).length <= 0 ) { 4536 errorMessage2.push(`Please enter place of birth.`); 4537 isValid2 = false; 4538 } 4539 } 4540 4541 4542 if($(this).closest("form").find("select#gender").length > 0 && $(this).closest("form").find("select#gender").is(":visible")) { 4543 if((typeof $(this).closest("form").find("select#gender").val() == 'undefined') || ($(this).closest("form").find("select#gender").val()).length <= 0 ) { 4544 errorMessage2.push(`Please select gender.`); 4545 isValid2 = false; 4546 } 4547 } 4548 4549 if($(this).closest("form").find("select#marital_status").length > 0 && $(this).closest("form").find("select#marital_status").is(":visible")) { 4550 if((typeof $(this).closest("form").find("select#marital_status").val() == 'undefined') || ($(this).closest("form").find("select#marital_status").val()).length <= 0 ) { 4551 errorMessage2.push(`Please enter marital status.`); 4552 isValid2 = false; 4553 } 4554 } 4555 4556 if($(this).closest("form").find("textarea#other_information").length > 0 && $(this).closest("form").find("textarea#other_information").is(":visible")) { 4557 if(((typeof $(this).closest("form").find("textarea#other_information").val() == 'undefined') || ($(this).closest("form").find("textarea#other_information").val().length <= 0)) && ($(this).closest("form").find("textarea#other_information").hasClass('required') || $(this).closest("form").find("textarea#other_information").is('[required]'))) { 4558 errorMessage2.push(`Please enter other information.`); 4559 isValid2 = false; 4560 } 4561 } 4562 4563 // Prevent form submission if validation fails 4564 if (!isValid2) { 4565 alert(errorMessage2.join("\n")); 4566 $(this).attr('disabled', false); 4567 return false; 4568 } 4569 4570 //console.log($(this).closest("form")); 4571 var l = ($(this).closest("form").attr("id"), $(this).closest("form").find("input#StoreCartId").val()), 4572 m = $(this).closest("form").find("#StoreCartProductVariantId").val(), 4573 n = $(this).closest("form").find("input#quantity").val(), 4574 o = "data[StoreCart][id]=" + l + "&data[StoreCart][product_variant_id]=" + m + "&data[StoreCart][quantity]=" + n, 4575 4576 p = (typeof $(this).closest("form").find("select#title").val() !== 'undefined') ? $(this).closest("form").find("select#title").val() : '', 4577 q = (typeof $(this).closest("form").find("input#full_name").val() !== 'undefined') ? $(this).closest("form").find("input#full_name").val() : '', 4578 r = (typeof $(this).closest("form").find("input#email").val() !== 'undefined') ? $(this).closest("form").find("input#email").val() : '', 4579 s = (typeof $(this).closest("form").find("input#date_of_birth").val() !== 'undefined') ? $(this).closest("form").find("input#date_of_birth").val() : '', 4580 4581 tHour = (typeof $(this).closest("form").find("input#time_of_birthHour").val() !== 'undefined') ? $(this).closest("form").find("input#time_of_birthHour").val() : '', 4582 tMin = (typeof $(this).closest("form").find("input#time_of_birthMinute").val() !== 'undefined') ? $(this).closest("form").find("input#time_of_birthMinute").val() : '', 4583 tMeridian = (typeof $(this).closest("form").find("input#time_of_birthMeridian").val() !== 'undefined') ? $(this).closest("form").find("input#time_of_birthMeridian").val() : '', 4584 //t = tHour+":"+tMin+" "+tMeridian; 4585 t = (tHour.length > 0 || tMin.length > 0) ? tHour+":"+tMin+" "+tMeridian : '', 4586 4587 //t = (typeof $(this).closest("form").find("input#time_of_birth").val() !== 'undefined') ? $(this).closest("form").find("input#time_of_birth").val() : '', 4588 u = (typeof $(this).closest("form").find("input#place_of_birth").val() !== 'undefined') ? $(this).closest("form").find("input#place_of_birth").val() : '', 4589 v = (typeof $(this).closest("form").find("select#gender").val() !== 'undefined') ? $(this).closest("form").find("select#gender").val() : '', 4590 w = (typeof $(this).closest("form").find("input#marital_status").val() !== 'undefined') ? $(this).closest("form").find("input#marital_status").val() : '', 4591 x = (typeof $(this).closest("form").find("textarea#other_information").val() !== 'undefined') ? $(this).closest("form").find("textarea#other_information").val() : '', 4592 4593 y = "&data[StoreCart][title]=" + p + "&data[StoreCart][full_name]=" + q + "&data[StoreCart][email]=" + r + "&data[StoreCart][date_of_birth]=" + s + "&data[StoreCart][time_of_birth]=" + t + "&data[StoreCart][place_of_birth]=" + u + "&data[StoreCart][gender]=" + v + "&data[StoreCart][marital_status]=" + w + "&data[StoreCart][other_information]=" + x, 4594 z = o + y; 4595 4596 if (m == undefined) { 4597 m = $(this).closest("form").find("input.m_variant").val(); 4598 o = "data[StoreCart][id]=" + l + "&data[StoreCart][product_variant_id]=" + m + "&data[StoreCart][quantity]=" + n 4599 y = "&data[StoreCart][title]=" + p + "&data[StoreCart][full_name]=" + q + "&data[StoreCart][email]=" + r + "&data[StoreCart][date_of_birth]=" + s + "&data[StoreCart][time_of_birth]=" + t + "&data[StoreCart][place_of_birth]=" + u + "&data[StoreCart][gender]=" + v + "&data[StoreCart][marital_status]=" + w + "&data[StoreCart][other_information]=" + x, 4600 z = o + y; 4601 } 4602 4603 a1 = (typeof $(this).closest("form").find("input#is_gift_card").val() !== 'undefined') ? $(this).closest("form").find("input#is_gift_card").val() : 0; 4604 z = z + "&data[StoreCart][is_gift_card]=" + a1; 4605 4606 b1 = (typeof $(this).closest("form").find("input#selection_type").val() !== 'undefined') ? $(this).closest("form").find("input#selection_type").val() : 0; 4607 z = z + "&data[StoreCart][measurement_type]=" + b1; 4608 4609 if(parseInt(b1) == 2) { 4610 if(typeof $(this).closest("form").find("select#saved_measurement").val() !== 'undefined') { 4611 c1 = (typeof $(this).closest("form").find("select#saved_measurement").val() !== 'undefined') ? $(this).closest("form").find("select#saved_measurement").val() : 0; 4612 if(c1.length > 0) { 4613 z = z + "&data[StoreCart][form_answer_id]=" + c1; 4614 } else { 4615 // alert("Please select a detail option to continue."); 4616 // $(this).attr('disabled', false); 4617 // return; 4618 } 4619 } else if(typeof $(this).closest("form").find("input#form_answer_id").val() !== 'undefined') { 4620 c1 = (typeof $(this).closest("form").find("input#form_answer_id").val() !== 'undefined') ? $(this).closest("form").find("input#form_answer_id").val() : 0; 4621 z = z + "&data[StoreCart][form_answer_id]=" + c1; 4622 } 4623 } else if(parseInt(b1) == 1) { 4624 d1 = (typeof $(this).closest("form").find("select#size_dropdown").val() !== 'undefined') ? $(this).closest("form").find("select#size_dropdown").val() : 0; 4625 if(d1.length > 0) { 4626 z = z + "&data[StoreCart][custom_size]=" + d1; 4627 } else { 4628 alert("Please select size to continue."); 4629 $(this).attr('disabled', false); 4630 return; 4631 } 4632 } else if(parseInt(b1) == 0) { 4633 e1 = (typeof $(this).closest("form").find("input#form_answer_id").val() !== 'undefined') ? $(this).closest("form").find("input#form_answer_id").val() : 0; 4634 z = z + "&data[StoreCart][form_answer_id]=" + e1; 4635 } 4636 4637 if (typeof $(this).closest("form").find("input#waist").val() !== 'undefined') { 4638 z = z + "&data[StoreCart][waist]=" + $(this).closest("form").find("input#waist").val(); 4639 } 4640 if (typeof $(this).closest("form").find("input#hip").val() !== 'undefined') { 4641 z = z + "&data[StoreCart][hip]=" + $(this).closest("form").find("input#hip").val(); 4642 } 4643 if (typeof $(this).closest("form").find("input#length").val() !== 'undefined') { 4644 z = z + "&data[StoreCart][length]=" + $(this).closest("form").find("input#length").val(); 4645 } 4646 4647 var checked_addons = ""; 4648 if(document.getElementsByName("product_addons[]").length > 0) { 4649 var product_addons = document.getElementsByName("product_addons[]"); 4650 for(pa = 0; pa < product_addons.length; pa++) { 4651 if(product_addons[pa].checked == true) { 4652 checked_addons = checked_addons + product_addons[pa].value + ","; 4653 } 4654 } 4655 } 4656 4657 if(is_subscribe === true) { 4658 $.ajax({
4659 type: "POST", 4660 async: !0, 4661 cache: !1, 4662 url: "/subscriptions/ajax_add_subscribe", 4663 dataType: "html", 4664 data: z, 4665 beforeSend: function() {}, 4666 success: function(responseData) { 4667 var sresponse = responseData.replace(/\s+/g, ''); 4668 4669 if (sresponse == "variant_missing" && document.getElementById("size_error") !== 'undefined' && document.getElementById("size_error") !== null) { 4670 document.getElementById("size_error").innerHTML = "Please select a variant to continue"; 4671 is_subscribe = false; 4672 return false; 4673 } else if (sresponse == "variant_missing") { 4674 var result = ''; 4675 var variant_count = Theme.ProductData.product.options.length; 4676 if(variant_count < 2) { 4677 result = Theme.ProductData.product.options[0].toLowerCase(); 4678 } 4679 alert('Kindly select '+result+' option'); 4680 is_subscribe = false; 4681 return false; 4682 } 4683 4684 setTimeout(function() { 4685 if(is_subscribe !== false) { 4686 window.location.href = "/subscriptions/cart"; 4687 return false 4688 } 4689 }, 1000); 4690 4691 // if(is_buy_now === false && checked_addons.length < 1) { 4692 // $("#targetDiv").html(responseData); 4693 // if(parseInt(window.Store.TemplateConfig.show_sidebar_on_addcart) == 1) { 4694 // $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 4695 // } 4696 // $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 4697 // } 4698 }, 4699 error: function(a) { 4700 alert(500 == a.status ? "Internal error: " + a.responseText : "Unexpected error.") 4701 }, 4702 complete: function() { 4703 // Conversion.Utils.setConversion('AddToCart', n); 4704 } 4705 }); 4706 } else { 4707 $.ajax({
4708 type: "POST", 4709 async: !0, 4710 cache: !1, 4711 url: "/store_carts/ajax_add", 4712 dataType: "html", 4713 data: z, 4714 beforeSend: function() {}, 4715 success: function(responseData) { 4716 var sresponse = responseData.replace(/\s+/g, ''); 4717 4718 if (sresponse == "variant_missing" && document.getElementById("size_error") !== 'undefined' && document.getElementById("size_error") !== null) { 4719 document.getElementById("size_error").innerHTML = "Please select a variant to continue"; 4720 is_buy_now = false; 4721 return false; 4722 } else if (sresponse == "variant_missing") { 4723 var result = ''; 4724 var variant_count = Theme.ProductData.product.options.length; 4725 if(variant_count < 2){ 4726 result = Theme.ProductData.product.options[0].toLowerCase(); 4727 } 4728 alert('Kindly select '+result+' option'); 4729 is_buy_now = false; 4730 return false; 4731 } 4732 4733 if(window.metrilo !== undefined) { 4734 const productId = l; // The ID of the added product 4735 const quantity = n; // The quantity of added items 4736 window.metrilo.addToCart(productId, quantity) 4737 } 4738 4739 if(is_buy_now === false && checked_addons.length < 1) { 4740 $("#targetDiv").html(responseData); 4741 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 4742 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 4743 } 4744 }, 4745 error: function(a) { 4746 alert(500 == a.status ? "Internal error: " + a.responseText : "Unexpected error.") 4747 }, 4748 complete: function() { 4749 Conversion.Utils.setConversion('AddToCart', n); 4750 } 4751 }).done(function (data) { 4752 // New Code for adding addon starts 4753 if(checked_addons.length > 1) { 4754 //Check Addon Quantity 4755 var allowAdd = 0; 4756 var ProductId = 0; 4757 var ProductAddonValueId = 0; 4758 ProductId = $("#product_id").val(); 4759 //ProductAddonValueId = $("#product_addon_value_id").val(); 4760 ProductAddonValueId = checked_addons; 4761 if (ProductId && ProductAddonValueId) { 4762 allowAdd = 1; 4763 } else if (!ProductId || !ProductAddonValueId) { 4764 allowAdd = 0; 4765 } 4766 4767 //Now Process To Addon 4768 if (parseInt(allowAdd) == 1) { 4769 //Check Form Process 4770 var FormID = $(this).closest("form").attr('id'); 4771 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][product_addon_value_id]=" + ProductAddonValueId; 4772 $.ajax({
4773 type: "POST", 4774 async: true, 4775 cache: false, 4776 url: "/store_carts/ajax_addon", 4777 dataType: "html", 4778 data: FormData, 4779 beforeSend: function(XMLHttpRequest) { 4780 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 4781 }, 4782 success: function(responseData, textStatus) { 4783 if(is_buy_now === false) { 4784 if($("#targetDiv").length > 0) { 4785 $("#targetDiv").html(responseData); 4786 } 4787 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 4788 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 4789 } 4790 /* 4791 if (data.length > 0 && data.trim() !== "failure") { 4792 alert("Addon added successfully"); 4793 } else { 4794 alert("Please add this product to your cart before choosing the addon."); 4795 } 4796 */ 4797 }, 4798 error: function(jqXHR, textStatus, errorThrown) { 4799 if (jqXHR.status == 500) { 4800 alert('Internal error: ' + jqXHR.responseText); 4801 } 4802 } 4803 }); 4804 // // stop the form from submitting the normal way and refreshing the page 4805 // return false; 4806 } 4807 } 4808 // New code for adding addon ends here 4809 }); 4810 } 4811 } 4812 4813 $(this).attr('disabled', false); 4814 4815 setTimeout(function() { 4816 if(is_buy_now !== false) { 4817 if(window.Store.PaymentConfig.gokwik.merchant_id == '') { 4818 window.location.href = "/store_carts/cart"; 4819 } else { 4820 $("button.btngokwik").click(); 4821 } 4822 } else if(is_subscribe !== false) { 4823 window.location.href = "/subscriptions/cart"; 4824 } else { 4825 return !1; 4826 } 4827 }, 1000); 4828 }, this), delayTime); 4829 }); 4830 }, 4831 ajaxAddMultipleVariantProduct: function() { 4832 var m_count = 0; 4833 $('body').on("click", ".btn-add-multi-variant-cart", function(a) { 4834 a.preventDefault(); 4835 a.stopImmediatePropagation(); 4836 let btnAddMultiVariant = $(this); 4837 btnAddMultiVariant.attr('disabled', true); 4838
4839 var is_buy_now = btnAddMultiVariant.hasClass("btn-buynow"); 4840 let product_id = btnAddMultiVariant.closest("form").find("input#StoreCartId").val(); 4841 let product_variant_ids = btnAddMultiVariant.closest("form").find("input#StoreCartId").val(); 4842 let delayTime = 0; //2000; //2 seconds = 2000 microseconds 4843 4844 if ($("div#diverror").length > 0) { 4845 if (parseInt(Theme.ProductData.product.minimum_order_quantity) > 0 && $("input#quantity").val() < parseInt(Theme.ProductData.product.minimum_order_quantity)) { 4846 $("div#diverror").show().find(".label-danger").html("Minimum order quantity must be " + parseInt(Theme.ProductData.product.minimum_order_quantity) + ""); 4847 btnAddMultiVariant.attr('disabled', false); 4848 return; 4849 } else { 4850 $("div#diverror").hide().find(".label-danger").html(''); 4851 } 4852 } 4853 4854 // New Code for adding custom form starts 4855 // Custom Form Fields 23-08-2022 4856 let all_fields = []; 4857 let string_fields = ''; 4858 if($("div#div_product_questions").length > 0) { 4859 let input_fields = ($("div#div_product_questions :input").length > 0) ? $("div#div_product_questions :input").serialize() : ''; 4860 if(input_fields.length > 0) { 4861 all_fields.push(input_fields); 4862 } 4863 4864 let select_fields = ($("div#div_product_questions select").length > 0) ? $("div#div_product_questions select").serialize() : ''; 4865 if(select_fields.length > 0) { 4866 all_fields.push(select_fields); 4867 } 4868 4869 let textarea_fields = ($("div#div_product_questions textarea").length > 0) ? $("div#div_product_questions textarea").serialize() : ''; 4870 if(textarea_fields.length > 0) { 4871 all_fields.push(textarea_fields); 4872 } 4873 4874 string_fields = all_fields.join("&"); 4875 4876 //Set Product ID 4877 string_fields = string_fields + "&product_id=" + product_id; 4878 4879 if(string_fields.length > 1) { 4880 let FormData = string_fields; 4881 delayTime = 2000; 4882 $.ajax({
4883 type: "POST", 4884 async: true, 4885 cache: false, 4886 url: "/store_carts/ajax_add_form_answers", 4887 dataType: "json", 4888 data: FormData, 4889 beforeSend: function(XMLHttpRequest) { 4890 4891 }, 4892 success: $.proxy(function(responseData, textStatus) { 4893 if(responseData.success == true) { 4894 let form_answer_id = responseData.data.form_answer_id; 4895 $(this).closest("form").find("input#form_answer_id").val(form_answer_id); 4896 } 4897 }, this), 4898 error: function(jqXHR, textStatus, errorThrown) { 4899 if (jqXHR.status == 500) { 4900 alert('Internal error: ' + jqXHR.responseText); 4901 } 4902 } 4903 }); 4904 } 4905 } 4906 // New Code for adding custom form ends 4907 4908 setTimeout($.proxy(function() { 4909 //let FormData = $(this).parents('form:first').serialize(); 4910 let formData = ''; 4911 let totalOrderQuantity = 0; 4912 4913 let product_id = (typeof btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][id]']").val() !== 'undefined') ? btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][id]']").val() : 0; 4914 formData = formData + 'data[StoreCart][id]=' + product_id; 4915 4916 let product_variant_ids = []; 4917 btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][product_variant_id]']").each(function() { 4918 product_variant_ids.push($(this).val()); 4919 }); 4920 4921 //Enable product set-wise buying option 4922 let product_set_wise_buying_option_enabled = $("#product_set_wise_buying_option_enabled").val(); 4923 if(product_set_wise_buying_option_enabled == 1) { 4924 let checkvariantqty = 0; 4925 if(product_variant_ids.length > 0) { 4926 $.each(product_variant_ids, function(index, product_variant_id) { 4927 4928 let stock_qty = $("#quantity_"+ product_id +"_"+ product_variant_id).data("quantity"); 4929 let moq_qty = $("#quantity_"+ product_id +"_"+ product_variant_id).data("moqQuantity"); 4930 let qty = $("#quantity_"+ product_id +"_"+ product_variant_id).val(); 4931 if(checkvariantqty == 0 && stock_qty > 0 && qty < moq_qty){ 4932 checkvariantqty = 1; 4933 } 4934 4935 }); 4936 } 4937 if(checkvariantqty == 1) { 4938 alert("Please enter minimum order quantity for all variants"); 4939 $("button#add-to-cart").removeAttr("disabled").removeClass("disabled btn-outstock").html(Theme.Language.getStr("AddToCartListButton")).css("display", "block"); // set add-to-cart button to unavailable class and disable button 4940 //$("button.btn-buynow").removeAttr("disabled").removeClass("disabled").show(); 4941 return false; 4942 } 4943 } 4944 4945 formData = formData + '&data[StoreCart][product_variant_id]=' + product_variant_ids; 4946 4947 if(product_variant_ids.length > 0) { 4948 $.each(product_variant_ids, function(index, product_variant_id) { 4949 if(parseInt(btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][quantity_"+ product_id +"_"+ product_variant_id +"]']").val()) > 0) { 4950 formData = formData + '&data[StoreCart][quantity_'+ product_id +'_'+ product_variant_id +']=' + parseInt(btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][quantity_"+ product_id +"_"+ product_variant_id +"]']").val()); 4951 totalOrderQuantity = totalOrderQuantity + parseInt(btnAddMultiVariant.parents('form:first').find("input[name='data[StoreCart][quantity_"+ product_id +"_"+ product_variant_id +"]']").val()); 4952 } 4953 }); 4954 } 4955 4956 let checked_addons = ""; 4957 if(document.getElementsByName("product_addons[]").length > 0) { 4958 let product_addons = document.getElementsByName("product_addons[]"); 4959 for(pa = 0; pa < product_addons.length; pa++) { 4960 if(product_addons[pa].checked == true) { 4961 checked_addons = checked_addons + product_addons[pa].value + ","; 4962 } 4963 } 4964 } 4965 4966 //Multi Variant Add 4967 $.ajax({
4968 type: "POST", 4969 async: !0, 4970 cache: !1, 4971 url: "/store_carts/ajax_multi_variant_add", 4972 dataType: "html", 4973 data: formData, 4974 beforeSend: function() {}, 4975 success: function(responseData) { 4976 var sresponse = responseData.replace(/\s+/g, ''); 4977 4978 if (sresponse == "variant_missing" && document.getElementById("size_error") !== 'undefined' && document.getElementById("size_error") !== null) { 4979 document.getElementById("size_error").innerHTML = "Please select a variant to continue"; 4980 is_buy_now = false; 4981 return false; 4982 } else if (sresponse == "variant_missing") { 4983 var result = ''; 4984 var variant_count = Theme.ProductData.product.options.length; 4985 if(variant_count < 2) { 4986 result = Theme.ProductData.product.options[0].toLowerCase(); 4987 } 4988 alert('Kindly select '+ result +' option'); 4989 is_buy_now = false; 4990 return false; 4991 } 4992 4993 if(window.metrilo !== undefined) { 4994 const productId = product_id; // The ID of the added product 4995 const quantity = totalOrderQuantity; // The quantity of added items 4996 window.metrilo.addToCart(productId, quantity) 4997 } 4998 4999 if(is_buy_now === false && checked_addons.length < 1) { 5000 $("#targetDiv").html(responseData); 5001 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 5002 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 5003 } 5004 }, 5005 error: function(a) { 5006 alert(500 == a.status ? "Internal error: " + a.responseText : "Unexpected error.") 5007 }, 5008 complete: function() { 5009 Conversion.Utils.setConversion('AddToCart', totalOrderQuantity); 5010 } 5011 }).done(function (data) { 5012 // New Code for adding addon starts 5013 if(checked_addons.length > 1) { 5014 //Check Addon Quantity 5015 var allowAdd = 0; 5016 var ProductId = 0; 5017 var ProductAddonValueId = 0; 5018 ProductId = $("#product_id").val(); 5019 //ProductAddonValueId = $("#product_addon_value_id").val(); 5020 ProductAddonValueId = checked_addons; 5021 if (ProductId && ProductAddonValueId) { 5022 allowAdd = 1; 5023 } else if (!ProductId || !ProductAddonValueId) { 5024 allowAdd = 0; 5025 } 5026 5027 //Now Process To Addon 5028 if (parseInt(allowAdd) == 1) { 5029 //Check Form Process 5030 var FormID = $(this).closest("form").attr('id'); 5031 var FormData = "data[StoreCart][id]=" + ProductId + "&data[StoreCart][product_addon_value_id]=" + ProductAddonValueId; 5032 $.ajax({
5033 type: "POST", 5034 async: true, 5035 cache: false, 5036 url: "/store_carts/ajax_addon", 5037 dataType: "html", 5038 data: FormData, 5039 beforeSend: function(XMLHttpRequest) { 5040 //$("#StoreOrderPaymentCityId").find("option").not(':first').remove(); 5041 }, 5042 success: function(responseData, textStatus) { 5043 if(is_buy_now === false) { 5044 if($("#targetDiv").length > 0) { 5045 $("#targetDiv").html(responseData); 5046 } 5047 $("#div-drop-cart div.cd-cart-trigger").trigger("click"); 5048 $("#div-drop-cart span.rounded-circle").html($("#ccount").val()); 5049 } 5050 /* 5051 if (data.length > 0 && data.trim() !== "failure") { 5052 alert("Addon added successfully"); 5053 } else { 5054 alert("Please add this product to your cart before choosing the addon."); 5055 } 5056 */ 5057 }, 5058 error: function(jqXHR, textStatus, errorThrown) { 5059 if (jqXHR.status == 500) { 5060 alert('Internal error: ' + jqXHR.responseText); 5061 } 5062 } 5063 }); 5064 // // stop the form from submitting the normal way and refreshing the page 5065 // return false; 5066 } 5067 } 5068 // New code for adding addon ends here 5069 }); 5070 5071 $(this).attr('disabled', false); 5072 5073 setTimeout(function() { 5074 return !1; 5075 }, 2000); 5076 }, this), delayTime); 5077 }); 5078 }, 5079 }, 5080 Theme.Utils.Customer = { 5081 initCustomer: function() { 5082 window.phone_intlTel = Theme.Utils.PhoneCountryCode('phonenumber', defaultValues.PhoneISO2); 5083 window.mobile_intlTel = Theme.Utils.PhoneCountryCode('phone', defaultValues.PhoneISO2); 5084 Theme.Utils.Element.init(); 5085 Theme.Utils.Customer.changeCountry(); 5086 //Theme.Utils.Customer.changeState(); 5087 if (parseInt(defaultValues.CountryId) > 0) { 5088 $("select#country_id").change(); 5089 } 5090 5091 $("button.editemail").on("click", function() { 5092 $("#otpdiv").hide(); 5093 $("#emaildiv").show(); 5094 $("label.error").html(''); 5095 }); 5096 5097 //Resend OTP 5098 $("button.resend-otp").on("click", function() { 5099 var action = 0; 5100 var email = $("input#emailotp").val(); 5101 5102 $.ajax({
5103 type: "POST", 5104 async: true, 5105 cache: false, 5106 url: "/customers/resend_otp", 5107 accepts: 'application/json', 5108 dataType: "json", 5109 data: "data[Customer][email]=" + email +"&data[Customer][action]=" + action, 5110 beforeSend: function(XMLHttpRequest) { 5111 $('button[type="button"]').addClass("disabled").attr("disabled", "disabled"); 5112 }, 5113 complete: function() { 5114 5115 }, 5116 success: function(data, textStatus) { 5117 if (data.status == 1) { 5118 window.location.reload(); 5119 5120 } else { 5121 $('button[type="button"]').removeClass("disabled").removeAttr("disabled"); 5122 $("label.error").html(data.message); 5123 5124 } 5125 }, 5126 error: function(jqXHR, textStatus, errorThrown) { 5127 if (jqXHR.status == 500) { 5128 alert('Internal error: ' + jqXHR.responseText); 5129 } 5130 } 5131 }); 5132 }); 5133 5134 //Edit eamil address 5135 $("button.editEmail").on("click", function() { 5136 var action = 1; 5137 var email = $("input#emailotp").val(); 5138 5139 $.ajax({
5140 type: "POST", 5141 async: true, 5142 cache: false, 5143 url: "/customers/resend_otp", 5144 accepts: 'application/json', 5145 dataType: "json", 5146 data: "data[Customer][email]=" + email +"&data[Customer][action]=" + action, 5147 beforeSend: function(XMLHttpRequest) { 5148 $('button[type="button"]').addClass("disabled").attr("disabled", "disabled"); 5149 }, 5150 complete: function() { 5151 5152 }, 5153 success: function(data, textStatus) { 5154 if (data.status == 1) { 5155 5156 window.location.reload(); 5157 /*if(action == 1){ 5158 5159 }else{ 5160 $("#otpdiv").show(); 5161 $("#emaildiv").hide(); 5162 $("label.error").html('Otp resent successfully'); 5163 $('button[type="button"]').removeClass("disabled").removeAttr("disabled"); 5164 }*/ 5165 } else { 5166 $('button[type="button"]').removeClass("disabled").removeAttr("disabled"); 5167 $("label.error").html(data.message); 5168 5169 } 5170 }, 5171 error: function(jqXHR, textStatus, errorThrown) { 5172 if (jqXHR.status == 500) { 5173 alert('Internal error: ' + jqXHR.responseText); 5174 } 5175 } 5176 }); 5177 }); 5178 5179 //Verify OTP 5180 $("button.verify-otp").on("click", function() { 5181 var otp = $("input#email_otp").val(); 5182 var email = $("input#email").val(); 5183 if(otp == '') { 5184 $("label.error").html('Please enter valid otp'); 5185 return false; 5186 } 5187 5188 $.ajax({
5189 type: "POST", 5190 async: true, 5191 cache: false, 5192 url: "/customers/verify_otp", 5193 accepts: 'application/json', 5194 dataType: "json", 5195 data: "data[Customer][email]=" + email + "&data[Customer][otp]=" + otp, 5196 beforeSend: function(XMLHttpRequest) { 5197 $('button[type="button"]').addClass("disabled").attr("disabled", "disabled"); 5198 }, 5199 complete: function() { 5200 5201 }, 5202 success: function(data, textStatus) { 5203 if (data.status == 1) { 5204 window.location.href= "/"; 5205 } else { 5206 $('button[type="button"]').removeClass("disabled").removeAttr("disabled"); 5207 $("label.error").html('Invalid otp, Please try again'); 5208 } 5209 }, 5210 error: function(jqXHR, textStatus, errorThrown) { 5211 if (jqXHR.status == 500) { 5212 alert('Internal error: ' + jqXHR.responseText); 5213 } 5214 } 5215 }); 5216 }); 5217 }, 5218 initOtp: function() { 5219 Theme.Utils.StoreOrder.reverseCountdownTimer(); 5220 $('.otp-resend-code').hide(); 5221 $('.otp-count-down').show(); 5222 }, 5223 checkEmailExists: function() { 5224 $(document).on('change', 'input.email_exist_check', function(){ 5225 var emailAddress = $(this).val(); 5226 $.ajax({
5227 type: "POST", 5228 async: true, 5229 cache: false, 5230 url: "/customers/ajax_email_exist", 5231 accepts: 'application/json', 5232 dataType: "json", 5233 data: "data[Customer][email]=" + emailAddress, 5234 beforeSend: function(XMLHttpRequest) { 5235 $('button[type="submit"]').addClass("disabled").attr("disabled", "disabled"); 5236 }, 5237 complete: function() { 5238 5239 }, 5240 success: function(data, textStatus) { 5241 if (data.email_exists !== undefined && data.email_exists == 1) { 5242 $('div#div_already_register').removeClass('d-none'); 5243 } else { 5244 $('div#div_already_register').addClass('d-none'); 5245 $('button[type="submit"]').removeClass("disabled").removeAttr("disabled"); 5246 } 5247 }, 5248 error: function(jqXHR, textStatus, errorThrown) { 5249 if (jqXHR.status == 500) { 5250 alert('Internal error: ' + jqXHR.responseText); 5251 } 5252 } 5253 }); 5254 }); 5255 }, 5256 initEditProfile: function() { 5257 Theme.Utils.Element.init(); 5258 Theme.Utils.Customer.changeCountry(); 5259 //Theme.Utils.Customer.changeState(); 5260 window.phone_intlTel = Theme.Utils.PhoneCountryCode('phone', defaultValues.PhoneISO2); 5261 window.alternate_phone_intlTel = Theme.Utils.PhoneCountryCode('alternate_phone', defaultValues.PhoneISO2); 5262 5263 window.shipping_phone_intlTel = Theme.Utils.PhoneCountryCode('shipping_phone', defaultValues.ShippingPhoneISO2); 5264 window.payment_phone_intlTel = Theme.Utils.PhoneCountryCode('payment_phone', defaultValues.PaymentPhoneISO2); 5265 //Check Phone Number and Pincode 5266 if (parseInt(defaultValues.CountryId) > 0) { 5267 if (parseInt(defaultValues.CountryId) == 101) { 5268 $("#phone").attr("minlength", 10).attr("maxlength", 11); 5269 $("#zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 5270 } else { 5271 $("#phone").removeAttr("minlength").attr("maxlength", 20); 5272 $("#zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 5273 } 5274 } 5275 5276 //Display Values Accordingly 5277 if (parseInt(defaultValues.StateId) > 0) { 5278 $("#state_name").val('').hide(); 5279 $("select#state_id").show().attr("required", "required"); 5280 $("input#city_name").show().attr("required", "required"); 5281 } else { 5282 $("select#state_id").val(0).removeAttr("required").hide(); 5283 $("input#state_name").show(); 5284 $("input#city_name").show().removeAttr("required"); 5285 } 5286 5287 $("#CustomerEditProfileForm").validate({ 5288 ignore: [] 5289 }); 5290 5291 $("#myaccountEditProfileForm").validate({ 5292 submitHandler: function(form) { 5293 //$("button#edit_profile_button").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 5294 let alternate_phone_isd_code = window.alternate_phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 5295 $("input[name='data[Customer][alternate_phone_isd_code]'").val(alternate_phone_isd_code); 5296 5297 let alternate_phone_iso2_code = window.alternate_phone_intlTel.getSelectedCountryData().iso2; 5298 $("input[name='data[Customer][alternate_phone_iso2_code]'").val(alternate_phone_iso2_code.toUpperCase()); 5299 5300 5301 setTimeout(function () { 5302 form.submit(); 5303 }, 500); 5304 } 5305 }); 5306
5307 $("#myaccountChangeLoginDetailsForm").validate({ 5308 submitHandler: function(form) { 5309 //$("button#edit_profile_button").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 5310 let phone_isd_code = window.phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 5311 $("input[name='data[Customer][phone_isd_code]'").val(phone_isd_code); 5312 5313 let phone_iso2_code = window.phone_intlTel.getSelectedCountryData().iso2; 5314 $("input[name='data[Customer][phone_iso2_code]'").val(phone_iso2_code.toUpperCase()); 5315 5316 5317 setTimeout(function () { 5318 form.submit(); 5319 }, 500); 5320 } 5321 }); 5322 }, 5323 initChangePassword: function() { 5324 $("#CustomerPasswordEditProfileForm").validate(); 5325 $("#old_password").rules("add", { 5326 required: true, 5327 messages: { 5328 required: "Please enter valid old password." 5329 } 5330 }); 5331 $("#new_password").rules("add", { 5332 required: true, 5333 messages: { 5334 required: "Please enter valid new password." 5335 } 5336 }); 5337 $("#confirm_password").rules("add", { 5338 required: true, 5339 equalTo: "#new_password", 5340 messages: { 5341 required: "Please enter valid confirm password.", 5342 equalTo: "New Password does not match the confirm password." 5343 } 5344 }); 5345 }, 5346 initResetPassword: function() { 5347 $("#CustomerResetPasswordForm").validate(); 5348 $("#new_password").rules("add", { 5349 required: true, 5350 messages: { 5351 required: "Please enter valid new password." 5352 } 5353 }); 5354 $("#confirm_password").rules("add", { 5355 required: true, 5356 equalTo: "#new_password", 5357 messages: { 5358 required: "Please enter valid confirm password.", 5359 equalTo: "New Password does not match the confirm password." 5360 } 5361 }); 5362 }, 5363 getStates: function(country_id) { 5364 $.ajax({
5365 type: "POST", 5366 async: true, 5367 cache: false, 5368 url: "/customers/getStates", 5369 dataType: "html", 5370 data: { 5371 "data[Customer][country_id]": country_id 5372 }, 5373 beforeSend: function(XMLHttpRequest) { 5374 // $("#CustomerCityId").find("option").remove().end().append("<option value=\"0\">Select City</option>").val(0); 5375 $("select#state_id").find("option").not(':first').remove(); 5376 5377 $("#state_name").hide(); 5378 $("#state_id").hide(); 5379 }, 5380 success: function(data, textStatus) { 5381 if(parseInt(data.length) > 10 && data.trim() != 'Record Not Found') { 5382 $("#state_name").val('').hide(); 5383 $("#state_id").show().attr("required", "required").append(data); 5384 $("select#state_id").closest(".field").addClass("field--show-floating-label"); 5385 $("#city_name").attr("required", "required"); 5386 } else { 5387 $("#state_id").val(0).removeAttr("required").hide(); 5388 $("select#state_id").closest(".field").removeClass("field--show-floating-label"); 5389 $("#state_name").show(); 5390 $("#city_name").removeAttr("required"); 5391 } 5392 }, 5393 error: function(jqXHR, textStatus, errorThrown) { 5394 if (jqXHR.status == 500) { 5395 alert('Internal error: ' + jqXHR.responseText); 5396 } 5397 } 5398 }); 5399 }, 5400 getCities: function(country_id, state_id) { 5401 $.ajax({
5402 type: "POST", 5403 async: true, 5404 cache: false, 5405 url: "/customers/getCities", 5406 dataType: "html", 5407 data: { 5408 "data[Customer][country_id]": country_id, 5409 "data[Customer][state_id]": state_id 5410 }, 5411 beforeSend: function(XMLHttpRequest) { 5412 // $("#CustomerCityId").find("option").remove().end().append("<option value=\"0\">Select City</option>").val(0); 5413 $("#city_id").find("option").not(':first').remove(); 5414 }, 5415 success: function(data, textStatus) { 5416 if(parseInt(data.length) > 10 && data.trim() != 'Record Not Found') { 5417 $("#city_id").append(data); 5418 } 5419 }, 5420 error: function(jqXHR, textStatus, errorThrown) { 5421 if (jqXHR.status == 500) { 5422 alert('Internal error: ' + jqXHR.responseText); 5423 } 5424 } 5425 }); 5426 }, 5427 changeCountry: function() { 5428 $("select#country_id").on("change", function(event) { 5429 $("option:selected", $(this)).each(function() { 5430 var country_id = $(this).val(); 5431 5432 const state_title = ($(this).data('stateTitle')) ? $(this).data('stateTitle') : ''; 5433 const city_title = ($(this).data('cityTitle')) ? $(this).data('cityTitle') : ''; 5434 const is_pincode_required = ($(this).data('isPincodeRequired')) ? $(this).data('isPincodeRequired') : 0; 5435 5436 $("select#state_id").parent('div').find('label.field__label').html(state_title); 5437 $("select#state_id option[value]:first").text("Select " + state_title); 5438 $("select#state_name").attr('placeholder', state_title); 5439 5440 $("input#city_name").parent('div').find('label.field__label').html(city_title); 5441 $("input#city_name").attr('placeholder', city_title); 5442 5443 Theme.Utils.Customer.getStates(country_id); 5444 5445 //Check Phone Number and Pincode 5446 if (parseInt(country_id) == 101) { 5447 $("#phone").attr("minlength", 10).attr("maxlength", 11); 5448 $("#zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 5449 } else { 5450 $("#phone").removeAttr("minlength").attr("maxlength", 20); 5451 $("#zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 5452 } 5453 5454 return false; 5455 }); 5456 }); 5457 }, 5458 changeState: function() { 5459 $("#state_id").on("change", function(event) { 5460 $("option:selected", $(this)).each(function() { 5461 var country_id = $("#country_id").val(); 5462 var state_id = $(this).val(); 5463 Theme.Utils.Customer.getCities(country_id, state_id); 5464 return false; 5465 }); 5466 }); 5467 }, 5468 validateCustomer: function() { 5469 $("#CustomerRegisterForm").validate({ 5470 errorPlacement: function(error, element) { 5471 if (element.parent('.checkbox').length) { 5472 error.insertAfter(element.parent()); 5473 } else { 5474 error.insertAfter(element); 5475 } 5476 }, 5477 submitHandler: function(form) { 5478 $("button#btn_register_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 5479 5480 let phone_isd_code = window.phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 5481 $("input[name='data[Customer][phone_isd_code]'").val(phone_isd_code); 5482 5483 let phone_iso2_code = window.phone_intlTel.getSelectedCountryData().iso2; 5484 $("input[name='data[Customer][phone_iso2_code]'").val(phone_iso2_code.toUpperCase()); 5485 5486 let mobile_isd_code = window.mobile_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 5487 $("input[name='data[Customer][mobile_isd_code]'").val(mobile_isd_code); 5488 5489 let mobile_iso2_code = window.mobile_intlTel.getSelectedCountryData().iso2; 5490 $("input[name='data[Customer][mobile_iso2_code]'").val(mobile_iso2_code.toUpperCase()); 5491 5492 if(window.googleRecaptchaSiteKey !== 'undefined') { 5493 grecaptcha.ready(function () { 5494 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'login'}).then(function (token) { 5495 $(form).find('input#recaptcha_response_register').val(token); 5496 }); 5497 }); 5498 } 5499 5500 5501 return true; 5502 } 5503 }); 5504 $("#CustomerVerifyOtpForm").validate({ 5505 errorPlacement: function(error, element) { 5506 if (element.parent('.checkbox').length) { 5507 error.insertAfter(element.parent()); 5508 } else { 5509 error.insertAfter(element); 5510 } 5511 } 5512 }); 5513 }, 5514 ajaxLogin: function() { 5515 $("#CustomerIndexForm").validate({ 5516 submitHandler: function(form) { 5517 var Email = $(form).find("input#email").val(); 5518 var Password = $(form).find("input#password").val(); 5519 var RedirectUrl = $(form).find("#redirect_url").val(); 5520 var FormData = "data[Customer][email]=" + Email + "&data[Customer][password]=" + Password + "&data[Customer][redirect_url]=" + RedirectUrl + ""; 5521 5522 $.ajax({
5523 type: "POST", 5524 async: true, 5525 cache: false, 5526 url: "/customers/ajax_login", 5527 accepts: 'application/json', 5528 dataType: "json", 5529 data: FormData, 5530 beforeSend: function(XMLHttpRequest) { 5531 $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled"); 5532 }, 5533 complete: function() { 5534 $(form).trigger("reset"); 5535 //$('html,body').animate({ scrollTop: $("#divreview").offset().top - 60}, 1000); 5536 $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled"); 5537 }, 5538 success: function(data, textStatus) { 5539 //console.log(data); 5540 if (data.login_status !== undefined && data.login_status == 1) { 5541 $("#login_err").hide(); 5542 $("#login_success").fadeIn(3000); 5543 $("#loginModal").modal('hide'); 5544 window.location.reload(); 5545 } else { 5546 $("#login_err").show(); 5547 $("#login_success").hide(); 5548 } 5549 }, 5550 error: function(jqXHR, textStatus, errorThrown) { 5551 //alert(errorThrown); 5552 console.log(errorThrown); 5553 if (jqXHR.status == 500) { 5554 alert('Internal error: ' + jqXHR.responseText); 5555 } 5556 } 5557 }); 5558 return false; // blocks redirect after submission via ajax 5559 } 5560 }), $("#CustomerIndexFormPopup").validate({ 5561 submitHandler: function(a) { 5562 5563 var b = $(a).find("input#email_popup").val(), 5564 c = $(a).find("input#password_popup").val(), 5565 d = $(a).find("#redirect_url_popup").val(), 5566 e = "data[Customer][email]=" + b + "&data[Customer][password]=" + c + "&data[Customer][redirect_url]=" + d; 5567 return $.ajax({ 5568 type: "POST", 5569 async: !0, 5570 cache: !1, 5571 url: "/customers/ajax_login", 5572 accepts: "application/json", 5573 dataType: "json", 5574 data: e, 5575 beforeSend: function() { 5576 $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled") 5577 }, 5578 complete: function() { 5579 $(a).trigger("reset"), $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled") 5580 }, 5581 success: function(a) { 5582 void 0 !== a.login_status && 1 == a.login_status ? ($("#login_err").hide(), $("#login_success").fadeIn(3e3), $("#loginModal").modal("hide"), window.location.reload()) : ($("#login_err").show(), $("#login_success").hide()) 5583 }, 5584 error: function(a, b, c) { 5585 console.log(c), 500 == a.status && alert("Internal error: " + a.responseText) 5586 } 5587 }), !1 5588 } 5589 }) 5590 }, 5591 validateLoginOtp: function() { 5592 $("#CustomerLoginFormOtp").validate(); 5593 }, 5594 validateLogin: function() { 5595 $("#CustomerLoginForm").validate(); 5596 }, 5597 validateForgotPassword: function() { 5598 $("form#CustomerForgotPasswordForm").validate({ 5599 errorPlacement: function(error, element) { 5600 if (element.parent('.checkbox').length) { 5601 error.insertAfter(element.parent()); 5602 } else { 5603 error.insertAfter(element); 5604 } 5605 }, 5606 submitHandler: function(form) { 5607 $("button#btn_forgot_password_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 5608 5609 if(window.googleRecaptchaSiteKey !== 'undefined') { 5610 grecaptcha.ready(function () { 5611 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'login'}).then(function (token) { 5612 $(form).find('input#recaptcha_response_forgot_password').val(token); 5613 }); 5614 }); 5615 } 5616 5617 setTimeout(function () { 5618 form.submit(); 5619 }, 2000); 5620 5621 return false; 5622 } 5623 }); 5624 }, 5625 // initManageAddresses: function() { 5626 // Theme.Utils.StoreOrder.changeShippingCountry(); 5627 // $('.edit_address').click(function() { 5628 // var customerAddressId = $(this).data('id'); 5629 // var addressData = customAddressesObject[customerAddressId]; 5630 // $("input#action").val(2); 5631 // if (customerAddressId != null && addressData != undefined) { 5632 // //console.log(addressData); 5633 // if (parseInt(addressData.shipping_state_id) > 0) { 5634 // Theme.Utils.StoreOrder.getShippingStates(addressData.shipping_country_id); 5635 5636 // } 5637 5638 // if (parseInt(addressData.shipping_state_id) > 0) { 5639 // $("#shipping_state_name").val('').removeAttr("required").hide(); 5640 // $(document).ajaxComplete(function(event, xhr, settings) { 5641 // if (settings.url === "/store_orders/getShippingStates") { 5642 // ///// $("select#shipping_state_id").show().attr("required", "required").val(parseInt(addressData.shipping_state_id)); 5643 // } 5644 // }); 5645 5646 // } else { 5647 // $("select#shipping_country_id").change(); 5648 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5649 // $("#shipping_state_name").show().removeAttr("required"); 5650 // } 5651 5652 // $("input#customer_address_id").val(addressData.id); 5653 // $("input#shipping_first_name").val(addressData.shipping_first_name); 5654 // $("input#shipping_last_name").val(addressData.shipping_last_name); 5655 // $("input#shipping_phone").val(addressData.shipping_phone); 5656 // $("textarea#shipping_address").val(addressData.shipping_address); 5657 // $("input#shipping_zip").val(addressData.shipping_postal_code); 5658 // $("input#shipping_city_name").val(addressData.shipping_city); 5659 // $("input#shipping_company_name").val(addressData.shipping_company_name); 5660 // $("input#shipping_gstin").val(addressData.shipping_gstin); 5661 // $("select#shipping_state_id").val(addressData.shipping_state_id); 5662 // $("select#shipping_country_id").val(addressData.shipping_country_id); 5663 // $("input#shipping_state_name").val(addressData.shipping_state); 5664 // $("input#payment_address").val(addressData.payment_address); 5665 // $("input#payment_first_name").val(addressData.payment_first_name); 5666 // $("input#payment_last_name").val(addressData.payment_last_name); 5667 // $("input#payment_zip").val(addressData.payment_postal_code); 5668 // $("input#payment_email").val(addressData.payment_email); 5669 // $("input#payment_city_name").val(addressData.payment_city); 5670 // if (parseInt(addressData.is_default) == 1) { 5671 // $("input#is_default").prop('checked', true); 5672 // $("#defaultCheckbox").hide(); 5673 // } else { 5674 // $("input#is_default").prop('checked', false); 5675 // $("#defaultCheckbox").show(); 5676 // } 5677 // $("select#payment_state_id").val(addressData.payment_state_id); 5678 // $("input#payment_state_name").val(addressData.payment_state); 5679 // $("select#payment_country_id").val(addressData.payment_country_id); 5680 // $("select#shipping_address_type_id").val(addressData.shipping_address_type_id
5680); 5681 // } 5682 // }); 5683 5684 // $('.delete_address').click(function() { 5685 // var customerAddressId = $(this).data('id'); 5686 // $("input#customer_address_id").val(customerAddressId); 5687 // }); 5688 5689 // $('#add_new_address').click(function() { 5690 // $("input#action").val(1); 5691 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5692 // $("input#customer_address_id").val(0); 5693 // $("input#shipping_first_name").val(''); 5694 // $("input#shipping_last_name").val(''); 5695 // $("input#shipping_address").val(''); 5696 // $("input#shipping_phone").val(''); 5697 // $("input#shipping_zip").val(''); 5698 // $("input#shipping_city_name").val(''); 5699 // $("input#shipping_company_name").val(''); 5700 // $("input#shipping_gstin").val(''); 5701 // $("select#shipping_state_id").val(''); 5702 // $("select#shipping_country_id").val(''); 5703 // $("input#shipping_state_name").val(''); 5704 // $("input#payment_address").val(''); 5705 // $("input#payment_first_name").val(''); 5706 // $("input#payment_last_name").val(''); 5707 // $("input#payment_zip").val(''); 5708 // $("input#payment_city_name").val(''); 5709 // $("select#payment_state_id").val(''); 5710 // $("input#payment_state_name").val(''); 5711 // $("input#is_default").prop('checked', false); 5712 // $("#defaultCheckbox").show(); 5713 // $("select#shipping_country_id").change(); 5714 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5715 // $("#shipping_state_name").show().removeAttr("required"); 5716 // }); 5717 5718 // $("form#EditAddressForm").validate({ 5719 // ignore: [], 5720 // debug: !0, 5721 // invalidHandler: function() { 5722 5723 // }, 5724 // errorPlacement: function(a, b) { 5725 // a.insertAfter(b.parent(".checkbox").length ? b.parent() : b) 5726 // }, 5727 // submitHandler: function(a) { 5728 // a.submit() 5729 // } 5730 // }); 5731 // }, 5732 // initManageAddresses: function() { 5733 // Theme.Utils.StoreOrder.changeShippingCountry(); 5734 // $('.edit_address').click(function() { 5735 // var customerAddressId = $(this).data('id'); 5736 // var addressData = customAddressesObject[customerAddressId]; 5737 // $("input#action").val(2); 5738 // if (customerAddressId != null && addressData != undefined) { 5739 // if (parseInt(addressData.shipping_state_id) > 0) { 5740 // Theme.Utils.StoreOrder.getShippingStates(addressData.shipping_country_id); 5741 // } 5742 // if (parseInt(addressData.payment_state_id) > 0) { 5743 // Theme.Utils.StoreOrder.getPaymentStates(addressData.payment_country_id); 5744 // $("#payment_state_name").val('').removeAttr("required").hide(); 5745 // } else { 5746 // $("select#payment_country_id").change(); 5747 // $("#payment_state_id").val('').removeAttr("required").hide(); 5748 // $("#payment_state_name").show().removeAttr("required"); 5749 // } 5750 5751 // if (parseInt(addressData.shipping_state_id) > 0) { 5752 // $("#shipping_state_name").val('').removeAttr("required").hide(); 5753 // $(document).ajaxComplete(function(event, xhr, settings) { 5754 // if (settings.url === "/store_orders/getShippingStates") { 5755 // ///// $("select#shipping_state_id").show().attr("required", "required").val(parseInt(addressData.shipping_state_id)); 5756 // } 5757 // }); 5758 5759 // } else { 5760 // $("select#shipping_country_id").change(); 5761 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5762 // $("#shipping_state_name").show().removeAttr("required"); 5763 5764 // $("#payment_state_id").val('').removeAttr("required").hide(); 5765 // $("#payment_state_name").show().removeAttr("required"); 5766 // } 5767 5768 // $("input#customer_address_id").val(addressData.id); 5769 // $("input#shipping_first_name").val(addressData.shipping_first_name); 5770 // $("input#shipping_last_name").val(addressData.shipping_last_name); 5771 // $("input#shipping_phone").val(addressData.shipping_phone); 5772 // $("textarea#shipping_address").val(addressData.shipping_address); 5773 // $("input#shipping_zip").val(addressData.shipping_postal_code); 5774 // $("input#shipping_city_name").val(addressData.shipping_city); 5775 // $("input#shipping_company_name").val(addressData.shipping_company_name); 5776 // $("input#shipping_gstin").val(addressData.shipping_gstin); 5777 // $("select#shipping_state_id").val(addressData.shipping_state_id); 5778 // $("select#shipping_country_id").val(addressData.shipping_country_id); 5779 // $("input#shipping_state_name").val(addressData.shipping_state); 5780 // $("textarea#payment_address").val(addressData.payment_address); 5781 // $("input#payment_first_name").val(addressData.payment_first_name); 5782 // $("input#payment_last_name").val(addressData.payment_last_name); 5783 // $("input#payment_zip").val(addressData.payment_postal_code); 5784 // $("input#payment_email").val(addressData.payment_email); 5785 // $("input#payment_city_name").val(addressData.payment_city); 5786 // $("input#payment_phone").val(addressData.payment_phone); 5787 // $("input#payment_company_name").val(addressData.payment_company_name); 5788 // $("input#payment_gstin").val(addressData.payment_gstin); 5789 // if (parseInt(addressData.is_default) == 1) { 5790 // $("input#is_default").prop('checked', true); 5791 // $("#defaultCheckbox").hide(); 5792 // } else { 5793 // $("input#is_default").prop('checked', false); 5794 // $("#defaultCheckbox").show(); 5795 // } 5796 // $("select#payment_state_id").val(addressData.payment_state_id); 5797 // $("input#payment_state_name").val(addressData.payment_state); 5798 // $("select#payment_country_id").val(addressData.payment_country_id); 5799 // $("select#shipping_address_type_id").val(addressData.shipping_address_type_id
5799); 5800 5801 // var isBillingSame = ( 5802 // (addressData.shipping_first_name || '') == (addressData.payment_first_name || '') && 5803 // (addressData.shipping_last_name || '') == (addressData.payment_last_name || '') && 5804 // (addressData.shipping_address || '') == (addressData.payment_address || '') && 5805 // (addressData.shipping_city || '') == (addressData.payment_city || '') && 5806 // (addressData.shipping_state || '') == (addressData.payment_state || '') && 5807 // (addressData.shipping_postal_code || '') == (addressData.payment_postal_code || '') && 5808 // (addressData.shipping_phone || '') == (addressData.payment_phone || '') 5809 // ); 5810 // if (isBillingSame) { 5811 // $("input#billing_same_as_shipping").prop('checked', true); 5812 // $("#billingAddressSection").hide(); 5813 // } else { 5814 // $("input#billing_same_as_shipping").prop('checked', false); 5815 // $("#billingAddressSection").show(); 5816 // } 5817 // } 5818 // }); 5819 5820 // $(document).on('change', '#payment_country_id', function() { 5821 // Theme.Utils.StoreOrder.getPaymentStates($(this).val()); 5822 // }); 5823 5824 // $('.delete_address').click(function() { 5825 // var customerAddressId = $(this).data('id'); 5826 // $("input#customer_address_id").val(customerAddressId); 5827 // }); 5828 5829 // $('#add_new_address').click(function() { 5830 // $("input#action").val(1); 5831 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5832 // $("input#customer_address_id").val(0); 5833 // $("input#shipping_first_name").val(''); 5834 // $("input#shipping_last_name").val(''); 5835 // $("input#shipping_address").val(''); 5836 // $("input#shipping_phone").val(''); 5837 // $("input#shipping_zip").val(''); 5838 // $("input#shipping_city_name").val(''); 5839 // $("input#shipping_company_name").val(''); 5840 // $("input#shipping_gstin").val(''); 5841 // $("select#shipping_state_id").val(''); 5842 // $("select#shipping_country_id").val(''); 5843 // $("input#shipping_state_name").val(''); 5844 // $("textarea#payment_address").val(''); 5845 // $("input#payment_first_name").val(''); 5846 // $("input#payment_last_name").val(''); 5847 // $("input#payment_zip").val(''); 5848 // $("input#payment_city_name").val(''); 5849 // $("select#payment_state_id").val(''); 5850 // $("input#payment_state_name").val(''); 5851 // $("input#payment_phone").val(''); 5852 // $("input#payment_company_name").val(''); 5853 // $("input#payment_gstin").val(''); 5854 // $("input#is_default").prop('checked', false); 5855 // $("#defaultCheckbox").show(); 5856 // $("input#billing_same_as_shipping").prop('checked', true); 5857 // $("#billingAddressSection").hide(); 5858 // $("select#shipping_country_id").change(); 5859 // $("#shipping_state_id").val('').removeAttr("required").hide(); 5860 // $("#shipping_state_name").show().removeAttr("required"); 5861 // }); 5862 5863 // $(document).on('change', '#billing_same_as_shipping', function() { 5864 // if ($(this).is(':checked')) { 5865 // $("#billingAddressSection").hide(); 5866 // } else { 5867 // $("#billingAddressSection").show(); 5868 // } 5869 // }); 5870 5871 // $("form#EditAddressForm").validate({ 5872 // ignore: [], 5873 // debug: !0, 5874 // invalidHandler: function() { 5875 5876 // }, 5877 // errorPlacement: function(a, b) { 5878 // a.insertAfter(b.parent(".checkbox").length ? b.parent() : b) 5879 // }, 5880 // submitHandler: function(a) { 5881 // a.submit() 5882 // } 5883 // }); 5884 // }, 5885 initManageAddresses: function() { 5886 Theme.Utils.StoreOrder.changeShippingCountry(); 5887 5888 $('.edit_address').click(function() { 5889 var customerAddressId = $(this).data('id'); 5890 var addressData = customAddressesObject[customerAddressId]; 5891 $("input#action").val(2); 5892 if (customerAddressId != null && addressData != undefined) { 5893 if (parseInt(addressData.shipping_state_id) > 0) { 5894 Theme.Utils.StoreOrder.getShippingStates(addressData.shipping_country_id); 5895 } 5896 if (parseInt(addressData.payment_state_id) > 0) { 5897 Theme.Utils.StoreOrder.getPaymentStates(addressData.payment_country_id); 5898 $("#payment_state_name").val('').removeAttr("required").hide(); 5899 } else { 5900 $("select#payment_country_id").change(); 5901 $("#payment_state_id").val('').removeAttr("required").hide(); 5902 $("#payment_state_name").show().removeAttr("required"); 5903 } 5904 5905 if (parseInt(addressData.shipping_state_id) > 0) { 5906 $("#shipping_state_name").val('').removeAttr("required").hide(); 5907 $(document).ajaxComplete(function(event, xhr, settings) { 5908 if (settings.url === "/store_orders/getShippingStates") { 5909 ///// $("select#shipping_state_id").show().attr("required", "required").val(parseInt(addressData.shipping_state_id)); 5910 } 5911 }); 5912 } else { 5913 $("select#shipping_country_id").change(); 5914 $("#shipping_state_id").val('').removeAttr("required").hide(); 5915 $("#shipping_state_name").show().removeAttr("required"); 5916 5917 $("#payment_state_id").val('').removeAttr("required").hide(); 5918 $("#payment_state_name").show().removeAttr("required"); 5919 } 5920 5921 $("input#customer_address_id").val(addressData.id); 5922 5923 $("input#shipping_first_name").val(addressData.shipping_first_name); 5924 $("input#shipping_last_name").val(addressData.shipping_last_name); 5925 5926 $("input#shipping_phone").val(addressData.shipping_phone); 5927 $("input#shipping_phone_with_isd_code").val(addressData.shipping_phone_isd_code + addressData.shipping_phone); 5928 $("input#shipping_phone_iso2").val(addressData.shipping_phone_iso2); 5929 5930 $("textarea#shipping_address").val(addressData.shipping_address); 5931 $("input#shipping_zip").val(addressData.shipping_postal_code); 5932 $("input#shipping_city_name").val(addressData.shipping_city); 5933 $("input#shipping_company_name").val(addressData.shipping_company_name); 5934 $("input#shipping_gstin").val(addressData.shipping_gstin); 5935 $("select#shipping_state_id").val(addressData.shipping_state_id); 5936 $("select#shipping_country_id").val(addressData.shipping_country_id); 5937 $("input#shipping_state_name").val(addressData.shipping_state); 5938 5939 $("input#payment_first_name").val(addressData.payment_first_name); 5940 $("input#payment_last_name").val(addressData.payment_last_name); 5941 5942 $("input#payment_phone").val(addressData.payment_phone); 5943 $("input#payment_phone_with_isd_code").val(addressData.payment_phone_isd_code + addressData.payment_phone); 5944 $("input#payment_phone_iso2").val(addressData.payment_phone_iso2); 5945 5946 $("textarea#payment_address").val(addressData.payment_address); 5947 $("input#payment_zip").val(addressData.payment_postal_code); 5948 $("input#payment_email").val(addressData.payment_email); 5949 $("input#payment_city_name").val(addressData.payment_city); 5950 5951 $("input#payment_company_name").val(addressData.payment_company_name); 5952 $("input#payment_gstin").val(addressData.payment_gstin); 5953 if (parseInt(addressData.is_default) == 1) { 5954 $("input#is_default").prop('checked', true); 5955 $("#defaultCheckbox").hide(); 5956 } else { 5957 $("input#is_default").prop('checked', false); 5958 $("#defaultCheckbox").show(); 5959 } 5960 $("select#payment_state_id").val(addressData.payment_state_id); 5961 $("input#payment_state_name").val(addressData.payment_state); 5962 $("select#payment_country_id").val(addressData.payment_country_id); 5963 $("select#shipping_address_type_id").val(addressData.shipping_address_type_id
5963); 5964 5965 var isBillingSame = ( 5966 (addressData.shipping_first_name || '') == (addressData.payment_first_name || '') && 5967 (addressData.shipping_last_name || '') == (addressData.payment_last_name || '') && 5968 (addressData.shipping_address || '') == (addressData.payment_address || '') && 5969 (addressData.shipping_city || '') == (addressData.payment_city || '') && 5970 (addressData.shipping_state || '') == (addressData.payment_state || '') && 5971 (addressData.shipping_postal_code || '') == (addressData.payment_postal_code || '') && 5972 (addressData.shipping_phone || '') == (addressData.payment_phone || '') 5973 ); 5974 if (isBillingSame) { 5975 $("input#billing_same_as_shipping").prop('checked', true); 5976 $("#billingAddressSection").hide(); 5977 } else { 5978 $("input#billing_same_as_shipping").prop('checked', false); 5979 $("#billingAddressSection").show(); 5980 } 5981 5982 if ($('#shipping_phone').length > 0) { 5983 window.shipping_phone_intlTel = Theme.Utils.PhoneCountryCode('shipping_phone', addressData.shipping_phone_iso2); 5984 } 5985 if ($('#payment_phone').length > 0) { 5986 window.payment_phone_intlTel = Theme.Utils.PhoneCountryCode('payment_phone', addressData.payment_phone_iso2); 5987 } 5988 } 5989 }); 5990 5991 $(document).on('change', '#payment_country_id', function() { 5992 Theme.Utils.StoreOrder.getPaymentStates($(this).val()); 5993 }); 5994 5995 $('.delete_address').click(function() { 5996 var customerAddressId = $(this).data('id'); 5997 $("input#customer_address_id").val(customerAddressId); 5998 }); 5999 6000 $('#add_new_address').click(function() { 6001 $("input#action").val(1); 6002 $("#shipping_state_id").val('').removeAttr("required").hide(); 6003 $("input#customer_address_id").val(0); 6004 $("input#shipping_first_name").val(''); 6005 $("input#shipping_last_name").val(''); 6006 $("input#shipping_address").val(''); 6007 $("input#shipping_phone").val(''); 6008 $("input#shipping_zip").val(''); 6009 $("input#shipping_city_name").val(''); 6010 $("input#shipping_company_name").val(''); 6011 $("input#shipping_gstin").val(''); 6012 $("select#shipping_state_id").val(''); 6013 $("select#shipping_country_id").val(''); 6014 $("input#shipping_state_name").val(''); 6015 $("textarea#payment_address").val(''); 6016 $("input#payment_first_name").val(''); 6017 $("input#payment_last_name").val(''); 6018 $("input#payment_zip").val(''); 6019 $("input#payment_city_name").val(''); 6020 $("select#payment_state_id").val(''); 6021 $("input#payment_state_name").val(''); 6022 $("input#payment_phone").val(''); 6023 $("input#payment_company_name").val(''); 6024 $("input#payment_gstin").val(''); 6025 $("input#is_default").prop('checked', false); 6026 $("#defaultCheckbox").show(); 6027 $("input#billing_same_as_shipping").prop('checked', true); 6028 $("#billingAddressSection").hide(); 6029 $("select#shipping_country_id").change(); 6030 $("#shipping_state_id").val('').removeAttr("required").hide(); 6031 $("#shipping_state_name").show().removeAttr("required"); 6032 }); 6033 6034 $(document).on('change', '#billing_same_as_shipping', function() { 6035 if ($(this).is(':checked')) { 6036 $("#billingAddressSection").hide(); 6037 } else { 6038 $("#billingAddressSection").show(); 6039 } 6040 }); 6041 6042 $("form#EditAddressForm").validate({ 6043 ignore: ".iti__search-input", 6044 //ignore: [], 6045 debug: !0, 6046 invalidHandler: function() { 6047 6048 }, 6049 errorPlacement: function(a, b) { 6050 a.insertAfter(b.parent(".checkbox").length ? b.parent() : b) 6051 }, 6052 submitHandler: function(form) { 6053 $("button#btnUpdateAddress").addClass("disabled").attr("disabled", "disabled").html("Please wait <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>"); 6054 6055 let shipping_phone_with_isd_code = window.shipping_phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 6056 if(shipping_phone_with_isd_code !== undefined) { 6057 $("input[name='data[myaccount][shipping_phone_with_isd_code]'").val(shipping_phone_with_isd_code); 6058 } 6059 6060 let shipping_phone_iso2_code = window.shipping_phone_intlTel.getSelectedCountryData().iso2; 6061 if(shipping_phone_iso2_code !== undefined) { 6062 $("input[name='data[myaccount][shipping_phone_iso2]'").val(shipping_phone_iso2_code.toUpperCase()); 6063 } 6064 6065 let payment_phone_with_isd_code = window.payment_phone_intlTel.getNumber(intlTelInputUtils.numberFormat.E164); 6066 if(payment_phone_with_isd_code !== undefined) { 6067 $("input[name='data[myaccount][payment_phone_with_isd_code]'").val(payment_phone_with_isd_code); 6068 } 6069 6070 let payment_phone_iso2_code = window.payment_phone_intlTel.getSelectedCountryData().iso2; 6071 if(payment_phone_iso2_code !== undefined) { 6072 $("input[name='data[myaccount][payment_phone_iso2]'").val(payment_phone_iso2_code.toUpperCase()); 6073 } 6074 6075 // if(window.googleRecaptchaSiteKey !== undefined && $('input#recaptchaResponse2').length) { 6076 // grecaptcha.ready(function () { 6077 // grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'customer_login'}).then(function (token) { 6078 // $(form).find('input#recaptchaResponse2').val(token); 6079 // }); 6080 // }); 6081 // } 6082 6083 setTimeout(function () { 6084 form.submit(); 6085 }, 1000); 6086 } 6087 }); 6088 }, 6089 initCustomerLedger: function() { 6090 6091 }, 6092 initGokwikOTPLogin:function() { 6093 6094 $(document).on('click', '.gokwikloginwithpass', function(event) { 6095 event.preventDefault(); 6096 $("div#loginwithgokwik").fadeOut('slow').addClass("d-none"); 6097 $("div#gokwikOTPCountainer").fadeOut('slow').addClass("d-none"); 6098 $("div#loginwithpass").fadeIn('slow').removeClass("d-none"); 6099 }); 6100 6101 $(document).on('click', '.gokwikloginwithotp', function(event) { 6102 event.preventDefault(); 6103 $("div#loginwithpass").fadeOut('slow').addClass("d-none"); 6104 $("div#gokwikOTPCountainer").fadeOut('slow').addClass("d-none"); 6105 $("div#loginwithgokwik").fadeIn('slow').removeClass("d-none"); 6106 }); 6107 6108 $(document).ready(function () { 6109 $('#gokwik_phone').on('input', function () { 6110 var phone = $(this).val().trim(); 6111 6112 if (phone.length == 10) { 6113 $('#btngokwikloginsubmit').prop('disabled', false); 6114 } 6115 }); 6116 }); 6117 6118 //Change Mobile No 6119 $(document).on('click', '.loginwithgokwik', function(event) { 6120 event.preventDefault(); 6121 $("div#gokwikOTPCountainer").fadeOut('slow').addClass("d-none"); 6122 $("div#loginwithgokwik").fadeIn('slow').removeClass("d-none"); 6123 $('.gokwik-verify-otp-code').prop('disabled', false); 6124 }); 6125 6126 //Resend OTP 6127 $('.gokwik-otp-resend-code').on('click', function(event) { 6128 var clickedForm = $(this).closest('form'); 6129 var mobileNo = clickedForm.find('#gokwik_mobile').val(); 6130 Theme.Utils.Customer.sendGokwikLoginOtp(mobileNo); 6131 $('.gokwik-verify-otp-code').prop('disabled', false); 6132 6133 }); 6134 6135 $('#btngokwikloginsubmit').on('click', function(event) { 6136 event.preventDefault(); // Prevent the default form submission 6137 var clickedForm = $(this).closest('form'); 6138 6139 var mobileNo = clickedForm.find('#gokwik_phone').val(); 6140 6141 if (mobileNo) { 6142 if (mobileNo.length >= 10 && Theme.Utils.Element.validateNumeric(mobileNo) === true) { 6143 $('#btngokwikloginsubmit').prop('disabled', true); 6144 Theme.Utils.Customer.sendGokwikLoginOtp(mobileNo); 6145 } else { 6146 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][gokwik_phone]', 'Please enter valid mobile no.') 6147 return; 6148 } 6149 } else { 6150 if (mobileNo.length < 10 || Theme.Utils.Element.validateNumeric(mobileNo) === false) { 6151 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][gokwik_phone]', 'Please enter valid mobile no.') 6152 return; 6153 } 6154 6155 } 6156 }); 6157 6158 $('.gokwik-verify-otp-code').on('click', function(event) { 6159 event.preventDefault(); // Prevent the default form submission 6160 var clickedForm = $(this).closest('form'); 6161 6162 var mobileNo = clickedForm.find('#gokwik_mobile').val(); 6163 var otp_code = clickedForm.find('#gokwik_otp_code').val(); 6164 if (otp_code == '' ) { 6165 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', 'Please enter valid OTP'); 6166 return 6167 } 6168 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', ''); 6169 $('.gokwik-verify-otp-code').prop('disabled', true); 6170 window.__KP_LOGIN_SDK_INSTANCE__.kpVerifyOTP({phone: String(mobileNo), otp: parseInt(otp_code)}) 6171 .then(function(response) { 6172 console.log(response); 6173 if (response.status == 200) { 6174 6175 $.ajax({
6176 type: "POST", 6177 url: "/customers/login_with_phone", 6178 accepts: "application/json", 6179 dataType: "json", 6180 data: "data[Customer][phone]=" + mobileNo +"&data[Customer][kptoken]="+response.body.data.kpToken+"&data[Customer][token]="+window.Store.PaymentConfig.gokwik.token+"", 6181 beforeSend: function() { 6182 $('.gokwik-verify-otp-code').prop('disabled', true); 6183 }, 6184 success: function(data) { 6185 console.log(data); 6186 if(data.login_status == 1) { 6187 window.location.reload(); 6188 } else { 6189 $('.gokwik-verify-otp-code').prop('disabled', false); 6190 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', 'Your account is not registered with us. Kindly register to proceed.'); 6191 } 6192 }, 6193 error: function(a, b, c) { 6194 //alert("Internal error: " + a.responseText) 6195 } 6196 }) 6197 } else { 6198 $('.gokwik-verify-otp-code').prop('disabled', false); 6199 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', response.message); 6200 } 6201 }) 6202 .catch(function(error){ 6203 console.log(error); 6204 $('.gokwik-verify-otp-code').prop('disabled', false); 6205 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', "Error in verify OTP"); 6206 }); 6207 }); 6208 }, 6209 sendGokwikLoginOtp:function(mobileNo) { 6210 window.__KP_LOGIN_SDK_INSTANCE__.kpSendOTP(mobileNo) 6211 .then(function(response) { 6212 console.log(response); 6213 if (response.status == 200) { 6214 //Theme.Utils.StoreOrder.ajaxValidation('data[Customer][gokwik_phone]', 'OTP sent successfully'); 6215 var login_user_id = mobileNo.substring(3); 6216 $('.gokwik-login-user-id').html("***"+login_user_id); 6217 $('#gokwik_mobile').val(mobileNo); 6218 $("div#loginwithgokwik").fadeOut('slow').addClass("d-none"); 6219 $("div#gokwikOTPCountainer").fadeIn('slow').removeClass("d-none"); 6220 Theme.Utils.StoreOrder.reverseCountdownTimer(); 6221 Theme.Utils.StoreOrder.ajaxValidation('gokwik_otp_code', ''); 6222 } else { 6223 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][gokwik_phone]', response.message); 6224 } 6225 }) 6226 .catch(function(error){ 6227 console.log(error); 6228 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][gokwik_phone]', "Error sending OTP"); 6229 }); 6230 } 6231 }; 6232 6233 Theme.Utils.StoreOrder = { 6234 initCheckout: function() { 6235 Theme.Utils.Element.init(); 6236 6237 this.changeDeliveryMode(); 6238 this.changeShippingCountry(); 6239 this.changeShippingState(); 6240 this.changeShippingCity(); 6241 6242 this.changePaymentCountry(); 6243 //this.changePaymentState(); 6244 this.setOtherDetails(); 6245 if (defaultValues.DefaultAddressId != 0 && defaultValues.DefaultAddressId != null) { 6246 Theme.Utils.StoreOrder.editMultipleAddress(defaultValues.DefaultAddressId, false); 6247 } else { 6248 this.setCheckoutDefaults(); 6249 } 6250 6251 //Either Register OR Guest Checkout 6252 $("#checkout_via1").on("click", function() { 6253 $("#divpassword").show(); 6254 $("#shipping_password").attr("required", "required"); 6255 }); 6256 6257 $("#checkout_via2").on("click", function() { 6258 $("#divpassword").hide(); 6259 $("#shipping_password").removeAttr("required"); 6260 }); 6261 6262 if ($('#checkout_via2').is(':checked')) { 6263 $("#divpassword").hide(); 6264 $("#shipping_password").removeAttr("required"); 6265 } 6266 6267 $("a.edit-link").on("click", function(e) { 6268 e.preventDefault(); 6269 $("div#divshipping").toggleClass("hidden"); 6270 $("div#divbilling").toggleClass("hidden"); 6271 $("div#divbillshipinfo").toggleClass("hidden"); 6272 6273 if ($('#StoreOrderOtherPayment').is(':checked')) { 6274 $("#StoreOrderOtherPayment").toggle(this.checked).trigger("click"); 6275 } 6276 6277 var scrollUpto = 0; 6278 if ($(this).data('scrollDiv') == "shipping") { 6279 var offsetShipping = $("div#ShippingSummary").offset(); 6280 scrollUpto = offsetShipping.top - 10; 6281 6282 } else if ($(this).data('scrollDiv') == "billing") { 6283 var offsetPayment = $("div#PaymentSummary").offset(); 6284 scrollUpto = offsetPayment.top - 10; 6285 } 6286 6287 $('html, body').animate({ 6288 scrollTop: scrollUpto 6289 }, 1000); 6290 }); 6291 6292 $("a#btnLogin").on("click", function(e) { 6293 var ele = $("div#toggleText"); 6294 var text = $("a#btnLogin");
6295 ele.toggle(); 6296 }); 6297 6298 $('form#StoreOrderCheckoutForm input[type=text]').on('keyup', function() { 6299 Theme.Utils.StoreOrder.resetElements(); 6300 }); 6301 6302 if ($("button#btnStoreOrder").is(":disabled")) { 6303 $("button#btnStoreOrder").removeProp("disabled"); 6304 } 6305 }, 6306 initAccordion: function() { 6307 $('.accordion-summary').click(function() { 6308 $('.summary-details').slideToggle("fast"); 6309 if ($(this).hasClass('summary-open')) { 6310 $(this).addClass('summary-close').removeClass('summary-open'); 6311 } else { 6312 $(this).addClass('summary-open').removeClass('summary-close'); 6313 } 6314 }); 6315 }, 6316 setCheckoutDefaults: function() { 6317 if (defaultValues.IsShippingServiceableCity == 1 && parseInt(defaultValues.DeliveryPincodeCheckId) != 5 && parseInt(defaultValues.ShippingCountryId) == 101) { 6318 //Theme.Utils.StoreOrder.getShippingSrilankaStates(defaultValues.ShippingCountryId); 6319 } 6320 6321 if (parseInt(defaultValues.ShippingStateId) > 0) { 6322 $("#shipping_state_name").val('').removeAttr("required").hide(); 6323 $("#shipping_state_id").show().attr("required", "required").val(parseInt(defaultValues.ShippingStateId)).attr("selected", "selected"); 6324 if (parseInt(defaultValues.DeliveryPincodeCheckId) != 5 && defaultValues.IsShippingServiceableCity == 1) { 6325 $("#shipping_city_name").val('').removeAttr("required").hide(); 6326 $("#shipping_city_id").show().attr("required", "required"); 6327 } 6328 } else { 6329 $("select#shipping_country_id").change(); 6330 //$("#shipping_state_id").val('').removeAttr("required").hide(); 6331 //$("#shipping_city_id").val('').removeAttr("required").hide(); 6332 //$("#shipping_state_name").show().removeAttr("required"); 6333 //$("#shipping_city_name").show().removeAttr("required"); 6334 } 6335 if (parseInt(defaultValues.DeliveryPincodeCheckId) == 5) { 6336 if (!$("#shipping_state_name").is(':visible')) { 6337 Theme.Utils.StoreOrder.getShippingServiceableStates(defaultValues.ShippingCountryId); 6338 } 6339 } 6340 6341 //Billing System 6342 if (parseInt(defaultValues.PaymentStateId) > 0) { 6343 $("#payment_state_id").show().attr("required", "required"); 6344 //$("#payment_city_id").show().attr("required", "required"); 6345 $("#payment_state_name").val('').removeAttr("required").hide(); 6346 //$("#payment_city_name").val('').removeAttr("required").hide(); 6347 } else { 6348 $("#payment_state_id").val(0).removeAttr("required").hide(); 6349 //$("#payment_city_id").val(0).removeAttr("required").hide(); 6350 $("#payment_state_name").show().removeAttr("required"); 6351 //$("#payment_city_name").show().removeAttr("required"); 6352 } 6353 6354 if ($('#StoreOrderOtherPayment').is(':checked')) { 6355 $("#PaymentSummary input[type=text], #PaymentSummary input[type=email]").removeAttr("required"); 6356 $("#PaymentSummary textarea").removeAttr("required"); 6357 $("#payment_country_id").removeAttr("required"); 6358 $("#payment_state_id").removeAttr("required"); 6359 //$("#payment_city_id").removeAttr("required"); 6360 $("#PaymentSummary").hide(); 6361 } 6362 6363 //Setting Shipping or Billing is active 6364 $("input:radio[class=delivery_mode]:first").attr('checked', true).click(); 6365 6366 //Check Phone Number and Pincode 6367 if (parseInt(defaultValues.ShippingCountryId) == 101) { 6368 $("#shipping_phone").attr("minlength", 10).attr("maxlength", 11); 6369 $("#shipping_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 6370 } else { 6371 $("#shipping_phone").removeAttr("minlength").attr("maxlength", 20); 6372 $("#shipping_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 6373 } 6374 6375 if (parseInt(defaultValues.PaymentCountryId) == 101) { 6376 $("#payment_phone").attr("minlength", 10).attr("maxlength", 11); 6377 $("#payment_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 6378 } else { 6379 $("#payment_phone").removeAttr("minlength").attr("maxlength", 20); 6380 $("#payment_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 6381 } 6382 }, 6383 setOtherDetails: function() { 6384 6385 $("#StoreOrderOtherPayment").on("click", function() { 6386 6387 if ($(this).is(':checked')) { 6388 var payment_country_id = $("#payment_country_id").val(); 6389 Theme.Utils.StoreOrder.getPaymentStates(payment_country_id); 6390 $("#PaymentSummary input[type=text]").removeAttr("required"); 6391 $("#PaymentSummary textarea").removeAttr("required"); 6392 $("#payment_country_id").removeAttr("required"); 6393 $("#payment_state_id").removeAttr("required"); 6394 //$("#payment_city_id").removeAttr("required"); 6395 $("#PaymentSummary").hide(); 6396 } else { 6397 6398 $("#PaymentSummary").show(); 6399 6400 var payment_country_id = $("#payment_country_id").val(); 6401 Theme.Utils.StoreOrder.getPaymentStates(payment_country_id); 6402 $("#PaymentSummary #payment_first_name").attr("required", "required"); 6403 $("#PaymentSummary #payment_last_name").attr("required", "required"); 6404 $("#PaymentSummary #payment_email").attr("required", "required"); 6405 $("#PaymentSummary #payment_phone").attr("required", "required"); 6406 $("#PaymentSummary #payment_address").attr("required", "required"); 6407 if (parseInt(defaultValues.PaymentStateId) > 0) { 6408 $("#payment_state_id").attr("required", "required"); 6409 //$("#payment_city_id").attr("required", "required"); 6410 } 6411 } 6412 }); 6413 }, 6414 getShippingStates: function(shipping_country_id) { 6415 if (parseInt(shipping_country_id) > 0) { 6416 $.ajax({
6417 type: "POST", 6418 async: false, 6419 cache: false, 6420 url: "/store_orders/getShippingStates", 6421 dataType: "html", 6422 data: { 6423 "data[StoreOrder][shipping_country_id]": shipping_country_id 6424 }, 6425 beforeSend: function(XMLHttpRequest) { 6426 $("#shipping_state_id").find("option").not(':first').remove(); 6427 $("#shipping_city_id").find("option").not(':first').remove(); 6428 6429 $("#shipping_state_name").hide(); 6430 $("#shipping_state_id").hide(); 6431 $("#shipping_city_name").show().attr("required", "required"); 6432 $("#shipping_city_id").removeAttr("required").hide(); 6433 }, 6434 success: function(data, textStatus) { 6435 if(data.length > 0 && data != 'Record Not Found') { 6436 $("#shipping_state_name").val('').removeAttr("required").hide().parent("div").addClass("field__input-wrapper--select"); 6437 $("#shipping_state_id").show().attr("required", "required").append(data); 6438 6439 } else { 6440 $("#shipping_state_id").val(0).removeAttr("required").hide(); 6441 $("#shipping_state_name").show().removeAttr("required").parent("div").removeClass("field__input-wrapper--select"); 6442 6443 6444 } 6445 }, 6446 error: function(jqXHR, textStatus, errorThrown) { 6447 if (jqXHR.status == 500) { 6448 alert('Internal error: ' + jqXHR.responseText); 6449 } 6450 } 6451 }); 6452 } 6453 }, 6454 getShippingSrilankaStates: function(shipping_country_id) { 6455 if (parseInt(shipping_country_id) > 0) { 6456 $.ajax({
6457 type: "POST", 6458 async: false, 6459 cache: false, 6460 url: "/store_orders/getShippingSrilankaStates", 6461 dataType: "html", 6462 data: { 6463 "data[StoreOrder][shipping_country_id]": shipping_country_id 6464 }, 6465 beforeSend: function(XMLHttpRequest) { 6466 $("#shipping_state_id").find("option").not(':first').remove(); 6467 $("#shipping_city_id").find("option").not(':first').remove(); 6468 $("#shipping_state_name").hide(); 6469 $("#shipping_state_id").hide(); 6470 $("#shipping_city_name").hide(); 6471 $("#shipping_city_id").removeAttr("required").hide(); 6472 }, 6473 success: function(data, textStatus) { 6474 if(data.length > 0 && data != 'Record Not Found') { 6475 $("#shipping_state_name").val('').removeAttr("required").hide().parent("div").addClass("field__input-wrapper--select"); 6476 $("#shipping_state_id").show().attr("required", "required").append(data); 6477 $("#shipping_city_name").val('').removeAttr("required").hide(); 6478 $("#shipping_city_id").show().attr("required", "required"); 6479 } else { 6480 $("#shipping_state_id").val(0).removeAttr("required").hide(); 6481 $("#shipping_state_name").show().removeAttr("required").parent("div").removeClass("field__input-wrapper--select"); 6482 $("#shipping_city_id").removeAttr("required").hide(); 6483 $("#shipping_city_name").show().removeAttr("required"); 6484 } 6485 }, 6486 error: function(jqXHR, textStatus, errorThrown) { 6487 if (jqXHR.status == 500) { 6488 alert('Internal error: ' + jqXHR.responseText); 6489 } 6490 } 6491 }); 6492 } 6493 }, 6494 getShippingCities: function(shipping_country_id, shipping_state_id) { 6495 if (parseInt(shipping_country_id) > 0 && parseInt(shipping_state_id) > 0) { 6496 $.ajax({
6497 type: "POST", 6498 async: true, 6499 cache: false, 6500 url: "/store_orders/getShippingCities", 6501 dataType: "html", 6502 data: { 6503 "data[StoreOrder][shipping_country_id]": shipping_country_id, 6504 "data[StoreOrder][shipping_state_id]": shipping_state_id 6505 }, 6506 beforeSend: function(XMLHttpRequest) { 6507 $("#shipping_city_id").find("option").not(':first').remove(); 6508 }, 6509 success: function(data, textStatus) { 6510 if(data.length > 0 && data != 'Record Not Found') { 6511 $("#shipping_city_id").append(data); 6512 } 6513 }, 6514 error: function(jqXHR, textStatus, errorThrown) { 6515 if (jqXHR.status == 500) { 6516 alert('Internal error: ' + jqXHR.responseText); 6517 } 6518 } 6519 }); 6520 } 6521 }, 6522 getShippingSrilankaCities: function(shipping_country_id, shipping_state_id) { 6523 if (parseInt(shipping_country_id) > 0 && parseInt(shipping_state_id) > 0) { 6524 6525 $.ajax({
6526 type: "POST", 6527 async: false, 6528 cache: false, 6529 url: "/store_orders/getShippingSrilankaCities", 6530 dataType: "html", 6531 data: { 6532 "data[StoreOrder][shipping_country_id]": shipping_country_id, 6533 "data[StoreOrder][shipping_state_id]": shipping_state_id 6534 }, 6535 beforeSend: function(XMLHttpRequest) { 6536 $("#shipping_city_id").find("option").not(':first').remove(); 6537 }, 6538 success: function(data, textStatus) { 6539 if(data.length > 0 && data != 'Record Not Found') { 6540 $("#shipping_city_id").append(data); 6541 } 6542 }, 6543 error: function(jqXHR, textStatus, errorThrown) { 6544 if (jqXHR.status == 500) { 6545 alert('Internal error: ' + jqXHR.responseText); 6546 } 6547 } 6548 }); 6549 } 6550 }, 6551 getShippingServiceableStates: function(shipping_country_id) { 6552 if (parseInt(shipping_country_id) > 0) { 6553 $.ajax({
6554 type: "POST", 6555 async: true, 6556 cache: false, 6557 url: "/store_orders/getShippingServiceableStates", 6558 dataType: "html", 6559 data: { 6560 "data[StoreOrder][shipping_country_id]": shipping_country_id 6561 }, 6562 beforeSend: function(XMLHttpRequest) { 6563 $("select#shipping_state_name").find("option").not(':first').remove(); 6564 $("select#shipping_city_name").find("option").not(':first').remove(); 6565 $("#shipping_serviceable_area_id").find("option").not(':first').remove(); 6566 }, 6567 complete: function(data) { 6568 if (parseInt(defaultValues.ShippingStateName.length) > 0) { 6569 $('select#shipping_state_name option[value=' + defaultValues.ShippingStateName + ']').attr("selected", true); 6570 $("select#shipping_state_name").trigger('change'); 6571 } 6572 }, 6573 success: function(data, textStatus) { 6574 if(data.length > 0 && data != 'Record Not Found') { 6575 $("#shipping_state_name").show().attr("required", "required").append(data); 6576 } else { 6577 $("#shipping_state_name").val(0).removeAttr("required"); 6578 } 6579 }, 6580 error: function(jqXHR, textStatus, errorThrown) { 6581 if (jqXHR.status == 500) { 6582 alert('Internal error: ' + jqXHR.responseText); 6583 } 6584 } 6585 }); 6586 } 6587 }, 6588 getShippingServiceableCities: function(shipping_country_id, shipping_state_name) { 6589 if (parseInt(shipping_country_id) > 0 && parseInt(shipping_state_name.length) > 0) { 6590 $.ajax({
6591 type: "POST", 6592 async: true, 6593 cache: false, 6594 url: "/store_orders/getShippingServiceableCities", 6595 dataType: "html", 6596 data: { 6597 "data[StoreOrder][shipping_country_id]": shipping_country_id, 6598 "data[StoreOrder][shipping_state_name]": shipping_state_name 6599 }, 6600 beforeSend: function(XMLHttpRequest) { 6601 $("#shipping_city_name").find("option").not(':first').remove(); 6602 $("#shipping_serviceable_area_id").find("option").not(':first').remove(); 6603 }, 6604 complete: function(data) { 6605 if (parseInt(defaultValues.ShippingCityName.length) > 0) { 6606 $('select#shipping_city_name option[value=' + defaultValues.ShippingCityName + ']').attr("selected", true); 6607 $("select#shipping_city_name").trigger('change'); 6608 } 6609 }, 6610 success: function(data, textStatus) { 6611 if(data.length > 0 && data != 'Record Not Found') { 6612 $("#shipping_city_name").append(data); 6613 } 6614 }, 6615 error: function(jqXHR, textStatus, errorThrown) { 6616 if (jqXHR.status == 500) { 6617 alert('Internal error: ' + jqXHR.responseText); 6618 } 6619 } 6620 }); 6621 } 6622 }, 6623 getShippingServiceableAreas: function(shipping_country_id, shipping_state_name, shipping_city_name) { 6624 if (parseInt(shipping_country_id) > 0 && parseInt(shipping_state_name.length) > 0 && parseInt(shipping_city_name.length) > 0) { 6625 $.ajax({
6626 type: "POST", 6627 async: true, 6628 cache: false, 6629 url: "/store_orders/getShippingServiceableAreas", 6630 dataType: "html", 6631 data: { 6632 "data[StoreOrder][shipping_country_id]": shipping_country_id, 6633 "data[StoreOrder][shipping_state_name]": shipping_state_name, 6634 "data[StoreOrder][shipping_city_name]": shipping_city_name 6635 }, 6636 beforeSend: function(XMLHttpRequest) { 6637 $("select#shipping_serviceable_area_id").find("option").not(':first').remove(); 6638 }, 6639 complete: function(data) { 6640 if (parseInt(defaultValues.ShippingServiceableAreaId) > 0) { 6641 $('select#shipping_serviceable_area_id option[value=' + defaultValues.ShippingServiceableAreaId + ']').attr("selected", true); 6642 } 6643 }, 6644 success: function(data, textStatus) { 6645 if(data.length > 0 && data != 'Record Not Found') { 6646 $("select#shipping_serviceable_area_id").append(data); 6647 } 6648 }, 6649 error: function(jqXHR, textStatus, errorThrown) { 6650 if (jqXHR.status == 500) { 6651 alert('Internal error: ' + jqXHR.responseText); 6652 } 6653 } 6654 }); 6655 } 6656 }, 6657 6658 getPaymentStates: function(payment_country_id) { 6659 if (parseInt(payment_country_id) > 0) { 6660 $.ajax({
6661 type: "POST", 6662 async: false, 6663 cache: false, 6664 url: "/store_orders/getPaymentStates", 6665 dataType: "html", 6666 data: { 6667 "data[StoreOrder][payment_country_id]": payment_country_id 6668 }, 6669 beforeSend: function(XMLHttpRequest) { 6670 $("#payment_state_id").find("option").not(':first').remove(); 6671 //$("#payment_city_id").find("option").not(':first').remove(); 6672 6673 $("#payment_state_name").hide(); 6674 //$("#payment_city_name").hide(); 6675 $("#payment_state_id").hide(); 6676 //$("#payment_city_id").hide(); 6677 }, 6678 success: function(data, textStatus) { 6679 if (data.length > 0 && data != 'Record Not Found') { 6680 $("#payment_state_name").val('').removeAttr("required").hide().parent("div").addClass("field__input-wrapper--select");; 6681 //$("#payment_city_name").val('').removeAttr("required").hide(); 6682 $("#payment_state_id").show().attr("required", "required").append(data); 6683 //$("#payment_city_id").show().attr("required", "required"); 6684 } else { 6685 $("#payment_state_id").val(0).removeAttr("required").hide(); 6686 //$("#payment_city_id").val(0).removeAttr("required").hide(); 6687 $("#payment_state_name").show().removeAttr("required").parent("div").removeClass("field__input-wrapper--select"); 6688 //$("#payment_city_name").show().removeAttr("required"); 6689 } 6690 }, 6691 error: function(jqXHR, textStatus, errorThrown) { 6692 console.log(jqXHR); 6693 if (jqXHR.status == 500) { 6694 alert('Internal error: ' + jqXHR.responseText); 6695 } 6696 } 6697 }); 6698 } 6699 }, 6700 getPaymentCities: function(payment_country_id, payment_state_id) { 6701 if (parseInt(payment_country_id) > 0 && parseInt(payment_state_id) > 0) { 6702 $.ajax({
6703 type: "POST", 6704 async: true, 6705 cache: false, 6706 url: "/store_orders/getPaymentCities", 6707 dataType: "html", 6708 data: { 6709 "data[StoreOrder][payment_country_id]": payment_country_id, 6710 "data[StoreOrder][payment_state_id]": payment_state_id 6711 }, 6712 beforeSend: function(XMLHttpRequest) { 6713 $("#payment_city_id").find("option").not(':first').remove(); 6714 }, 6715 success: function(data, textStatus) { 6716 if (data.length > 0 && data != 'Record Not Found') { 6717 $("#payment_city_id").append(data); 6718 } 6719 }, 6720 error: function(jqXHR, textStatus, errorThrown) { 6721 if (jqXHR.status == 500) { 6722 alert('Internal error: ' + jqXHR.responseText); 6723 } 6724 } 6725 }); 6726 } 6727 }, 6728 changeShippingCountry: function() { 6729 $("select#shipping_country_id").on("change", function(event) { 6730 $("option:selected", $(this)).each(function() { 6731 var shipping_country_id = $(this).val(); 6732 var payment_country_id = $(this).val(); 6733 6734 if (parseInt(defaultValues.DeliveryPincodeCheckId) == 5) { 6735 Theme.Utils.StoreOrder.getShippingServiceableStates(shipping_country_id); 6736 } else { 6737 if (defaultValues.IsShippingServiceableCity == 1 && parseInt(shipping_country_id) == 101) { 6738 Theme.Utils.StoreOrder.getShippingSrilankaStates(shipping_country_id); 6739 } else { 6740 Theme.Utils.StoreOrder.getShippingStates(shipping_country_id); 6741 } 6742 } 6743 6744 if ($("#StoreOrderOtherPayment").is(":checked")) { 6745 if (parseInt(defaultValues.DeliveryPincodeCheckId) != 5) { 6746 Theme.Utils.StoreOrder.getPaymentStates(payment_country_id); 6747 } 6748 if (parseInt(shipping_country_id) == 101) { 6749 $("#payment_state_id").show().attr("required", "required"); 6750 $("#payment_state_name").val('').removeAttr("required").hide(); 6751 6752 } else { 6753 $("#payment_state_id").val(0).removeAttr("required").hide(); 6754 $("#payment_state_name").show().removeAttr("required"); 6755 } 6756 } 6757 6758 //Check Phone Number and Pincode 6759 if (parseInt(shipping_country_id) == 101) { 6760 $("#shipping_phone").attr("minlength", 10).attr("maxlength", 11); 6761 $("#shipping_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 6762 } else { 6763 $("#shipping_phone").removeAttr("minlength").attr("maxlength", 20); 6764 $("#shipping_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 6765 } 6766 6767 Theme.Utils.StoreOrder.resetElements(); 6768 return false; 6769 }); 6770 }); 6771 }, 6772 changeShippingState: function() { 6773 if (parseInt(defaultValues.DeliveryPincodeCheckId) == 5) { 6774 /* $("#shipping_state_id").on("change", function (event) { 6775 $("option:selected", $(this)).each(function(){ 6776 var shipping_country_id = $("#shipping_country_id").val(); 6777 var shipping_state_name = $(this).val(); 6778 Theme.Utils.StoreOrder.getShippingServiceableCities(shipping_country_id, shipping_state_name); 6779 Theme.Utils.StoreOrder.resetElements(); 6780 return false; 6781 }); 6782 }); */ 6783 $("#shipping_state_name").on("change", function(event) { 6784 $("option:selected", $(this)).each(function() { 6785 var shipping_country_id = $("#shipping_country_id").val(); 6786 var shipping_state_name = $(this).val(); 6787 Theme.Utils.StoreOrder.getShippingServiceableCities(s
6787hipping_country_id, shipping_state_name); 6788 return false; 6789 }); 6790 }); 6791 } else { 6792 6793 6794 $("select#shipping_state_id").on("change", function(event) { 6795 $("option:selected", $(this)).each(function() { 6796 var shipping_country_id = $("#shipping_country_id").val(); 6797 var shipping_state_id = $(this).val(); 6798 if (defaultValues.IsShippingServiceableCity == 1 && parseInt(shipping_country_id) == 101) { 6799 Theme.Utils.StoreOrder.getShippingSrilankaCities(shipping_country_id, shipping_state_id); 6800 } 6801 Theme.Utils.StoreOrder.resetElements(); 6802 return false; 6803 }); 6804 }); 6805 6806 /* $("#shipping_state_id").on("change", function (event) { 6807 $("option:selected", $(this)).each(function(){ 6808 Theme.Utils.StoreOrder.resetElements(); 6809 return false; 6810 }); 6811 }); */ 6812 } 6813 }, 6814 changeShippingCity: function() { 6815 if (parseInt(defaultValues.DeliveryPincodeCheckId) == 5) { 6816 $("select#shipping_city_name").on("change", function(event) { 6817 $("option:selected", $(this)).each(function() { 6818 var shipping_country_id = $("select#shipping_country_id").val(); 6819 var shipping_state_name = $("#shipping_state_name").val(); 6820 var shipping_city_name = $(this).val(); 6821 Theme.Utils.StoreOrder.getShippingServiceableAreas(shipping_country_id, shipping_state_name, shipping_city_name); 6822 return false; 6823 }); 6824 }); 6825 } 6826}, 6827changePaymentCountry: function() { 6828 $("#payment_country_id").on("change", function() { 6829 $("option:selected", $(this)).each(function() { 6830 var payment_country_id = $(this).val(); 6831 Theme.Utils.StoreOrder.getPaymentStates(payment_country_id); 6832 6833 //Check Phone Number and Pincode 6834 if (parseInt(payment_country_id) == 101) { 6835 $("#payment_phone").attr("minlength", 10).attr("maxlength", 11); 6836 $("#payment_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 6837 } else { 6838 $("#payment_phone").removeAttr("minlength").attr("maxlength", 20); 6839 $("#payment_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 6840 } 6841 6842 return false; 6843 }); 6844 }); 6845}, 6846changePaymentState: function() { 6847 alert(""); 6848 $("#payment_state_id").on("change", function(event) { 6849 $("option:selected", $(this)).each(function() { 6850 var payment_country_id = $("#payment_country_id").val(); 6851 var payment_state_id = $(this).val(); 6852 Theme.Utils.StoreOrder.getPaymentCities(payment_country_id, payment_state_id); 6853 return false; 6854 }); 6855 }); 6856}, 6857changeDeliveryMode: function() { 6858 /* Enable According To Delivery Mode */ 6859 $('.delivery_mode').on("click", function(event) { 6860 var store_address; 6861 var chkValue = $(this).filter(':checked').parent("label").text(); 6862 if ($.trim(chkValue) == "Store Pickup") { 6863 $("#div_pickup_details").fadeIn(100); 6864 //store_address = $.trim($("#div_pickup_details").html()); 6865 //$("#shipping_address").val(store_address); 6866 6867 /* Show or hide shipping and billing */ 6868 $("div#divshipping").find("#shipping_first_name, #shipping_last_name, #shipping_email, #shipping_phone, #shipping_address, #shipping_country_id, #shipping_state_id, #shipping_city_id").removeAttr("required"); 6869 $("div#divshipping").hide(); 6870 6871 $('#StoreOrderOtherPayment').prop('checked', false); 6872 $("div#divother").hide(); 6873 $("div#PaymentSummary").show(); 6874 $("div#PaymentSummary").find("#payment_first_name, #payment_last_name, #payment_email, #payment_phone, #payment_address, #payment_country_id, #payment_state_id, #payment_city_id").attr("required", true); 6875 } else { 6876 $("#div_pickup_details").fadeOut(100); 6877 /* Show or hide shipping and billing */ 6878 $("div#PaymentSummary").find("#payment_first_name, #payment_last_name, #payment_email, #payment_phone, #payment_address, #payment_country_id, #payment_state_id, #payment_city_id").removeAttr("required"); 6879 $("div#PaymentSummary").hide(); 6880 6881 $("div#divother").show(); 6882 $('#StoreOrderOtherPayment').prop('checked', true); 6883 $("div#divshipping").show(); 6884 $("div#divshipping").find("#shipping_first_name, #shipping_last_name, #shipping_email, #shipping_phone, #shipping_address, #
6884shipping_country_id, #shipping_state_id, #shipping_city_id").attr("required", true); 6885 } 6886 }); 6887}, 6888resetElements: function() { 6889 if ($('input#StoreOrderOtherPayment').is(':checked')) { 6890 $("input#payment_first_name").val($("input#shipping_first_name").val().trim()); 6891 $("input#payment_last_name").val($("input#shipping_last_name").val().trim()); 6892 $("input#payment_phone").val($("input#shipping_phone").val().trim()); 6893 $("input#payment_address").val($("input#shipping_address").val().trim()); 6894 6895 //Do not apply input tag before state_name, city_name !important 6896 if ($("#shipping_state_name").val() !== null) { 6897 $("input#payment_state_name").val($("#shipping_state_name").val().trim()); 6898 } 6899 if ($("#shipping_city_name").length > 0) { 6900 $("input#payment_city_name").val($("#shipping_city_name").val().trim()); 6901 } 6902 6903 $("input#payment_zip").val($("input#shipping_zip").val().trim()); 6904 $("select#payment_country_id").val($("select#shipping_country_id").val().trim()); 6905 if ($("select#shipping_state_id").val() != undefined) { 6906 $("select#payment_state_id").val($("select#shipping_state_id").val().trim()); 6907 } 6908 if (parseInt($("select#payment_country_id").val()) == 101) { 6909 $("input#payment_phone").attr("minlength", 10).attr("maxlength", 11); 6910 $("input#payment_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 6911 } else { 6912 $("input#payment_phone").removeAttr("minlength").attr("maxlength", 20); 6913 $("input#payment_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 6914 } 6915 } 6916 }, 6917 validateCheckout: function() { 6918 $("form#StoreOrderCheckoutForm").validate({ 6919 ignore: [], 6920 debug: true, 6921 invalidHandler: function(event, validator) { 6922 $("div#divshipping").removeClass("hidden"); 6923 $("div#divbilling").removeClass("hidden"); 6924 $("div#divbillshipinfo").addClass("hidden"); 6925 }, 6926 errorPlacement: function(error, element) { 6927 if ($('#store_delivery_mode_id_3').length) { 6928 $(".tabbable-line").tabs(); 6929 $(".tabbable-line").tabs("option", "active", 2); 6930 $($('.tabbable-line a[href="#tab_default_2"]')).tab('show'); 6931 } 6932 //If any validation error than open edit area. 6933 var inputSelected = $("input[name='data[StoreOrder][customer_address_selected]']:checked").val(); 6934 if (inputSelected != null) { 6935 if (!$('#divshipping').is(':visible')) { 6936 Theme.Utils.StoreOrder.editMultipleAddress(inputSelected, true); 6937 //$('select#shipping_country_id').change(); 6938 //$('select#payment_country_id').change(); 6939 $('#divshipping').slideDown(); 6940 $('#divbilling').slideDown(); 6941 } 6942 $('html, body').animate({ 6943 scrollTop: $("#divshipping").offset().top 6944 }, 1000); 6945 } 6946 if (element.parent('.checkbox').length) { 6947 error.insertAfter(element.parent()); 6948 } else { 6949 error.insertAfter(element); 6950 } 6951 }, 6952 submitHandler: function(form) { 6953 $('#btnStoreOrder').addClass("disabled").attr("disabled", "disabled"); 6954 form.submit(); 6955 /* 6956 if(Theme.Utils.StoreOrder.checkDeliveryAvailable()){ 6957 form.submit(); 6958 } else { 6959 //console.log(Theme.Utils.StoreOrder.checkDeliveryAvailable()); 6960 } 6961 */ 6962 } 6963 }); 6964 }, 6965 validateCustomerCheckout: function() { 6966 $("form#CustomerCheckoutForm").validate(); 6967 }, 6968 validateCoupon: function() { 6969 $("form#StoreCouponCartForm").validate(); 6970 }, 6971 checkDeliveryAvailable: function() { 6972 var pincode = $("#StoreOrderCheckoutForm").find("input#shipping_zip").val(); 6973 6974 if (pincode === '' || pincode.length < 4 || pincode.length > 10) { 6975 $('#shipping_zip').val('').addClass('required').attr('placeholder', 'Enter valid pincode'); 6976 alert("Enter valid pincode"); 6977 return false; 6978 } 6979 6980 var delivery_status = false; 6981 var ajaxLoading = false; 6982 6983 if (!ajaxLoading) { 6984 ajaxLoading = true; 6985 6986 var ShippingPincode = $("#StoreOrderCheckoutForm").find("input#shipping_zip").val(); 6987 var FormData = "data[shipping_pincode]=" + ShippingPincode + ""; 6988 6989 $("button#btnStoreOrder").addClass("disabled").attr("disabled", "disabled").html("Please wait <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>"); 6990 $.ajax({
6991 type: "POST", 6992 async: false, 6993 cache: false, 6994 url: "/store_orders/check_delivery_cod_available", 6995 accepts: 'application/json', 6996 dataType: "json", 6997 data: FormData, 6998 beforeSend: function(XMLHttpRequest) { 6999 //$("button#btnStoreOrder").addClass("disabled").attr("disabled", "disabled"); 7000 }, 7001 complete: function() { 7002 ajaxLoading = false; 7003 $("button#btnStoreOrder").removeClass("disabled").removeAttr("disabled").html("Continue"); 7004 }, 7005 success: function(data, textStatus) { 7006 //console.log(data); 7007 if (data.delivery_status !== undefined && data.delivery_status == 1) { 7008 delivery_status = true; 7009 } else { 7010 alert("Delivery not available at this pincode"); 7011 } 7012 }, 7013 error: function(jqXHR, textStatus, errorThrown) { 7014 //console.log(jqXHR.responseText); 7015 if (jqXHR.status == 500) { 7016 alert('Internal error: ' + jqXHR.responseText); 7017 } 7018 } 7019 }); 7020 7021 } 7022 return delivery_status; //stop the actual form post !important! 7023 }, 7024 changePaymentOption: function() { 7025 var payment_mode_val = $('.payment_mode:checked').data('paymentModeId'); 7026 if (payment_mode_val != null && payment_mode_val == 25) { 7027 $('.ccinfo-hold').removeClass('hidden').slideDown(); 7028 7029 $.validator.addMethod('card-field', function(value) { 7030 return value != ''; 7031 }, 'Please fill required feilds.'); 7032 } 7033 7034 $('.payment_mode').change(function() { 7035 if ($(this).is(':checked') && $(this).data('paymentModeId') == 25) { 7036 $('.ccinfo-hold').removeClass('hidden').slideDown(); 7037 7038 $.validator.addMethod('card-field', function(value) { 7039 return value != ''; 7040 }, 'Please fill required feilds.'); 7041 } else { 7042 $('.ccinfo-hold').slideUp(); 7043 } 7044 }); 7045 }, 7046 validatePaymentOption: function() { 7047 $.validator.addMethod('payment_mode', function(value) { 7048 return $('.payment_mode:checked').size() > 0; 7049 }, 'Please select atleast one payment option'); 7050 7051 $("form#StoreOrderCartForm").validate({ 7052 errorPlacement: function(error, element) { 7053 if (element.hasClass("payment_mode")) { 7054 error.prependTo(element.parent("div").parent("div")); 7055 } else { 7056 error.insertAfter(element); 7057 } 7058 } 7059 }); 7060 7061 $(document).on("click", "input.shipping_option", function() { 7062 Theme.Utils.StoreOrder.calculateShipping(); 7063 }); 7064 7065 $(document).on("click", "input.payment_mode", function() { 7066 Theme.Utils.StoreOrder.calculateShipping(); 7067 }); 7068 7069 Theme.Utils.StoreOrder.calculateShipping(); 7070 }, 7071 validateReview: function() { 7072 $("form#StoreOrderReviewForm").validate(); 7073 }, 7074 calculateShipping: function() { 7075 var total_order_amount = parseFloat($("input#total_order_amount").val()); 7076 var total_bundle_discount = parseFloat($("input#total_bundle_discount").val()); 7077 var total_shipping = parseFloat($("input#total_shipping").val()); 7078 var total_tax = parseFloat($("input#total_tax").val()); 7079 var total_discount = parseFloat($("input#total_discount").val()); 7080 var total_reward_discount = ($("input#total_reward_discount").length > 0) ? parseFloat($("input#total_reward_discount").val()) : 0; 7081 var total_gift_discount = parseFloat($("input#total_gift_discount").val()); 7082 7083 var total_payable_amount = parseFloat(total_order_amount) - parseFloat(total_bundle_discount) + parseFloat(total_shipping) + parseFloat(total_tax) - parseFloat(total_discount) - parseFloat(total_reward_discount) - parseFloat(total_gift_discount); 7084 var total_additional_charges = 0 7085 var shipping_extra_charges = 0; 7086 var cod_charges = 0; 7087 7088 if ($("input[type='radio'].shipping_option").is(':checked')) { 7089 if ($("input[type='radio'].shipping_option:checked").data("shippingOptionId") !== undefined && parseInt($("input[type='radio'].shipping_option:checked").data("shippingOptionId")) == 2) { 7090 shipping_extra_charges = parseFloat($("input[type='radio'].shipping_option:checked").data('shippingExtraCharges')); 7091 } 7092 } 7093 7094 if ($("input[type='radio'].payment_mode").is(':checked')) { 7095 if ($("input[type='radio'].payment_mode:checked").data("paymentModeId") !== undefined && parseInt($("input[type='radio'].payment_mode:checked").data("paymentModeId")) == 4) { 7096 cod_charges = parseFloat($("input#extra_charges").val()); 7097 } 7098 } 7099 7100 total_additional_charges = parseFloat(shipping_extra_charges) + parseFloat(cod_charges); 7101 total_shipping = parseFloat(total_shipping) + parseFloat(total_additional_charges); 7102 total_payable_amount = parseFloat(total_payable_amount) + parseFloat(total_additional_charges); 7103 7104 if (parseInt(total_shipping) > 0) {
7105 if(window.BRAND_STORE_CURRENCY_SYMBOL_POSTFIX == 1) { 7106 $("span.span_shipping").html(Brand.formatMoney(total_shipping * 100, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY); 7107 } else { 7108 $("span.span_shipping").html(window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(total_shipping * 100, "{{amount}}")); 7109 } 7110 } else { 7111 if (defaultValues.IsWholesale != undefined && parseInt(defaultValues.IsWholesale) > 0) { 7112 $("span.span_shipping").html("To be calculated"); 7113 } else { 7114 $("span.span_shipping").html("FREE"); 7115 } 7116 } 7117 7118 if(window.BRAND_STORE_CURRENCY_SYMBOL_POSTFIX == 1) { 7119 $("span.span_total_payable").html(Brand.formatMoney(total_payable_amount * 100, "{{amount}}") + " " + window.app.BRAND_STORE_CURRENCY); 7120 } else { 7121 $("span.span_total_payable").html(window.app.BRAND_STORE_CURRENCY + " " + Brand.formatMoney(total_payable_amount * 100, "{{amount}}")); 7122 } 7123 }, 7124 showCouponDetail: function() { 7125 $(document).on("click", "a.coupon_detail", function(event) { 7126 event.stopPropagation(); 7127 if ($(this).data('couponCode').length > 0) { 7128 var couponCode = $(this).data('couponCode'); 7129 7130 $.ajax({
7131 type: "POST", 7132 async: false, 7133 cache: false, 7134 url: "/store_coupons/term_condition", 7135 dataType: "html", 7136 data: { 7137 "data[StoreCoupon][coupon_code]": couponCode 7138 }, 7139 beforeSend: function(XMLHttpRequest) { 7140 $('#myCouponModal').show(); 7141 $('#myCouponModal').find(".modal-body").html(''); 7142 }, 7143 success: function(data, textStatus) { 7144 $('#myCouponModal').find(".modal-body").html(data); 7145 }, 7146 error: function(jqXHR, textStatus, errorThrown) { 7147 if (jqXHR.status == 500) { 7148 alert('Internal error: ' + jqXHR.responseText); 7149 } 7150 $('#myCouponModal').hide(); 7151 } 7152 }); 7153 } 7154 }); 7155 7156 $(document).on("click", ".apply_code", function(event) { 7157 var couponCodeText = $(this).parent().find('h5#coupon_code_text').text(); 7158 $('input#coupon_code').val(couponCodeText); 7159 $("#submit").prop("disabled", false); 7160 }); 7161 $(document).on("click", ".apply_code_mobile", function(event) { 7162 var couponCodeText = $(this).parent().find('h5#coupon_code_text_mobile').text(); 7163 $('input#coupon_code').val(couponCodeText); 7164 $("#submit").prop("disabled", false); 7165 }); 7166 7167 /* $(document).on("click","form#StoreCouponCartForm button", function(event){ 7168 $(this).attr('disabled','disabled'); 7169 }); */ 7170 }, 7171 getStorePickupMap: function() { 7172 $('.nav-tabs li a').click(function() { 7173 FormData = "data[Customer][pickup_postal_code]=0"; 7174 $.ajax({
7175 type: "POST", 7176 async: true, 7177 cache: false, 7178 url: "/store_orders/ajax_getStoreByPincode", 7179 dataType: "json", 7180 data: FormData, 7181 beforeSend: function(XMLHttpRequest) { 7182 //$("button .verify-otp-code").addClass("disabled").attr("disabled", "disabled"); 7183 }, 7184 complete: function() { 7185 //$("button .verify-otp-code").removeClass("disabled").removeAttr("disabled"); 7186 }, 7187 success: function(data, textStatus) { 7188 if (data != undefined) { 7189 pupAddress = data; 7190 Theme.Utils.StoreOrder.initializeGoogleMap(); 7191 } 7192 }, 7193 error: function(jqXHR, textStatus, errorThrown) { 7194 console.log(jqXHR); 7195 if (jqXHR.status == 500) { 7196 alert('Internal error: ' + jqXHR.responseText); 7197 } 7198 } 7199 }); 7200 }); 7201 $('#pickup_postal_code').keyup(function() { 7202 Theme.Utils.StoreOrder.getClickedMapResult($(this).val()); 7203 }); 7204}, 7205initializeGoogleMap: function() { 7206 var myOptions = { 7207 // scrollwheel: false, 7208 zoom: 16, 7209 draggable: true, 7210 mapTypeId: google.maps.MapTypeId.ROADMAP 7211 }; 7212 //Creates a map object. 7213 mapCanvas = new google.maps.Map(document.getElementById('map_canvas'), myOptions); 7214 7215 //Creates a infowindow object. 7216 infoWnd = new google.maps.InfoWindow({ 7217 maxWidth: 350 7218 }); 7219 7220 //Mapping markers on the map 7221 var bounds = new google.maps.LatLngBounds(); 7222 var pup, i, latlng; 7223 var firstMarker; 7224 for (i in pupAddress) { 7225 //Creates a marker 7226 pup = pupAddress[i]; 7227 latlng = new google.maps.LatLng(pup.latlng[0], pup.latlng[1]); 7228 bounds.extend(latlng); 7229 var marker = Theme.Utils.StoreOrder.createMapMarker(mapCanvas, latlng, pup.name); 7230 7231 if (defaultPUPAddressId == pup.addressId) { 7232 firstMarker = marker; 7233 defaultFound = true; 7234 } 7235 7236 if (defaultFound == false && rdoCounter == 0) { 7237 firstMarker = marker; 7238 } 7239 7240 Theme.Utils.StoreOrder.createMapMarkerButton(marker, i, pup.addressId, pup.address_seperated, defaultPUPAddressId); 7241 google.maps.event.trigger(firstMarker, 'click'); 7242 } 7243 7244 //Fits the map bounds 7245 mapCanvas.fitBounds(bounds); 7246 zoomChangeBoundsListener = google.maps.event.addListenerOnce(mapCanvas, 'bounds_changed', function(event) { 7247 if (this.getZoom()) { 7248 this.setZoom(16); 7249 } 7250 }); 7251 setTimeout(function() { 7252 google.maps.event.removeListener(zoomChangeBoundsListener); 7253 }, 2000); 7254 }, 7255 createMapMarker: function(map, latlng, title) { 7256 //Creates a marker 7257 var marker = new google.maps.Marker({ 7258 position: latlng, 7259 map: map, 7260 id: title, 7261 animation: google.maps.Animation.DROP, 7262 // icon: 'https://img.dmart.in/images/rwd/dmart-symbol-logo.svg',// Marker icon 7263 scaledSize: new google.maps.Size(10, 10) // scaled size 7264 }); 7265 //The infoWindow is opened when the address is clicked 7266 google.maps.event.addListener(marker, 'click', function() { 7267 infoWnd.setContent($(this).attr('id')); 7268 map.setZoom(16); 7269 map.panTo(marker.getPosition()); 7270 infoWnd.open(map, marker); 7271 // infoWnd.close(); 7272 marker.addListener('click', toggleBounce); 7273 }); 7274 return marker; 7275 7276 function toggleBounce() { 7277 if (marker.getAnimation() !== null) { 7278 marker.setAnimation(null); 7279 } else { 7280 marker.setAnimation(google.maps.Animation.BOUNCE); 7281 } 7282 } 7283 }, 7284 createMapMarkerButton: function(marker, i, addressId, addressSep, defaultPUPAddressId) { 7285 //Creates a address buttons 7286 var ul = document.getElementById('marker_list'); 7287 var li = ul.querySelector('#sotreAddressLi_' + addressId); 7288 google.maps.event.addDomListener(li, 'click', function() { 7289 google.maps.event.trigger(marker, 'click'); 7290 }); 7291 }, 7292 getClickedMapResult: function(pincode) { 7293 var inputString = pincode; 7294 $.each($("#marker_list").children(), function(index, physicalStore) { 7295 var htmlData = $(physicalStore).html(); 7296 if (htmlData.toLowerCase().indexOf(inputString.toLowerCase()) == -1) { 7297 $(physicalStore).hide() 7298 } else { 7299 $("#pupDiv").css("display", "block"); 7300 $(physicalStore).show() 7301 } 7302 }); 7303 if (!$("#marker_list li").is(":visible")) { 7304 $("#divPincodeErrorBlock").css("display", "block"); 7305 $("#divSearchPostalCodes").css("display", "none"); 7306 } else { 7307 $("#divPincodeErrorBlock").css("display", "none"); 7308 $("#divSearchPostalCodes").css("display", "block"); 7309 } 7310 }, 7311 getMultipleAddresses: function() { 7312 7313 $("input[name='data[StoreOrder][customer_address_selected]']").change(function() { 7314 $('#divbilling').slideUp();
7315 $('#divshipping').slideUp(); 7316 7317 $('.radio-block').removeClass('active'); 7318 $(this).parent().parent().addClass('active'); 7319 var customerAddressId = $(this).val(); 7320 Theme.Utils.StoreOrder.editMultipleAddress(customerAddressId, false); 7321 /* 7322 var addressData = customAddressesObject[customerAddressId]; 7323 if(customerAddressId != null && addressData != undefined){ 7324 $("input#customer_address_id").val(addressData.id); 7325 $("input#shipping_first_name").val(addressData.shipping_first_name); 7326 $("input#shipping_last_name").val(addressData.shipping_last_name); 7327 $("input#shipping_address").val(addressData.shipping_address); 7328 $("input#shipping_zip").val(addressData.shipping_postal_code); 7329 $("select#shipping_city_id").val(addressData.shipping_city_id); 7330 $("input#shipping_city_name").val(addressData.shipping_city); 7331 $("input#shipping_company_name").val(addressData.shipping_company_name); 7332 $("input#shipping_gstin").val(addressData.shipping_gstin); 7333 $("select#shipping_state_id").val(addressData.shipping_state_id); 7334 $("select#shipping_country_id").val(addressData.shipping_country_id); 7335 $("input#shipping_state_name").val(addressData.shipping_state); 7336 $("input#payment_address").val(addressData.payment_address); 7337 $("input#payment_first_name").val(addressData.payment_first_name); 7338 $("input#payment_last_name").val(addressData.payment_last_name); 7339 $("input#payment_zip").val(addressData.payment_postal_code); 7340 $("input#payment_city_name").val(addressData.payment_city); 7341 $("select#payment_state_id").val(addressData.payment_state_id); 7342 $("select#payment_country_id").val(addressData.payment_country_id); 7343 $("input#payment_state_name").val(addressData.payment_state); 7344 $("select#shipping_address_type_id").val(addressData.shipping_address_type_id); 7345 if(parseInt(addressData.is_default) == 1){ 7346 $("input#default_address_id").prop('checked',true); 7347 } else { 7348 $("input#default_address_id").prop('checked',false); 7349 } 7350 7351 if(defaultValues.IsShippingServiceableCity == 1 && parseInt(addressData.shipping_country_id) == 101 && addressData.shipping_city_id == 0){ 7352 Theme.Utils.StoreOrder.getShippingSrilankaCities(addressData.shipping_country_id, addressData.shipping_state_id); 7353 } 7354 } else { 7355 alert('Invalid Request'); 7356 } */ 7357 }); 7358 7359 $('#add_new_address').click(function() { 7360 $('.exitingalladdress').prop('checked', false); 7361 $('label.error').fadeOut(); 7362 if ($('#divshipping').is(':visible')) { 7363 $('#divshipping').fadeOut(); 7364 $('#divbilling').fadeOut(); 7365 $('#divshipping').fadeIn(); 7366 $('#divbilling').fadeIn(); 7367 } else { 7368 $('#divshipping').slideDown(); 7369 $('#divbilling').slideDown(); 7370 } 7371 $('html, body').animate({ 7372 scrollTop: $("#divshipping").offset().top 7373 }, 1000); 7374 7375 if (!$('#StoreOrderOtherPayment').is(':checked')) { 7376 $("#StoreOrderOtherPayment").toggle(this.checked).trigger("click"); 7377 } 7378 7379 setTimeout(function() { 7380 $("input#customer_address_id").val(0); 7381 $("input#shipping_first_name").val(''); 7382 $("input#shipping_last_name").val(''); 7383 $("input#shipping_address").val(''); 7384 $("input#shipping_zip").val(''); 7385 $("input#shipping_city_name").val(''); 7386 $("select#shipping_city_id").val(0); 7387 $("input#shipping_company_name").val(''); 7388 $("input#shipping_gstin").val(''); 7389 $("select#shipping_state_id").val(0); 7390 $("input#shipping_phone").val(''); 7391 $("input#shipping_state_name").val(''); 7392 $("input#payment_address").val(''); 7393 $("input#payment_first_name").val(''); 7394 $("input#payment_last_name").val(''); 7395 $("input#payment_zip").val(''); 7396 $("input#payment_city_name").val(''); 7397 $("select#payment_state_id").val(''); 7398 $("input#payment_state_name").val(''); 7399 $("input#payment_phone").val(''); 7400 $("input#default_address_id").prop('checked', false); 7401 }, 400); 7402 }); 7403 7404 $('.edit_address').click(function() { 7405 var customerAddressId = $(this).data('id'); 7406 Theme.Utils.StoreOrder.editMultipleAddress(customerAddressId, true); 7407 }); 7408 7409 $('.delivery-option-ul').click(function() { 7410 var inputVar = $(this).find('input'); 7411 inputVar.prop('checked', true); 7412 }); 7413 }, 7414 editMultipleAddress: function(customerAddressId, isOpenView) { 7415 var addressData = customAddressesObject[customerAddressId]; 7416 if (customerAddressId != null && addressData != undefined) { 7417 if (isOpenView) { 7418 if ($('#divshipping').is(':visible')) {
7419 $('#divshipping').fadeOut(); 7420 $('#divbilling').fadeOut(); 7421 $('#divshipping').fadeIn(); 7422 $('#divbilling').fadeIn(); 7423 } else { 7424 $('#divshipping').slideDown(); 7425 $('#divbilling').slideDown(); 7426 } 7427 $('html, body').animate({ 7428 scrollTop: $("#divshipping").offset().top 7429 }, 1000); 7430 } 7431 7432 if (parseInt(deliveryPincodeCheckId) != 5) { 7433 if (defaultValues.IsShippingServiceableCity == 1 && parseInt(addressData.shipping_country_id) == 101) { 7434 if ($('select#shipping_state_id').has('option').length < 2) { 7435 Theme.Utils.StoreOrder.getShippingSrilankaStates(addressData.shipping_country_id); 7436 } 7437 Theme.Utils.StoreOrder.getShippingSrilankaCities(addressData.shipping_country_id, addressData.shipping_state_id); 7438 } else if (addressData.shipping_state_id != 0 && ($('select#shipping_state_id option').length < 2)) { 7439 Theme.Utils.StoreOrder.getShippingStates(addressData.shipping_country_id); 7440 } 7441 } 7442 //Set Default coundition. 7443 7444 if (parseInt(addressData.shipping_state_id) > 0) { 7445 $("#shipping_state_name").val('').removeAttr("required").hide(); 7446 $("#shipping_state_id").show().attr("required", "required").val(parseInt(addressData.shipping_state_id)); 7447 } else { 7448 //$("select#shipping_country_id").change(); 7449 $("#shipping_state_id").val('').removeAttr("required").hide(); 7450 $("#shipping_state_name").show().removeAttr("required"); 7451 } 7452 if (parseInt(deliveryPincodeCheckId) == 5) { 7453 if (!$("#shipping_state_name").is(':visible')) { 7454 Theme.Utils.StoreOrder.getShippingServiceableStates(addressData.shipping_country_id); 7455 } 7456 } 7457 if (parseInt(addressData.shipping_country_id) != 101 || defaultValues.IsShippingServiceableCity == 0) { 7458 $("#shipping_city_id").val(0).removeAttr("required").hide(); 7459 $("#shipping_city_name").show().removeAttr("required"); 7460 } else { 7461 if (parseInt(deliveryPincodeCheckId) != 5) { 7462 $("#shipping_city_id").show().attr("required", "required"); 7463 $("#shipping_city_name").val('').removeAttr("required").hide(); 7464 } 7465 } 7466 //Billing System 7467 if (parseInt(addressData.payment_state_id) > 0) { 7468 if ($('select#payment_state_id option').length < 2) { 7469 Theme.Utils.StoreOrder.getPaymentStates(addressData.payment_country_id); 7470 } 7471 $("#payment_state_id").show().attr("required", "required"); 7472 $("#payment_state_name").val('').removeAttr("required").hide(); 7473 } else { 7474 $("#payment_state_id").val(0).removeAttr("required").hide(); 7475 $("#payment_state_name").show().removeAttr("required"); 7476 } 7477 7478 //Check Phone Number and Pincode 7479 if (parseInt(addressData.shipping_country_id) == 101) { 7480 $("#shipping_phone").attr("minlength", 10).attr("maxlength", 11); 7481 $("#shipping_zip").attr("minlength", 6).attr("maxlength", 6).attr("onKeyUp", "allow_numeric(this);"); 7482 } else { 7483 $("#shipping_phone").removeAttr("minlength").attr("maxlength", 20); 7484 $("#shipping_zip").attr("minlength", 1).attr("maxlength", 10).removeAttr("onKeyUp"); 7485 } 7486 7487 if ($('#StoreOrderOtherPayment').is(':checked')) { 7488 $("#StoreOrderOtherPayment").toggle(this.checked).trigger("click"); 7489 } 7490 7491 setTimeout(function() { 7492 $("input#customer_address_id").val(addressData.id); 7493 $("input#shipping_first_name").val(addressData.shipping_first_name); 7494 $("input#shipping_last_name").val(addressData.shipping_last_name); 7495 $("input#shipping_address").val(addressData.shipping_address); 7496 $("input#shipping_zip").val(addressData.shipping_postal_code); 7497 $("select#shipping_city_id").val(addressData.shipping_city_id); 7498 $("input#shipping_city_name").val(addressData.shipping_city); 7499 $("input#shipping_company_name").val(addressData.shipping_company_name); 7500 $("input#shipping_gstin").val(addressData.shipping_gstin); 7501 $("select#shipping_state_id").val(addressData.shipping_state_id); 7502 $("select#shipping_country_id").val(addressData.shipping_country_id); 7503 $("input#shipping_state_name").val(addressData.shipping_state); 7504 $("input#payment_address").val(addressData.payment_address); 7505 $("input#payment_first_name").val(addressData.payment_first_name); 7506 $("input#payment_last_name").val(addressData.payment_last_name); 7507 $("input#payment_zip").val(addressData.payment_postal_code); 7508 $("input#payment_city_name").val(addressData.payment_city); 7509 $("select#payment_state_id").val(addressData.payment_state_id); 7510 $("input#payment_state_name").val(addressData.payment_state); 7511 $("select#payment_country_id").val(addressData.payment_country_id); 7512 $("select#shipping_address_type_id").val(addressData.shipping_address_type_id
7512); 7513 /* $("input[name='data[StoreOrder][shipping_address_type_id]']").prop('checked',false); 7514 if(addressData.shipping_address_type_id == 1){ 7515 $("input#shipping_address_type_id_home").prop('checked',true); 7516 } else if(addressData.shipping_address_type_id == 2){ 7517 $("input#shipping_address_type_id_office").prop('checked',true); 7518 } else if(addressData.shipping_address_type_id == 3){ 7519 $("input#shipping_address_type_id_other").prop('checked',true); 7520 } else { 7521 $("input#shipping_address_type_id_home").prop('checked',true); 7522 } 7523 */ 7524 if (parseInt(addressData.is_default) == 1) { 7525 $("input#default_address_id").prop('checked', true); 7526 } else { 7527 $("input#default_address_id").prop('checked', false); 7528 } 7529 7530 if (addressData.shipping_state_id != 0 && ($('select#shipping_state_id option').length > 2) && ($("select#shipping_state_id").val() == null || $("select#shipping_state_id").val() == '')) { 7531 Theme.Utils.StoreOrder.getShippingStates(addressData.shipping_country_id); 7532 $("select#shipping_state_id").val(addressData.shipping_state_id); 7533 } 7534 if (addressData.payment_state_id != 0 && ($('select#payment_state_id option').length > 2) && ($("select#payment_state_id").val() == null || $("select#payment_state_id").val() == '')) { 7535 Theme.Utils.StoreOrder.getPaymentStates(addressData.payment_country_id); 7536 $("select#payment_state_id").val(addressData.payment_state_id); 7537 } 7538 }, 500); 7539 } else { 7540 alert('Invalid Request'); 7541 } 7542 }, 7543 initOTPMobileCheckout: function() { 7544 var resendTimer; 7545 7546 $('#phone_email').keyup(function() { 7547 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', ''); 7548 // inputDetail = $(this); 7549 // parentDiv = inputDetail.parent('div'); 7550 // boxClass = parentDiv.find('span .fa'); 7551 // labelTag = parentDiv.find('label'); 7552 // if (inputDetail.val().length >= 1) { 7553 // if (!$.isNumeric(inputDetail.val())) { 7554 // //$(this).val(''); 7555 // //return false; 7556 // inputDetail.attr('maxlength',150); 7557 // /*boxClass.removeClass('fa-mobile', {duration:150}).addClass('fa-envelope-o', {duration:200}); 7558 // labelTag.html('Enter Email Address <span class="text-danger">*</span>'); 7559 // inputDetail.data('isMobile',2);*/ 7560 // } else { 7561 // inputDetail.attr('maxlength',10); 7562 // boxClass.removeClass('fa-envelope-o', { 7563 // duration: 150 7564 // }).addClass('fa-times', { 7565 // duration: 200 7566 // }); 7567 // //labelTag.html('Enter Mobile No <span class="text-danger">*</span>'); 7568 // $('.password-div').slideUp(); 7569 // inputDetail.data('isMobile', 1); 7570 // } 7571 // } 7572 }); 7573 7574 $(".mobile-otp .otp__input").keyup(function() { 7575 if (this.value.length == this.maxLength) { 7576 var $next = $(this).next('.otp__input'); 7577 if ($next.length) { 7578 $(this).next('.otp__input').focus(); 7579 } else { 7580 $(this).blur(); 7581 $(this).next('button').prop('disabled', false); 7582 } 7583 } 7584 }); 7585 7586 $("#CustomerLoginWithOtpForm").validate({ 7587 submitHandler: function(form) { 7588 //$('#otp_code').trigger("reset"); 7589 //var otpCode = ''; 7590 //$('.otp__input').each(function(){ 7591 // otpCode = otpCode+$(this).val(); 7592 //}); 7593 //$('#otp_code').val(otpCode); 7594 $("button.verify-otp-code").addClass("disabled").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 7595 setTimeout(function() { 7596 Theme.Utils.StoreOrder.verifyLoginOtp(); 7597 }, 2000); 7598 } 7599 }); 7600 7601 $('#btnloginsubmit').click(function() { 7602 let clickedForm = $("form#CustomerLoginFormOtp"); 7603 7604 var loginInputData = $('.login-input').val(); 7605 if ($('#phone_email').data('isMobile') == 1) { 7606 $('#login_mobile_p').html($('#phone_email').val()); 7607 Theme.Utils.StoreOrder.sendLoginOtp(clickedForm, 0); 7608 } else if ($('#phone_email').data('isMobile') == 2) { 7609 Theme.Utils.StoreOrder.checkAjaxEmailExists();
7610 } else if ($('#phone_email').data('isMobile') == 3) { 7611 $("#CustomerLoginFormOtp").submit(); 7612 } 7613 }); 7614 7615 // $('#btnloginsubmitotp').click(function() { 7616 // var loginInputData = $('.login-input').val(); 7617 // if (loginInputData) { 7618 // if ($('#phone_email').data('isMobile') == 1) { 7619 // $('#login_mobile_p').html($('#phone_email').val()); 7620 // Theme.Utils.StoreOrder.sendLoginOtp(0); 7621 // } else if ($('#phone_email').data('isMobile') == 2) { 7622 // Theme.Utils.StoreOrder.checkAjaxEmailExists(); 7623 // } else if ($('#phone_email').data('isMobile') == 3) { 7624 // $("#CustomerLoginFormOtp").submit(); 7625 // } 7626 // } else { 7627 // var phone = $("input#phone_email").val(); 7628 // if (phone.length < 10) { 7629 // Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Mobile number must be 10 digit numeric value.') 7630 // return; 7631 // } 7632 // } 7633 // }); 7634 7635 $('.btnloginsubmitotp').on('click', function(event) { 7636 event.preventDefault(); // Prevent the default form submission 7637 var clickedForm = $(this).closest('form'); 7638 7639 var loginInputData = clickedForm.find('.login-input').val(); 7640 let loginOtpOptions = clickedForm.find('input[name=loginOtpOptions]:checked').val(); 7641 7642 if (loginInputData) { 7643 if(loginOtpOptions.toLowerCase() == 'email') { 7644 if(loginInputData.length > 0 && Theme.Utils.Element.validateEmail(loginInputData) === true) { 7645 Theme.Utils.StoreOrder.sendLoginOtp(clickedForm, 0); 7646 } else { 7647 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Please enter valid email.'); 7648 return; 7649 } 7650 } else if(loginOtpOptions.toLowerCase() == 'sms' || loginOtpOptions.toLowerCase() == 'whatsapp') { 7651 if (loginInputData.length >= 10 && Theme.Utils.Element.validateNumeric(loginInputData) === true) { 7652 Theme.Utils.StoreOrder.sendLoginOtp(clickedForm, 0); 7653 } else { 7654 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Please enter valid mobile no.') 7655 return; 7656 } 7657 } 7658 // if (clickedForm.find('#phone_email').data('isMobile') == 1) { 7659 // clickedForm.find('#login_mobile_p').html(); 7660 // console.log(1); 7661 // Theme.Utils.StoreOrder.sendLoginOtp(clickedForm, 0); 7662 // } else if (clickedForm.find('#phone_email').data('isMobile') == 2) { 7663 // console.log(2); 7664 // Theme.Utils.StoreOrder.checkAjaxEmailExists(); 7665 // } else if (clickedForm.find('#phone_email').data('isMobile') == 3) { 7666 // //$("form#CustomerLoginFormOtp").submit(); 7667 // console.log(3); 7668 // clickedForm.submit(); 7669 // } 7670 } else { 7671 if(loginOtpOptions.toLowerCase() == 'email') { 7672 if(loginInputData.length <= 0 || Theme.Utils.Element.validateEmail(loginInputData) === false) { 7673 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Please enter valid email.'); 7674 return; 7675 } 7676 } else if(loginOtpOptions.toLowerCase() == 'sms' || loginOtpOptions.toLowerCase() == 'whatsapp') { 7677 if (loginInputData.length < 10 || Theme.Utils.Element.validateNumeric(loginInputData) === false) { 7678 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Please enter valid mobile no.') 7679 return; 7680 } 7681 } 7682 } 7683 }); 7684 7685 $('.otp-resend-code').click(function() { 7686 let clickedForm = $("form#CustomerLoginFormOtp"); 7687 Theme.Utils.StoreOrder.sendLoginOtp(clickedForm, 1); 7688 Theme.Utils.StoreOrder.reverseCountdownTimer(); 7689 $('.otp-resend-code').hide(); 7690 $('.otp-count-down').show(); 7691 }); 7692 7693 $('input[name=loginOtpOptions]').on('click', function(event) { 7694 let loginOtpOptions = $(this).val(); 7695 if(loginOtpOptions.toLowerCase() == 'email') { 7696 $(this).closest('form').find('.login_via').text(Theme.Language.getStr('LabelEmail')); 7697 $(this).closest('form').find('input#phone_email').attr('placeholder', Theme.Language.getStr('PlaceHolderEmailTxt'));
7698 } else if(loginOtpOptions.toLowerCase() == 'sms') { 7699 $(this).closest('form').find('.login_via').text(Theme.Language.getStr('LabelMobile')); 7700 $(this).closest('form').find('input#phone_email').attr('placeholder', Theme.Language.getStr('PlaceHolderMobileNoTxt')); 7701 } else if(loginOtpOptions.toLowerCase() == 'whatsapp') { 7702 $(this).closest('form').find('.login_via').text(Theme.Language.getStr('LabelWhatsappMobile')); 7703 $(this).closest('form').find('input#phone_email').attr('placeholder', Theme.Language.getStr('PlaceHolderMobileNoTxt')); 7704 } 7705 }); 7706 7707 $('#edit_login_mobile_number').click(function() { 7708 $('#otpCountainer').fadeOut(); 7709 $('#credentialCountainer').slideDown(); 7710 }); 7711 7712 Theme.Utils.StoreOrder.ajaxLogin(); 7713 Theme.Utils.StoreOrder.validateOTPMobileCheckout(); 7714 }, 7715 validateOTPMobileCheckout: function() { 7716 $("form#CustomerRegistrationForm").validate(); 7717 }, 7718 ajaxLogin: function() { 7719 $("#CustomerLoginFormOtp").validate({ 7720 submitHandler: function(form) { 7721 var Email = $(form).find("input#phone_email").val(); 7722 var Password = $(form).find("input#password").val(); 7723 var RedirectUrl = $(form).find("#redirect_url").val(); 7724 var FormData = "data[Customer][email]=" + Email + "&data[Customer][password]=" + Password + "&data[Customer][redirect_url]=" + RedirectUrl + ""; 7725 7726 $.ajax({
7727 type: "POST", 7728 async: true, 7729 cache: false, 7730 url: "/customers/ajax_login", 7731 accepts: 'application/json', 7732 dataType: "json", 7733 data: FormData, 7734 beforeSend: function(XMLHttpRequest) { 7735 $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled"); 7736 }, 7737 complete: function() { 7738 $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled"); 7739 }, 7740 success: function(data, textStatus) { 7741 if (data.login_status !== undefined && data.login_status == 1) { 7742 window.location.reload(); 7743 } else { 7744 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][password]', data.message); 7745 } 7746 }, 7747 error: function(jqXHR, textStatus, errorThrown) { 7748 if (jqXHR.status == 500) { 7749 alert('Internal error: ' + jqXHR.responseText); 7750 } 7751 } 7752 }); 7753 return false; // blocks redirect after submission via ajax 7754 } 7755 }); 7756 }, 7757 reverseCountdownTimer: function() { 7758 var timeleft = 60; 7759 var resendTimer; 7760 // Stop previous timer if already running 7761 if (resendTimer !== null) { 7762 clearInterval(resendTimer); 7763 } 7764 7765 $("#count_down_timer").text(timeleft); 7766 $('.otp-resend-code').hide(); 7767 $('.otp-count-down').show(); 7768 7769 resendTimer = setInterval(function () { 7770 timeleft--; 7771 $("#count_down_timer").text(timeleft); 7772 7773 if (timeleft <= 0) { 7774 clearInterval(resendTimer); 7775 resendTimer = null; 7776 7777 $('.otp-count-down').hide(); 7778 $('.otp-resend-code').show(); 7779 } 7780 }, 1000); 7781 7782 // $("#count_down_timer").text(timeleft); 7783 // var resendTimer = setInterval(function() { 7784 // $("#count_down_timer").text(timeleft--); 7785 // if (timeleft <= 0) { 7786 // clearInterval(resendTimer); 7787 // $('.otp-count-down').hide(); 7788 // $('.otp-resend-code').show(); 7789 // } 7790 // }, 1000); 7791 }, 7792 checkAjaxEmailExists: function() { 7793 var inputDetail = $("input#phone_email"); 7794 var Email = inputDetail.val(); 7795 $.ajax({
7796 type: "POST", 7797 async: true, 7798 cache: false, 7799 url: "/customers/ajax_email_exist", 7800 accepts: 'application/json', 7801 dataType: "json", 7802 data: "data[Customer][email]=" + Email, 7803 beforeSend: function(XMLHttpRequest) { 7804 $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled"); 7805 }, 7806 complete: function() { 7807 //$('html,body').animate({ scrollTop: $("#divreview").offset().top - 60}, 1000); 7808 $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled"); 7809 }, 7810 success: function(data, textStatus) { 7811 //console.log(data); 7812 if (data.email_exists !== undefined && data.email_exists == 1) { 7813 //console.log(data); 7814 $('.password-div').slideDown(); 7815 inputDetail.data('isMobile', 3); 7816 } else { 7817 $('#loginSignUpDiv').slideUp(); 7818 $('#createAccountDiv').slideDown(); 7819 $('#register_email').val(Email); 7820 $('#register_otp_div').hide(); 7821 } 7822 }, 7823 error: function(jqXHR, textStatus, errorThrown) { 7824 //alert(errorThrown); 7825 //console.log(errorThrown); 7826 if (jqXHR.status == 500) { 7827 alert('Internal error: ' + jqXHR.responseText); 7828 } 7829 } 7830 }); 7831 }, 7832 ajaxValidation: function(elementName, message) { 7833 var msg = '<label class="error pull-right" for="' + elementName + '" id="' + elementName + '-error">' + message + '</label>'; 7834 $("label.error").remove(); 7835 $('input[name="' + elementName + '"], select[name="' + elementName + '"]').parent().addClass('error').after(msg); 7836 }, 7837 // sendLoginOtp: function(resend) { 7838 // var phone = $("input#phone_email").val(); 7839 // if (phone.length < 10) { 7840 // Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Mobile number must be 10 digit numeric value.') 7841 // return; 7842 // } 7843 // var isResend = resend; 7844 // var FormData = "data[Customer][phone]=" + phone + "&data[Customer][is_resend]=" + isResend; 7845 7846 // $.ajax({
7847 // type: "POST", 7848 // async: true, 7849 // cache: false, 7850 // url: "/customers/send_login_otp", 7851 // accepts: 'application/json', 7852 // dataType: "json", 7853 // data: FormData, 7854 // beforeSend: function(XMLHttpRequest) { 7855 // $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled"); 7856 // }, 7857 // complete: function() { 7858 // $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled"); 7859 // }, 7860 // success: function(data, textStatus) { 7861 7862 // if (data.otp_status !== undefined && data.otp_status == 1) { 7863 // if (data.register_status !== undefined && data.register_status == 1 && data.is_resend == 0) { 7864 // $('#credentialCountainer').slideUp(); 7865 7866 // $('#otpCountainer').fadeIn(); 7867 // $('#otpCountainer').css('display', 'inline'); 7868 // Theme.Utils.StoreOrder.reverseCountdownTimer(); 7869 // } else if (data.register_status !== undefined && data.is_resend == 0) { 7870 // $('#loginSignUpDiv').slideUp(); 7871 // $('#createAccountDiv').slideDown(); 7872 // $('#register_phone').val(phone); 7873 // $(".msignup").css('display', 'none'); 7874 // } 7875 // } else { 7876 // Theme.Utils.StoreOrder.ajaxValidation('otp_code', data.message); 7877 // } 7878 // }, 7879 // error: function(jqXHR, textStatus, errorThrown) { 7880 // console.log(jqXHR); 7881 // if (jqXHR.status == 500) { 7882 // alert('Internal error: ' + jqXHR.responseText); 7883 // } 7884 // } 7885 // }); 7886 // return false; 7887 // }, 7888 sendLoginOtp: function(clickedForm, resend) { 7889 var phone = clickedForm.find("input#phone_email").val(); 7890 var loginOtpOptions = clickedForm.find('input[name="loginOtpOptions"]:checked').val(); 7891 7892 if(loginOtpOptions == undefined) { 7893 loginOtpOptions = 'SMS'; 7894 } 7895 7896 if (!$.isNumeric(phone)) { 7897 var pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; 7898 7899 if(!pattern.test(phone)) { 7900 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Please enter valid email address.') 7901 return; 7902 } 7903 } else { 7904 if (parseInt(window.Store.StoreConfig.store_country_id) == 101 && (phone.length < 10 || phone.length > 10)) { 7905 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', 'Mobile number must be 10 digit numeric value.') 7906 return; 7907 } 7908 } 7909 7910 var isResend = resend; 7911 clickedForm.find("button#btnloginsubmitotp").addClass("disabled").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 7912 if(typeof window.googleRecaptchaSiteKey != 'undefined') { 7913 grecaptcha.ready(function () { 7914 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'login'}).then(function (token) { 7915 clickedForm.find('input#recaptcha_response_mobile_login').val(token); 7916 }); 7917 }); 7918 } 7919 7920 setTimeout(function() { 7921 var recaptcha_response = clickedForm.find("input#recaptcha_response_mobile_login").val(); 7922 var FormData = "data[Customer][phone]=" + phone + "&data[Customer][loginOtpOptions]=" + loginOtpOptions + "&data[Customer][is_resend]=" + isResend + "&recaptcha_response=" + recaptcha_response; 7923 7924 $.ajax({
7925 type: "POST", 7926 async: true, 7927 cache: false, 7928 url: "/customers/send_login_otp", 7929 accepts: 'application/json', 7930 dataType: "json", 7931 data: FormData, 7932 beforeSend: function(XMLHttpRequest) { 7933 $("button#btnloginsubmit").addClass("disabled").attr("disabled", "disabled"); 7934 $("button#btnloginsubmitotp").addClass("disabled").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 7935 }, 7936 complete: function() { 7937 $("button#btnloginsubmit").removeClass("disabled").removeAttr("disabled"); 7938 $("button#btnloginsubmitotp").removeClass("disabled").removeAttr("disabled").find("span.spinner").addClass("d-none"); 7939 }, 7940 success: function(data, textStatus) { 7941 if (data.otp_status !== undefined && data.otp_status == 1) { 7942 //if (data.register_status !== undefined && data.register_status == 1 && data.is_resend == 0) { 7943 if (data.is_resend == 0) { 7944 // $('#credentialCountainer').slideUp(); 7945 // $('#otpCountainer').fadeIn(); 7946 // $('#otpCountainer').css('display', 'inline'); 7947 var login_user_id = phone.substring(3); 7948 $('.login-user-id').html("***"+login_user_id); 7949 $("div#loginwithemail").fadeOut('slow').addClass("d-none"); 7950 $("div#otpCountainer").fadeIn('slow').removeClass("d-none"); 7951 7952 Theme.Utils.StoreOrder.reverseCountdownTimer(); 7953 // } else if (data.register_status !== undefined && data.is_resend == 0) { 7954 // alert("s"); 7955 // $('#loginSignUpDiv').slideUp(); 7956 // $('#createAccountDiv').slideDown(); 7957 // $('#register_phone').val(phone); 7958 // $(".msignup").css('display', 'none'); 7959 } 7960 } else { 7961 Theme.Utils.StoreOrder.ajaxValidation('data[Customer][phone_email]', data.message); 7962 return; 7963 } 7964 }, 7965 error: function(jqXHR, textStatus, errorThrown) { 7966 console.log(jqXHR); 7967 if (jqXHR.status == 500) { 7968 alert('Internal error: ' + jqXHR.responseText); 7969 } 7970 } 7971 }); 7972 }, 2000); 7973 7974 return false; 7975 }, 7976 validateLogin: function() { 7977 $("#CustomerLoginForm").validate(); 7978 }, 7979 verifyLoginOtp: function() { 7980 var phone = $("input#phone_email").val(); 7981 var otpCode = $("input#otp_code").val(); 7982 var FormData = "data[Customer][phone]=" + phone + "&data[Customer][otp_code]=" + otpCode; 7983 $.ajax({
7984 type: "POST", 7985 async: true, 7986 cache: false, 7987 url: "/customers/verify_login_otp", 7988 accepts: 'application/json', 7989 dataType: "json", 7990 data: FormData, 7991 beforeSend: function(XMLHttpRequest) { 7992 $("button.verify-otp-code").addClass("disabled").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 7993 }, 7994 complete: function() { 7995 $("button.verify-otp-code").removeClass("disabled").removeAttr("disabled").find("span.spinner").addClass("d-none"); 7996 }, 7997 success: function(data, textStatus) { 7998 if (data.login_status !== undefined && data.login_status == 1) { 7999 window.location.reload(); 8000 } else if (data.register_status !== undefined && data.register_status == 1) { 8001 if(parseInt(window.Store.TemplateConfig.is_customer_register_in_popup) == 1 && !window.location.pathname.includes('/customers/login')) { 8002 var clickedForm = $("#frm_signup_modal").closest('form'); 8003 if (!$.isNumeric(phone)) { 8004 clickedForm.find("#email").val(phone); 8005 clickedForm.find("#phone").val(''); 8006 } else { 8007 clickedForm.find("#email").val(''); 8008 clickedForm.find("#phone").val(phone); 8009 } 8010 8011 $("div#modal-forgot-password").fadeOut('slow').addClass("d-none"); 8012 $("div#modal-login").fadeOut('slow').addClass("d-none"); 8013 $("div#modal-signup").fadeIn('slow').removeClass("d-none"); 8014 $("div#loginwithemail").fadeIn('slow').removeClass("d-none"); 8015 $("div#otpCountainer").fadeOut('slow').addClass("d-none"); 8016 $("#lbl_modal_title").text("Register"); 8017 } else { 8018 window.location.href = "/customers/register"; 8019 } 8020 } else { 8021 Theme.Utils.StoreOrder.ajaxValidation('otp_code', data.message); 8022 $("button.verify-otp-code").removeClass("disabled").removeAttr("disabled").find("span.spinner").addClass("d-none"); 8023 } 8024 }, 8025 error: function(jqXHR, textStatus, errorThrown) { 8026 console.log(jqXHR); 8027 if (jqXHR.status == 500) { 8028 alert('Internal error: ' + jqXHR.responseText); 8029 } 8030 } 8031 }); 8032 return false; 8033 } 8034}; 8035 8036Theme.Utils.OrderHistory = { 8037 initOrderHistory: function() { 8038 $('[data-toggle="tooltip"]').tooltip(); 8039 8040 $(document).on("click", ".cancel-order", function(event) { 8041 event.preventDefault(); 8042 if(confirm("Are you sure you want to cancel this order?")){ 8043 var order_id = $(this).data("id"); 8044 $.ajax({
8045 type: "POST", 8046 async: true, 8047 cache: false, 8048 url: "/store_orders/order_cancellation", 8049 accepts: 'application/json', 8050 dataType: "json", 8051 data: "order_id="+ order_id +"", 8052 beforeSend: function(XMLHttpRequest) { 8053 $("a.cancel-order").addClass("disabled").attr("disabled", "disabled"); 8054 }, 8055 complete: function() { 8056 $("a.cancel-order").removeClass("disabled").removeAttr("disabled"); 8057 }, 8058 success: function(data, textStatus) { 8059 if (data.order_status !== undefined && data.order_status == 1) { 8060 window.location.reload(); 8061 } else if (data.message !== undefined) { 8062 alert(data.message); 8063 } 8064 }, 8065 error: function(jqXHR, textStatus, errorThrown) { 8066 if (jqXHR.status == 500) { 8067 alert('Internal error: ' + jqXHR.responseText); 8068 } 8069 } 8070 }); 8071 } 8072 return false; 8073 }); 8074 }, 8075}; 8076 8077Theme.Utils.OrderTracking = { 8078 validateOrderTracking: function() { 8079 if(typeof $("#TrackOrderForm") !== 'undefined') { 8080 $("#TrackOrderForm").validate(); 8081 } 8082 8083 if(typeof $("#ViewOrderForm") !== 'undefined') { 8084 $("#ViewOrderForm").validate(); 8085 } 8086 } 8087}; 8088 8089Theme.Utils.IPGPayment = { 8090 initIPG: function() { 8091 $("#StorePaymentModeIpgForm").submit(); 8092 } 8093}; 8094 8095Theme.Utils.Page = { 8096 initContact: function() { 8097 $("#StorePageContactForm").validate(); 8098 }, 8099 initCustomRequirement: function() { 8100 $("#StorePageCustomRequirementForm").validate(); 8101 }, 8102 initProductEnquiry: function() { 8103 $("#StoreProductEnquiriesIndexForm").validate(); 8104 }, 8105 initServiceLogin: function() { 8106 $("#EnquiryServiceLoginSaveForm").validate({ 8107 errorPlacement: function(error, element) { 8108 if (element.parent('.checkbox').length) { 8109 error.insertAfter(element.parent()); 8110 } else { 8111 error.insertAfter(element); 8112 } 8113 }, 8114 submitHandler: function(form) { 8115 $("button#btn_service_login_submit").attr("disabled", "disabled"); 8116 8117 if(window.googleRecaptchaSiteKey !== 'undefined') { 8118 grecaptcha.ready(function () { 8119 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'service_login_save'}).then(function (token) { 8120 $(form).find('input#recaptchaResponse').val(token); 8121 }); 8122 }); 8123 } 8124 8125 setTimeout(function() { 8126 form.submit(); 8127 }, 2000); 8128 } 8129 }); 8130 }, 8131 initServiceOtpVerify: function() { 8132 $("#EnquiryOtpVerificationForm").validate({ 8133 errorPlacement: function(error, element) { 8134 if (element.parent('.checkbox').length) { 8135 error.insertAfter(element.parent()); 8136 } else { 8137 error.insertAfter(element); 8138 } 8139 }, 8140 submitHandler: function(form) { 8141 $("button#btn_service_login_submit").attr("disabled", "disabled"); 8142 8143 if(window.googleRecaptchaSiteKey !== 'undefined') { 8144 grecaptcha.ready(function () { 8145 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'otp_verification'}).then(function (token) { 8146 $(form).find('input#recaptchaResponse').val(token); 8147 }); 8148 }); 8149 } 8150 setTimeout(function() { 8151 form.submit(); 8152 }, 2000); 8153 } 8154 }); 8155 }, 8156}; 8157 8158Theme.Utils.NewsletterSubscribe = { 8159 validateSubscribe: function() { 8160 $("#StoreNewsletterSubscriber").validate({ 8161 errorPlacement: function(error, element) { 8162 if (element.parent('.checkbox').length) { 8163 error.insertAfter(element.parent()); 8164 } else { 8165 error.insertAfter(element); 8166 } 8167 }, 8168 submitHandler: function(form) { 8169 var data_serialize = $(form).serialize(); 8170 8171 $.ajax({
8172 type: "POST", 8173 async: true, 8174 cache: false, 8175 url: "/store_newsletter_subscribers/subscribe", 8176 dataType: "html", 8177 data: data_serialize, 8178 beforeSend: function(XMLHttpRequest) { 8179 $("#btnpopsubmit").attr('disabled', 'disabled').text("Please wait..."); 8180 }, 8181 success: function(data, textStatus) { 8182 $("#div_pop_response").append(data); 8183 $(form).remove(); 8184 //Set Popup not to display again 8185 sessionStorage.setItem('popHome', "1"); 8186 setTimeout(function() { 8187 $("#homepagePopupModal").modal('hide'); 8188 }, 2000); 8189 }, 8190 error: function(jqXHR, textStatus, errorThrown) { 8191 if (jqXHR.status == 500) { 8192 alert('Internal error: ' + jqXHR.responseText); 8193 } 8194 } 8195 }); 8196 } 8197 }); 8198 } 8199}; 8200 8201Theme.Utils.Wishlist = { 8202 initWishlist: function() { 8203 $(document).on("click", ".delete-wishlist", function(event) { 8204 //Check Variant Quantity 8205 var allowAdd = 0; 8206 var ProductId = 0; 8207 8208 ProductId = $(this).data('product-id'); 8209 8210 if (ProductId) { 8211 allowAdd = 1; 8212 } else if (!ProductId) { 8213 allowAdd = 0; 8214 } 8215 8216 //Now Process To Add 8217 if(parseInt(allowAdd) == 1) { 8218 //Check Form Process 8219 var FormData = "data[Product][id]=" + ProductId + ""; 8220 var answer = confirm("You cannot recover deleted products, do you wish to continue?"); 8221 if (answer) { 8222 8223 $.ajax({
8224 type: "POST", 8225 async: true, 8226 cache: false, 8227 url: "/store_product_wishlists/removefromwishlist", 8228 dataType: "json", 8229 data: FormData, 8230 beforeSend: function(XMLHttpRequest) { 8231 8232 }, 8233 success: function(data, textStatus) { 8234 if(data.wishlist_status == 1) 8235 { 8236 $(".div"+ ProductId +"").remove(); 8237 } 8238 }, 8239 error: function(jqXHR, textStatus, errorThrown) { 8240 if (jqXHR.status == 500) { 8241 alert('Internal error: ' + jqXHR.responseText); 8242 } 8243 } 8244 }); 8245 } else { 8246 return false; 8247 } 8248 } 8249 8250 }); 8251 }, 8252 deleteWishlist: function() { 8253 // $().on('click', { 8254 8255 // }) 8256 8257 $.validator.addMethod('chkwishlist', function(value) { 8258 return $('.chkwishlist:checked').size() > 0; 8259 }, 'Please select atleast one checkbox'); 8260 8261 $("#StoreProductWishlistPreviewForm").validate({ 8262 submitHandler: function(form) { 8263 var answer = confirm("You cannot recover deleted products, do you wish to continue?"); 8264 if (answer) { 8265 form.submit(); 8266 return true; 8267 } else { 8268 return false; 8269 } 8270 }, 8271 errorPlacement: function(error, element) { 8272 if (element.parent('.checkbox').length) { 8273 error.insertAfter(element.parent()); 8274 } else { 8275 error.insertAfter(element); 8276 } 8277 } 8278 }); 8279 } 8280}; 8281 8282Theme.Utils.Testimonial = { 8283 validateTestimonial: function() { 8284 $.validator.addMethod("country", function(value, element) { 8285 return $("#country_id").val() > 0; 8286 }, "Please select a country"); 8287 8288 $("form#StoreTestimonialIndexForm").validate({ 8289 submitHandler: function(form) { 8290 $("button#btntestimonialsubmit").attr("disabled", "disabled"); 8291 8292 if(window.googleRecaptchaSiteKey !== 'undefined') { 8293 grecaptcha.ready(function () { 8294 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'contact'}).then(function (token) { 8295 $(form).find('input#recaptchaResponse').val(token); 8296 }); 8297 }); 8298 } 8299 8300 setTimeout(function() { 8301 form.submit(); 8302 }, 2000); 8303 8304 return false; 8305 } 8306 }); 8307 } 8308}; 8309 8310Theme.Utils.PhotoGallery = { 8311 initPhotoGallery: function() { 8312 if($(document).find('.photo-gallery').length > 0) { 8313 initPhotoSwipeFromDOM(".photo-gallery"); 8314 } 8315 }, 8316 initMasonry: function() { 8317 if($(document).find('ul#grid-filter').length > 0) { 8318 $(document).on("click", "ul#grid-filter li", function(e) { 8319 e.preventDefault(); 8320 $('ul#grid-filter li.active').removeClass('active'); 8321 $(this).addClass("active"); 8322 }); 8323 } 8324 } 8325}; 8326 8327Theme.Utils.PressCoverage = { 8328 initPressCoverage: function() { 8329 $(".img_pop").on("click", function(e) { 8330 e.preventDefault(); 8331 $('div#pressModal .modal-body').empty(); 8332 var title = $(this).closest('a').attr("title"); 8333 $('div#pressModal .modal-title').html(title); 8334 var image_path = $(this).closest('a').data("image"); 8335 var img = '<img src="' + image_path + '" alt="" id="imgLarge" name="imgLarge" class="img-fluid mx-auto" />'; 8336 $(img).appendTo('div#pressModal .modal-body'); 8337 var pressModal = new bootstrap.Modal(document.getElementById('pressModal'), { backdrop: 'static', keyboard: false }); 8338 pressModal.show(); 8339 // $('#pressModal').modal({ 8340 // show: true 8341 // }); 8342 }); 8343 } 8344}; 8345 8346Theme.Utils.Currency = {
8347 initCurrency: function() { 8348 Theme.Utils.Currency.changeCurrency(); 8349 }, 8350 changeCurrency: function() { 8351 $(".currency-dropdown").on("change", function(event) { 8352 $(this).closest('form').submit(); 8353 }); 8354 } 8355}; 8356 8357Theme.Utils.Language = { 8358 initLanguage: function() { 8359 Theme.Utils.Language.changeLanguage(); 8360 }, 8361 changeLanguage: function() { 8362 $(".language-dropdown").on("change", function(event) { 8363 $(this).closest('form').submit(); 8364 }); 8365 } 8366}; 8367 8368Theme.Utils.ClientLogo = { 8369 initClientLogo: function() { 8370 $(".clients-logo img").on("click", function(e) { 8371 e.preventDefault 8372 $('div#clientModal .modal-body').empty(); 8373 var title = $(this).parent('a').attr("title"); 8374 $('div#clientModal .modal-title').html(title); 8375 var image_path = $(this).parent('a').data("image"); 8376 var img = '<img src="' + image_path + '" alt="" id="imgLarge" name="imgLarge" class="img-responsive" />'; 8377 $(img).appendTo('div#clientModal .modal-body'); 8378 $('#clientModal').modal({ 8379 show: true 8380 }); 8381 }); 8382 } 8383}; 8384 8385Theme.Utils.Tag = { 8386 initSort: function() { 8387 $("#sort_by").on("change", function(event) { 8388 event.preventDefault(); 8389 Theme.Utils.Tag.buildQueryString(); 8390 return false; 8391 }); 8392 }, 8393 initColorFilter: function() { 8394 $(".color-chk").on("click", function() { 8395 if (window.BRAND_STORE_ID === 3491 && $(this).is(":checked")) { 8396 $(".color-chk").not(this).prop("checked", false); 8397 } 8398 var colorArray = []; 8399 $('input.color-chk:checkbox:checked').each(function() { 8400 colorArray.push($(this).val()); 8401 }); 8402 Theme.Utils.Category.buildQueryString(); 8403 }); 8404 }, 8405 buildQueryString: function() { 8406 var sort_by = $("#sort_by").val(); 8407 8408 var colorArray = []; 8409 $('input.color-chk:checkbox:checked').each(function() { 8410 colorArray.push($(this).val()); 8411 }); 8412 var page_url = window.location.pathname + "?" + sort_by; 8413 8414 if (colorArray != "") { 8415 page_url = page_url + "&colors=" + colorArray; 8416 } 8417 page_url = page_url.replace(/(^\s*&)|(&\s*$)/g, ''); 8418 8419 window.location.href = page_url; 8420 } 8421}; 8422 8423Theme.Utils.CustomForm = { 8424 initCustomEnquiryForm: function() { 8425 /* 8426 $('.datepick').datetimepicker({ 8427 language: 'en', 8428 weekStart: 1, 8429 todayBtn: 1, 8430 autoclose: 1, 8431 todayHighlight: 1, 8432 startView: 2, 8433 forceParse: 0, 8434 showMeridian: 1, 8435 startDate : new Date(), 8436 pickTime: false 8437 }); 8438 8439 $('#date_image_button').on('click', function(){ 8440 $('.datepick').datetimepicker('show'); //support hide, show and destroy command 8441 }); 8442 */ 8443 Theme.Utils.Element.init(); 8444 8445 $("form#StoreCustomEnquiryForm").validate({ 8446 errorPlacement: function(error, element) { 8447 if (element.parent('.checkbox').length) { 8448 error.insertAfter(element.parent()); 8449 } else { 8450 error.insertAfter(element); 8451 } 8452 }, 8453 submitHandler: function(form) { 8454 $("button#btn_submit").attr("disabled", "disabled").find("span.spinner").removeClass("d-none"); 8455 8456 /* 8457 if(window.googleRecaptchaSiteKey !== 'undefined') { 8458 grecaptcha.ready(function () { 8459 grecaptcha.execute(window.googleRecaptchaSiteKey, {action: 'login'}).then(function (token) { 8460 $(form).find('input#recaptcha_response_register').val(token); 8461 }); 8462 }); 8463 } 8464 */ 8465 8466 setTimeout(function () { 8467 form.submit(); 8468 }, 2000); 8469 8470 return false; 8471 } 8472 }); 8473 } 8474 }; 8475 8476 Theme.Utils.Blog = { 8477 initBlog: function() { 8478 8479 var a = $("#searchtoggl i"), 8480 b = $("#searchbar"); 8481 $(".scroll-search a").on("click", function(c) { 8482 c.preventDefault(), "searchtoggl" == $(this).attr("id") && (b.is(":visible") ? a.removeClass("fa-times").addClass("fa-search") : a.removeClass("fa-search").addClass("fa-times"), b.slideToggle(300, function() {})) 8483 }), $("#searchform").submit(function(a) { 8484 a.preventDefault() 8485 }); 8486 8487 if(typeof $("input#blog_keyword") !== 'undefined') { 8488 $("input#blog_keyword").autocomplete({ 8489 source: function(a, b) { 8490 var c = a.term; 8491 $.ajax({
8492 type: "POST", 8493 async: !0, 8494 cache: !1, 8495 url: "/store_blog_articles/getBlogsByKeyword", 8496 dataType: "json", 8497 data: { 8498 "data[StoreProduct][keyword]": c 8499 }, 8500 beforeSend: function() {}, 8501 success: function(a) { 8502 b($.map(a, function(a) { 8503 return { 8504 label: a.blog_name, 8505 value: a.slug_url 8506 } 8507 })) 8508 }, 8509 error: function(a) { 8510 console.log(a.responseText), 500 == a.status && alert("Internal error: " + a.responseText) 8511 } 8512 }) 8513 }, 8514 select: function(a, b) { 8515 console.log(a); 8516 console.log(b); 8517 window.location.href = window.storeURL+"/blog/"+ b.item.value, b.item.value = b.item.label, this.value = b.item.label, a.preventDefault() 8518 }, 8519 focus: function(a, b) { 8520 a.preventDefault(), $("input#blog_keyword").val(b.item.label) 8521 } 8522 }); 8523 } 8524 8525 }, 8526 socialSharing: function() { 8527 $('.prettySocial').prettySocial(); 8528 } 8529}; 8530 8531Theme.Utils.Career = { 8532 validateCareer: function() { 8533 $.validator.addMethod("country", function(value, element) { 8534 return $("#country_id").val() > 0; 8535 }, "Please select a country"); 8536 8537 $("#StoreCareerIndexForm").validate(); 8538 } 8539}; 8540 8541Theme.Utils.Job = { 8542 initJob: function() { 8543 8544 }, 8545 validateJob: function() { 8546 $("#StoreJobThanksForm").validate(); 8547 8548 } 8549}; 8550 8551Theme.Utils.StoreAddress = { 8552 initStoreAddress: function() { 8553 $(document).on('click', "#btn_change_store_address", function() { 8554 $("div#div_store_addresses").toggleClass('d-none'); 8555 }); 8556 } 8557}; 8558 8559Theme.Utils.StoreOrderReturn = { 8560 validateOrderReturn: function() { 8561 $("form#ReturnRequestInitiateReturnRequestAcceptForm").validate(); 8562 // $("form#ReturnRequestInitiateReturnRequestAcceptForm").validate({ 8563 // ignore: [], 8564 // debug: true, 8565 // rules: { 8566 // reason_id: { 8567 // // <- NAME of every radio in the same group 8568 // required: true 8569 // } 8570 // }, 8571 // messages: { 8572 // reason_id: "Kindly select atleast one reason", 8573 // }, 8574 // invalidHandler: function(event, validator) { 8575 8576 // }, 8577 // errorPlacement: function(error, element) { 8578 // if (element.parent('.checkbox').length) { 8579 // error.insertAfter(element.parent()); 8580 // } else if (element.parent('.radio').length) { 8581 // error.insertAfter(element.parent().parent()); 8582 // } else { 8583 // error.insertAfter(element); 8584 // } 8585 // }, 8586 // submitHandler: function(form) { 8587 // $('button#btnsubmit').addClass("disabled").attr("disabled", "disabled"); 8588 // form.submit(); 8589 // } 8590 // }); 8591 } 8592} 8593 8594Theme.Utils.Wallet = { 8595 initWallet: function() { 8596 $('button#btn_recharge').on('click', function() { 8597 $('div#div_recharge').toggle(); 8598 }); 8599 8600 $('a.wallet-recharge-offer').on('click', function() { 8601 let walletRechargeAmount = $(this).data('walletRechargeAmount'); 8602 $("input#recharge_amount").val(walletRechargeAmount); 8603 }); 8604 } 8605};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.