1var communityStore = { 2 3 itemCount : 0, 4 5 openModal: function(content, animatecart) { 6 var whiteout = $(".store-whiteout"); 7 8 if (whiteout.length) { 9 whiteout.empty().html(content); 10 } else { 11 $(".ccm-page").append("<div class='store-whiteout'>" + content + "</div>"); 12 13 setTimeout(function() { 14 $('.store-cart-modal').addClass('store-cart-modal-active'); 15 }, 10); 16 17 whiteout.click(function(e) { 18 if (e.target != this) return; // only allow the actual whiteout background to close the dialog 19 communityStore.exitModal(); 20 }); 21 22 $(document).keyup("keyup.communitywhiteout", function(e) { 23 if (e.keyCode === 27) { 24 communityStore.exitModal(); 25 $(document).unbind("keyup.communitywhiteout"); 26 } 27 }); 28 } 29 30 if (animatecart) { 31 setTimeout(function() { 32 $('.store-cart-modal').addClass('store-cart-modal-active'); 33 }, 30); 34 } else { 35 $('.store-cart-modal').addClass('store-cart-modal-active'); 36 } 37 }, 38 39 waiting: function() { 40 communityStore.openModal("<div class='store-spinner-container'><div class='store-spinner'></div></div>"); 41 }, 42 43 exitModal: function() { 44 $(".store-whiteout").remove(); 45 }, 46 47 productModal: function(pID, locale) { 48 communityStore.waiting(); 49 $.ajax({
50 url: PRODUCTMODAL, 51 data: { pID: pID, locale: locale }, 52 type: 'get', 53 cache: false, 54 dataType: 'text', 55 success: function(modalContent) { 56 communityStore.openModal(modalContent); 57 } 58 }); 59 }, 60 61 displayCart: function(res, animatecart) { 62 var emptyModal = '<div class="store-cart-modal store-cart-modal-slide clearfix store-cart-modal-active loading" id="cart-modal" data-simplebar="init">' + 63 '<div class="store-cart-modal-header"><h2 id="cartLabel">Shopping Basket</h2></div>' + 64 '<div class="store-cart-page-cart"><div class="loader"></div></div>' + 65 '</div>'; 66 67 communityStore.openModal(emptyModal, animatecart); 68 $.ajax({ 69 type: "POST", 70 cache: false, 71 dataType: 'text', 72 data: res, 73 url: CARTURL + '/getmodal' + TRAILINGSLASH, 74 success: function(data) { 75 communityStore.openModal(data, false); 76 } 77 }); 78 }, 79 80 addOfferToCart: function(form){ 81 var valid = true; 82 83 $(form).find('input,textarea,select').filter('[required]').each(function(i, requiredField) { 84 if ($(requiredField).val() == '') { 85 $(requiredField).focus(); 86 valid = false; 87 } 88 }); 89 90 if (!valid) { 91 return false; 92 } 93 94 var offerItems = $(form).find('[name="pID"]'); 95 if(offerItems.length==0){ 96 return; 97 } 98 99 var token = $(form).find('[name="ccm_token"]').val(); 100 101 102 var res = ''; 103 communityStore.waiting(); 104 $(offerItems).each(function(){ 105 var productData = { 106 'pID': $(this).val(), 107 'quantity': $(this).data('quantity'), 108 'ccm_token': token 109 }; 110 111 $.ajax({
112 url: CARTURL + "/add" + TRAILINGSLASH, 113 data: productData, 114 type: 'post', 115 async: false, 116 cache: false, 117 dataType: 'text', 118 success: function(data) { 119 res = jQuery.parseJSON(data); 120 121 if (res.product.pAutoCheckout == '1') { 122 window.location.href = CHECKOUTURL; 123 return false; 124 } 125 } 126 }); 127 }); 128 129 communityStore.displayCart(res, true); 130 communityStore.refreshCartTotals(); 131 }, 132 133 addToCart: function(form) { 134 135 var valid = true; 136 137 138 var priceinput = $(form).find('.store-product-customer-price-entry-field'); 139 140 if (priceinput.length > 0) { 141 var max = parseFloat(priceinput.attr('max')); 142 var min = parseFloat(priceinput.attr('min')); 143 var customerprice = parseFloat(priceinput.val()); 144 145 if (customerprice < min || customerprice > max || !isFinite(customerprice)) { 146 priceinput.focus(); 147 valid = false; 148 } 149 150 } 151 152 $(form).find('input,textarea,select').filter('[required]').each(function(i, requiredField) { 153 if ($(requiredField).val() == '') { 154 $(requiredField).focus(); 155 valid = false; 156 } 157 }); 158 159 if (!valid) { 160 return false; 161 } 162 163 var qtyfield = $(form).find('.store-product-qty'); 164 var qty = qtyfield.val(); 165 if (qty > 0) { 166 var serial = $(form).serialize(); 167 communityStore.waiting(); 168 $.ajax({
169 url: CARTURL + "/add" + TRAILINGSLASH, 170 data: serial, 171 type: 'post', 172 cache: false, 173 dataType: 'text', 174 success: function(data) { 175 var res = jQuery.parseJSON(data); 176 177 if (res.product.pAutoCheckout == '1') { 178 window.location.href = CHECKOUTURL; 179 return false; 180 } 181 182 communityStore.displayCart(res, true); 183 communityStore.refreshCartTotals(); 184 } 185 }); 186 } else { 187 alert(QTYMESSAGE); 188 qtyfield.focus(); 189 } 190 }, 191 192 //Update a single item in cart 193 updateItem: function(instanceID, modal) { 194 var qty = $("*[data-instance-id='" + instanceID + "']").find(".store-cart-list-product-qty .form-control").val(); 195 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 196 //communityStore.waiting(); 197 $.ajax({
198 url: CARTURL + "/update" + TRAILINGSLASH, 199 data: { instance: instanceID, pQty: qty, ccm_token: ccm_token }, 200 type: 'post', 201 cache: false, 202 dataType: 'text', 203 success: function(data) { 204 if (modal) { 205 var res = jQuery.parseJSON(data); 206 communityStore.displayCart(res); 207 communityStore.refreshCartTotals(); 208 } 209 } 210 }); 211 }, 212 213 214 //Update multiple item quantities 215 updateMultiple: function(instances, quantities, modal) { 216 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 217 218 $.ajax({ 219 url: CARTURL + "/update" + TRAILINGSLASH, 220 data: { instance: instances, pQty: quantities, ccm_token: ccm_token }, 221 type: 'post', 222 cache: false, 223 dataType: 'text', 224 success: function(data) { 225 if (modal) { 226 var res = jQuery.parseJSON(data); 227 communityStore.displayCart(res); 228 communityStore.refreshCartTotals(); 229 } 230 } 231 }); 232 }, 233 234 removeItem: function(instanceID, modal) { 235 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 236 $.ajax({
237 url: CARTURL + "/remove" + TRAILINGSLASH, 238 data: { instance: instanceID, ccm_token: ccm_token }, 239 type: 'post', 240 cache: false, 241 dataType: 'text', 242 success: function(data) { 243 if (modal) { 244 var res = jQuery.parseJSON(data); 245 communityStore.displayCart(res); 246 communityStore.refreshCartTotals(); 247 } 248 } 249 }); 250 }, 251 252 clearCart: function(modal) { 253 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 254 $.ajax({ 255 url: CARTURL + "/clear" + TRAILINGSLASH, 256 type: 'post', 257 cache: false, 258 dataType: 'text', 259 data: { clear: 1, ccm_token: ccm_token }, 260 success: function(data) { 261 if (modal) { 262 var res = jQuery.parseJSON(data); 263 communityStore.displayCart(res); 264 } 265 266 $(".store-utility-links .store-items-counter").text(0); 267 $(".store-utility-links .store-total-cart-amount").text(""); 268 $(".store-utility-links").addClass('store-cart-empty'); 269 } 270 }); 271 }, 272 273 refreshCartTotals: function(callback) { 274 cart = this; 275 276 $.ajax({
277 url: CARTURL + '/getCartSummary' + TRAILINGSLASH, 278 cache: false, 279 dataType: 'text', 280 success: function(response) { 281 var values = $.parseJSON(response); 282 var itemCount = values.itemCount; 283 var items = values.items; 284 cart.itemCount = itemCount; 285 var subTotal = values.subTotal; 286 var total = values.total; 287 var totalCents = values.totalCents; 288 var taxes = values.taxes; 289 var shippingTotal = values.shippingTotal; 290 var shippingTotalRaw = values.shippingTotalRaw; 291 292 if (itemCount == 0) { 293 $(".store-utility-links .store-items-counter").text(0); 294 $(".store-utility-links .store-total-cart-amount").text(""); 295 $(".store-utility-links").addClass('store-cart-empty'); 296 } else { 297 $(".store-utility-links .store-items-counter").text(itemCount); 298 $(".store-cart-grand-total-value").text(total); 299 $(".store-utility-links .store-total-cart-amount").text(total); 300 $(".store-utility-links").removeClass('store-cart-empty'); 301 } 302 303 if (shippingTotalRaw === false) { 304 $("#shipping-total").text($("#shipping-total").data('unknown-label')); 305 } else if (shippingTotalRaw <= 0) { 306 $("#shipping-total").text($("#shipping-total").data('no-charge-label')); 307 } else { 308 $("#shipping-total").text(shippingTotal); 309 } 310 311 $("#store-taxes").html(""); 312 for (var i = 0; i < taxes.length; i++) { 313 if (taxes[i].taxed === true) { 314 $("#store-taxes").append('<li class="store-line-item store-tax-item list-group-item"><strong>' + taxes[i].name + ":</strong> <span class=\"store-tax-amount\">" + taxes[i].taxamount + "</span></li>"); 315 } 316 } 317 318 $(".store-sub-total-amount").text(subTotal); 319 $(".store-total-amount").text(total); 320 $(".store-total-amount").data('total-cents', totalCents); 321 322 setTimeout(function(){ 323 $('.store-cart-page-cart-total').animate({opacity: 0}, 300, function(){ 324 $(this).animate({opacity: 1}, 500); 325 }); 326 }, 1); 327 328 try { 329 if (items.length) { 330 $(items).each(function () { 331 _paq.push(['addEcommerceItem', 332 this.sku, // (Required) productSKU 333 this.name, // (Optional) productName 334 [], // (Optional) productCategory 335 this.price, // (Recommended) price 336 this.qty // (Optional, defaults to 1) quantity 337 ]); 338 }); 339 } 340 341 _paq.push(['trackEcommerceCartUpdate', totalCents / 100]); 342 } 343 catch(e){ 344 345 } 346 347 console.log('setting basket in local storage'); 348 349 const basketJSON = JSON.stringify(values); 350 localStorage.setItem("basket", basketJSON); 351 352 353 354 if (callback) { 355 callback(values); 356 } 357 } 358 }); 359 }, 360 361 362 363 basketKeepalive: function(){ 364 // Retrieving data: 365 let text = localStorage.getItem("basket"); 366 if(text){ 367 try { 368 let basket = JSON.parse(text); 369 } 370 catch(e){ 371 372 } 373 } 374 }, 375 376 // checkout 377 loadViaHash: function() { 378 var hash = window.location.hash; 379 hash = hash.replace('#', ''); 380 if (hash != "") { 381 $(".store-active-form-group").removeClass('store-active-form-group'); 382 var pane = $("#store-checkout-form-group-" + hash); 383 pane.addClass('store-active-form-group'); 384 385 $('html, body').animate({ 386 scrollTop: pane.offset().top - CHECKOUTSCROLLOFFSET 387 }); 388 } 389 }, 390 391 updateBillingStates: function(load, callback) { 392 var countryCode = $("#store-checkout-billing-country").val(); 393 var selectedState; 394 var classList = $("#store-checkout-billing-state").attr('class').toString(); 395 var dataList = JSON.stringify($("#store-checkout-billing-state").data()); 396 if (load) { 397 selectedState = $("#store-checkout-saved-billing-state").val(); 398 } else { 399 selectedState = ''; 400 } 401 402 $.ajax({
403 url: HELPERSURL + "/stateprovince/getstates" + TRAILINGSLASH, 404 type: 'post', 405 cache: false, 406 dataType: 'text', 407 data: { country: countryCode, selectedState: selectedState, type: "billing", class: classList, data: dataList }, 408 success: function(states) { 409 $("#store-checkout-billing-state").replaceWith(states); 410 if (callback) { 411 callback(); 412 } 413 } 414 }); 415 }, 416 417 updateShippingStates: function(load, callback) { 418 var countryCode = $("#store-checkout-shipping-country").val(); 419 var selectedState; 420 var classList = $("#store-checkout-shipping-state").attr('class').toString(); 421 var dataList = JSON.stringify($("#store-checkout-shipping-state").data()); 422 423 if (load) { 424 selectedState = $("#store-checkout-saved-shipping-state").val(); 425 } else { 426 selectedState = ''; 427 } 428 429 $.ajax({ 430 url: HELPERSURL + "/stateprovince/getstates" + TRAILINGSLASH, 431 type: 'post', 432 cache: false, 433 dataType: 'text', 434 data: { country: countryCode, selectedState: selectedState, type: "shipping", class: classList, data: dataList }, 435 success: function(states) { 436 $("#store-checkout-shipping-state").replaceWith(states); 437 if (callback) { 438 callback(); 439 } 440 } 441 }); 442 }, 443 444 nextPane: function(obj) { 445 if (typeof $(obj)[0].checkValidity === "undefined" || $(obj)[0].checkValidity()) { 446 var pane = $(obj).closest(".store-checkout-form-group").find('.store-checkout-form-group-body').parent().next(); 447 $('.store-active-form-group').removeClass('store-active-form-group'); 448 pane.addClass('store-active-form-group'); 449 $(obj).closest(".store-checkout-form-group").addClass('store-checkout-form-group-complete'); 450 451 $('html, body').animate({ 452 scrollTop: pane.offset().top - CHECKOUTSCROLLOFFSET 453 }); 454 455 pane.find('input').first().focus(); 456 } 457 }, 458 459 showShippingMethods: function(callback) { 460 $.ajax({
461 url: HELPERSURL + "/shipping/getshippingmethods" + TRAILINGSLASH, 462 cache: false, 463 dataType: 'text', 464 success: function(html) { 465 $("#store-checkout-shipping-method-options").html(html); 466 $('.store-whiteout').remove(); 467 468 if (callback) { 469 callback(); 470 } 471 }, 472 failure: function() { 473 $('.store-whiteout').remove(); 474 475 if (callback) { 476 callback(); 477 } 478 } 479 }); 480 }, 481 482 showPaymentForm: function() { 483 var pmID = $("#store-checkout-payment-method-options input[type='radio']:checked").attr('data-payment-method-id'); 484 $('.store-payment-method-container').addClass('hidden'); 485 $(".store-payment-method-container[data-payment-method-id='" + pmID + "']").removeClass('hidden'); 486 }, 487 488 copyBillingToShipping: function() { 489 $("#store-checkout-shipping-first-name").val($("#store-checkout-billing-first-name").val()); 490 $("#store-checkout-shipping-last-name").val($("#store-checkout-billing-last-name").val()); 491 $("#store-checkout-shipping-email").val($("#store-checkout-billing-email").val()); 492 $("#store-checkout-shipping-phone").val($("#store-checkout-billing-phone").val()); 493 494 if ($("#store-checkout-billing-company")) { 495 $("#store-checkout-shipping-company").val($("#store-checkout-billing-company").val()); 496 } 497 498 $("#store-checkout-shipping-address-1").val($("#store-checkout-billing-address-1").val()); 499 $("#store-checkout-shipping-address-2").val($("#store-checkout-billing-address-2").val()); 500 $("#store-checkout-shipping-country").val($("#store-checkout-billing-country").val()); 501 $("#store-checkout-shipping-city").val($("#store-checkout-billing-city").val()); 502 var billingstate = $("#store-checkout-billing-state").clone().val($("#store-checkout-billing-state").val()).attr("name", "store-checkout-shipping-state").attr("id", "store-checkout-shipping-state"); 503 $("#store-checkout-shipping-state").replaceWith(billingstate); 504 $("#store-checkout-shipping-zip").val($("#store-checkout-billing-zip").val()); 505 }, 506 507 sortNumber: function(a, b) { 508 return a - b; 509 }, 510 hasFormValidation: function() { 511 return (typeof document.createElement('input').checkValidity == 'function'); 512 }, 513 submitProductFilter: function(element) { 514 var filterform = element.closest('form'); 515 var checkboxes = filterform.find(':checked'); 516 var search = {}; 517 var matchtypes = {}; 518 519 checkboxes.each(function(index, field) { 520 var name = field.name.replace('[]', ''); 521 var value = encodeURIComponent(field.value); 522 var matchtype = field.getAttribute('data-matching'); 523 524 if (name in search) { 525 search[name].push(value); 526 } else { 527 search[name] = [value]; 528 matchtypes[name] = [matchtype === 'or' ? '|' : ';']; 529 } 530 }); 531 532 var strings = []; 533 534 $.each(search, function(key, value) { 535 strings.push(key + '=' + value.join(matchtypes[key])); 536 }); 537 538 var price = filterform.find("[name='price']"); 539 540 if (price.length) { 541 var min = parseFloat(price.data('min'), 2); 542 var max = parseFloat(price.data('max'), 2); 543 544 var pricerange = price.val(); 545 546 if (min + '-' + max !== pricerange) { 547 strings.push('price=' + price.val()); 548 } 549 } 550 551 var searchstring = strings.join('&'); 552 553 var params = {}; 554 var hasparams = false; 555 556 location.search.substr(1).split("&").forEach(function(item) { 557 var key = item.split("=")[0]; 558 if (key.indexOf('sort') === 0) { 559 params[key] = item.split("=")[1]; 560 hasparams = true; 561 } 562 }); 563 564 if (hasparams) { 565 searchstring = searchstring + '&' + $.param(params); 566 } 567 568 var id = filterform.attr('id'); 569 570 if (id) { 571 searchstring += '#' + filterform.attr('id'); 572 } 573 574 window.location = '?' + searchstring; 575 }, 576 clearProductFilter: function(element) { 577 var filterform = element.closest('form'); 578 var checkboxes = filterform.find(':checked'); 579 var search = {}; 580 581 checkboxes.each(function(index, field) { 582 checkboxes.prop('checked', false); 583 }); 584 585 filterform.find('[name="price"]').val(''); 586 587 communityStore.submitProductFilter(element); 588 }, 589 processOtherAttributes: function() { 590 591 var extrafields = $('#store-checkout-form-group-payment #store-extrafields'); 592 593 if (extrafields.length) { 594 extrafields.remove(); 595 } 596 597 $('#store-checkout-form-group-payment').append('<div id="store-extrafields" style="display: none"></div>'); 598 599 $("#store-checkout-form-group-other-attributes .row").each(function(index, el) { 600 601 var novalue = $("#store-checkout-form-group-other-attributes").data('no-value'); 602 603 if (!novalue) { 604 novalue = ''; 605 } 606 607 var yesvalue = $("#store-checkout-form-group-other-attributes").data('yes-value'); 608 609 if (!yesvalue) { 610 yesvalue = 'Yes'; 611 } 612 613 var akID = $(el).data("akid"); 614 var field = $(el).find(".form-control"); 615 616 var value = '0'; 617 var displayvalue = ''; 618 var isselect = false; 619 620 // look for checkbox or radio 621 if (!field.length) { 622 field = $(el).find("[type=checkbox]").first(); 623 var label = $(el).find(".checkbox label").first(); 624 625 if (!label.text()) { 626 label = $(field).next(); 627 } 628 629 if (field.length) { 630 if (field.is(':checked')) { 631 value = '1'; 632 displayvalue = yesvalue; 633 } else { 634 displayvalue = novalue; 635 } 636 } else { 637 field = $(el).find('input[type=radio]:checked'); 638 if (field) { 639 displayvalue = field.closest('label').text().trim(); 640 } 641 } 642 } else { 643 value = field.val(); 644 645 if (field.is('select')) { 646 displayvalue = field.children(':selected').text(); 647 var isselect = true; 648 } else { 649 displayvalue = value; 650 } 651 } 652 653 654 if (field.length) { 655 displayvalue = displayvalue.replace(/[\n\r]/g, '<br>').trim(); 656 657 if (!displayvalue) { 658 displayvalue = '-'; 659 } 660 661 $('.store-summary-order-choices-' + akID).html(displayvalue); 662 $('#akIDinput' + akID).remove(); 663 664 var newfield = field.clone(); 665 666 if (isselect) { 667 newfield.val(field.val()); 668 } 669 670 newfield.appendTo($('#store-checkout-form-group-payment #store-extrafields')); 671 672 673 } 674 }); 675 676 }, 677 number_format: function (number, decimals, dec_point, thousands_sep) { 678 number = number*1;//makes sure `number` is numeric value 679 var str = number.toFixed(decimals?decimals:0).toString().split('.'); 680 var parts = []; 681 for ( var i=str[0].length; i>0; i-=3 ) { 682 parts.unshift(str[0].substring(Math.max(0,i-3),i)); 683 }
684 str[0] = parts.join(thousands_sep?thousands_sep:','); 685 return str.join(dec_point?dec_point:'.'); 686 } 687 688}; 689 690$(document).ready(function() { 691 if ($('.store-checkout-form-shell form').length > 0) { 692 communityStore.updateBillingStates(true); 693 if ($('#store-checkout-form-group-shipping').length > 0) { 694 communityStore.updateShippingStates(true); 695 communityStore.showShippingMethods(); 696 } 697 communityStore.showPaymentForm(); 698 } 699 700 $("#store-checkout-form-group-billing").submit(function(e) { 701 e.preventDefault(); 702 var email = $("#store-email").val(); 703 var bfName = $("#store-checkout-billing-first-name").val(); 704 var blName = $("#store-checkout-billing-last-name").val(); 705 var bPhone = $("#store-checkout-billing-phone").val(); 706 707 var bCompany = ''; 708 709 if ($("#store-checkout-billing-company")) { 710 bCompany = $("#store-checkout-billing-company").val(); 711 } 712 713 var bAddress1 = $("#store-checkout-billing-address-1").val(); 714 var bAddress2 = $("#store-checkout-billing-address-2").val(); 715 var bCountry = $("#store-checkout-billing-country").val(); 716 var bCity = $("#store-checkout-billing-city").val(); 717 var bState = $("#store-checkout-billing-state").val(); 718 var bPostal = $("#store-checkout-billing-zip").val(); 719 var notes = $("#store-checkout-notes").val(); 720 $("#store-checkout-form-group-billing .store-checkout-form-group-body .store-checkout-errors").remove(); 721 722 var ccm_token = $(this).find('[name=ccm_token]').val(); 723 724 if ($('#store-checkout-form-group-billing #store-checkout-form-group-other-attributes').length) { 725 communityStore.processOtherAttributes(); 726 } 727 728 communityStore.waiting(); 729 var obj = $(this); 730 $.ajax({
731 url: CHECKOUTURL + "/updater" + TRAILINGSLASH, 732 type: 'post', 733 cache: false, 734 dataType: 'text', 735 data: { 736 ccm_token: ccm_token, 737 adrType: 'billing', 738 email: email, 739 fName: bfName, 740 lName: blName, 741 phone: bPhone, 742 company: bCompany, 743 addr1: bAddress1, 744 addr2: bAddress2, 745 count: bCountry, 746 city: bCity, 747 state: bState, 748 postal: bPostal, 749 notes: notes 750 }, 751 success: function(result) { 752 //var test = null; 753 var response = JSON.parse(result); 754 755 if (response.error == false) { 756 757 if ($('#store-copy-billing').is(":checked")) { 758 communityStore.copyBillingToShipping(); 759 $("#store-checkout-form-group-shipping").submit(); 760 $('#store-copy-billing').prop('checked', false) 761 } else { 762 $(".store-whiteout").remove(); 763 } 764 765 obj.find('.store-checkout-form-group-summary .store-summary-name').html(response.first_name + ' ' + response.last_name); 766 obj.find('.store-checkout-form-group-summary .store-summary-phone').html(response.phone); 767 obj.find('.store-checkout-form-group-summary .store-summary-email').html(response.email); 768 obj.find('.store-checkout-form-group-summary .store-summary-address').html(response.address); 769 obj.find('.store-checkout-form-group-summary .store-summary-notes').html(response.notes); 770 771 if (response.notes) { 772 obj.find('#store-check-notes-container').show(); 773 } else { 774 obj.find('#store-check-notes-container').hide(); 775 } 776 777 communityStore.nextPane(obj); 778 communityStore.refreshCartTotals(); 779 780 } else { 781 $("#store-checkout-form-group-billing .store-checkout-form-group-body ").prepend('<div class="store-checkout-errors"><div class="store-checkout-error alert alert-danger"></div></div>'); 782 $("#store-checkout-form-group-billing .store-checkout-error").html(response.errors.join('<br>')); 783 $('.store-whiteout').remove(); 784 } 785 }, 786 error: function(data) { 787 $(".store-whiteout").remove(); 788 } 789 }); 790 791 }); 792 793 $("#store-checkout-form-group-shipping").submit(function(e) { 794 e.preventDefault(); 795 var sfName = $("#store-checkout-shipping-first-name").val(); 796 var slName = $("#store-checkout-shipping-last-name").val(); 797 var sCompany = ''; 798 799 if ($("#store-checkout-shipping-company")) { 800 sCompany = $("#store-checkout-shipping-company").val(); 801 } 802 803 var sAddress1 = $("#store-checkout-shipping-address-1").val(); 804 var sAddress2 = $("#store-checkout-shipping-address-2").val(); 805 var sCountry = $("#store-checkout-shipping-country").val(); 806 var sCity = $("#store-checkout-shipping-city").val(); 807 var sState = $("#store-checkout-shipping-state").val(); 808 var sPostal = $("#store-checkout-shipping-zip").val(); 809 $("#store-checkout-form-group-shipping .store-checkout-form-group-body .store-checkout-errors").remove(); 810 811 var ccm_token = $(this).find('[name=ccm_token]').val(); 812 813 if ($('#store-checkout-form-group-shipping #store-checkout-form-group-other-attributes').length) { 814 communityStore.processOtherAttributes(); 815 } 816 817 communityStore.waiting(); 818 var obj = $(this); 819 $.ajax({
820 url: CHECKOUTURL + "/updater" + TRAILINGSLASH, 821 type: 'post', 822 cache: false, 823 dataType: 'text', 824 data: { 825 ccm_token: ccm_token, 826 adrType: 'shipping', 827 fName: sfName, 828 lName: slName, 829 company: sCompany, 830 addr1: sAddress1, 831 addr2: sAddress2, 832 count: sCountry, 833 city: sCity, 834 state: sState, 835 postal: sPostal 836 }, 837 //dataType: 'json', 838 success: function(result) { 839 var response = JSON.parse(result); 840 if (response.error == false) { 841 obj.find('.store-checkout-form-group-summary .store-summary-name').html(response.first_name + ' ' + response.last_name); 842 obj.find('.store-checkout-form-group-summary .store-summary-address').html(response.address); 843 obj.find('.store-checkout-form-group-summary .store-summary-company').html(response.company); 844 if (response.vat_number != '') { 845 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(response.vat_number); 846 } else { 847 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html('-'); 848 } 849 communityStore.showShippingMethods(function() { 850 communityStore.refreshCartTotals(); 851 communityStore.nextPane(obj); 852 }); 853 } else { 854 $("#store-checkout-form-group-shipping .store-checkout-form-group-body").prepend('<div class="store-checkout-errors"><div class="alert alert-danger"></div></div>'); 855 $("#store-checkout-form-group-shipping .alert").html(response.errors.join('<br>')); 856 $('.store-whiteout').remove(); 857 } 858 }, 859 error: function(data) { 860 $(".store-whiteout").remove(); 861 } 862 }); 863 864 }); 865 866 $("#store-checkout-form-group-vat").submit(function(e) { 867 e.preventDefault(); 868 var vat_number = $("#store-checkout-shipping-vat-number").val(); 869 $("#store-checkout-form-group-vat .store-checkout-errors").remove(); 870 var ccm_token = $(this).find('[name=ccm_token]').val(); 871 872 if ($('#store-checkout-form-group-vat #store-checkout-form-group-other-attributes').length) { 873 communityStore.processOtherAttributes(); 874 } 875 876 communityStore.waiting(); 877 var obj = $(this); 878 $.ajax({
879 url: HELPERSURL + "/tax/setvatnumber" + TRAILINGSLASH, 880 type: 'post', 881 cache: false, 882 dataType: 'text', 883 data: { 884 vat_number: vat_number, 885 ccm_token: ccm_token 886 }, 887 success: function(result) { 888 //var test = null; 889 var response = JSON.parse(result); 890 if (response.error == false) { 891 if (response.vat_number != '') { 892 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(response.vat_number); 893 } else { 894 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(obj.find('.store-checkout-form-group-summary .store-summary-vat-number').data('vat-blank')); 895 } 896 communityStore.refreshCartTotals(); 897 communityStore.nextPane(obj); 898 $('.store-whiteout').remove(); 899 } else { 900 901 902 $("#store-checkout-form-group-vat .store-checkout-form-group-body ").prepend('<div class="store-checkout-errors"><div class="store-checkout-error alert alert-danger"></div></div>'); 903 $("#store-checkout-form-group-vat .store-checkout-error").html(response.errors.join('<br>')); 904 $('.store-whiteout').remove(); 905 } 906 }, 907 error: function(data) { 908 $(".store-whiteout").remove(); 909 } 910 }); 911 912 }); 913 914 $("#store-checkout-form-group-shipping-method").submit(function(e) { 915 e.preventDefault(); 916 communityStore.waiting(); 917 var obj = $(this); 918 var ccm_token = $(this).find('[name=ccm_token]').val(); 919 920 if ($("#store-checkout-shipping-method-options input[type='radio']:checked").length < 1) { 921 $('.store-whiteout').remove(); 922 alert($('#store-checkout-shipping-method-options').data('error-message')); 923 } else { 924 var smID = $("#store-checkout-shipping-method-options input[type='radio']:checked").val(); 925 var methodText = $.trim($("#store-checkout-shipping-method-options input[type='radio']:checked").parent().find('.store-shipping-details').html()); 926 obj.find('.summary-shipping-method').html(methodText); 927 var sInstructions = $('#store-checkout-shipping-instructions').val(); 928 obj.find('.summary-shipping-instructions').html(sInstructions); 929 930 $.ajax({
931 type: 'post', 932 cache: false, 933 dataType: 'text', 934 data: { 935 smID: smID, 936 sInstructions: sInstructions, 937 ccm_token: ccm_token 938 }, 939 url: HELPERSURL + "/shipping/selectshipping" + TRAILINGSLASH, 940 success: function(total) { 941 communityStore.refreshCartTotals(function() { 942 communityStore.nextPane(obj); 943 $('.store-whiteout').remove(); 944 }); 945 } 946 }); 947 948 } 949 }); 950 951 $(".store-btn-previous-pane").click(function(e) { 952 //hide the body of the current pane, go to the next pane, show that body. 953 var pane = $(this).closest(".store-checkout-form-group").find('.store-checkout-form-group-body').parent().prev(); 954 $('.store-active-form-group').removeClass('store-active-form-group'); 955 pane.addClass('store-active-form-group'); 956 957 $('html, body').animate({ 958 scrollTop: pane.parent().offset().top - CHECKOUTSCROLLOFFSET 959 }); 960 961 $(this).closest(".store-checkout-form-group").prev().removeClass("store-checkout-form-group-complete"); 962 e.preventDefault(); 963 }); 964 965 $("#store-checkout-payment-method-options input[type='radio']").change(function() { 966 communityStore.showPaymentForm(); 967 }); 968 969 $('#store-cart .store-btn-cart-list-remove').click(function(e) { 970 $('#deleteform input[name=instance]').val($(this).data('instance')); 971 $('#deleteform').submit(); 972 e.preventDefault(); 973 }); 974 975 $(document).on('click', '.store-btn-add-to-cart', function(e) { 976 var add = false; 977 978 if ($(this).data('invalid') == '1') { 979 $(this).data('invalid', '0'); 980 } else { 981 982 if (communityStore.hasFormValidation()) { 983 if (!$(this).closest('form')[0].checkValidity()) { 984 985 $(this).data('invalid', '1'); 986 $(this).click(); 987 } else { 988 add = true; 989 } 990 } else { 991 add = true; 992 } 993 994 if (add) { 995 communityStore.addToCart($(this).closest('form')[0]); 996 e.preventDefault(); 997 } 998 } 999 1000 }); 1001 1002 $(document).on('submit', '.store-product-block', function(e) { 1003 if ($(this).find('.store-btn-add-to-cart').length > 0) { 1004 communityStore.addToCart($(this)); 1005 } 1006 e.preventDefault(); 1007 }); 1008 1009 $(document).on('click', '.store-btn-add-to-cart-offer', function(e) { 1010 var add = false; 1011 1012 if ($(this).data('invalid') == '1') { 1013 $(this).data('invalid', '0'); 1014 } else { 1015 1016 if (communityStore.hasFormValidation()) { 1017 if (!$(this).closest('form')[0].checkValidity()) { 1018 1019 $(this).data('invalid', '1'); 1020 $(this).click(); 1021 } else { 1022 add = true; 1023 } 1024 } else { 1025 add = true; 1026 } 1027 1028 if (add) { 1029 communityStore.addOfferToCart($(this).closest('form')[0]); 1030 e.preventDefault(); 1031 } 1032 } 1033 1034 }); 1035 1036 $(document).on('click', '.store-price-suggestion', function(e) { 1037 var productform = $(this).closest('form'); 1038 productform.find('.store-product-customer-price-entry-field').val($(this).data('suggestion-value')); 1039 communityStore.addToCart(productform); 1040 e.preventDefault(); 1041 }); 1042 1043 $(document).on('click', '.store-btn-cart-list-remove', function(e) { 1044 communityStore.removeItem($(this).data('instance-id'), $(this).data('modal')); 1045 e.preventDefault(); 1046 }); 1047 1048 $('.store-product-quick-view').click(function(e) { 1049 communityStore.productModal($(this).data('product-id'), $(this).data('locale')); 1050 e.preventDefault(); 1051 });
1052 1053 $('.store-cart-link-modal').click(function(e) { 1054 communityStore.displayCart(false, true); 1055 e.preventDefault(); 1056 }); 1057 1058 $(document).on('click', '.store-modal-exit, .store-btn-cart-modal-continue', function(e) { 1059 communityStore.exitModal(); 1060 e.preventDefault(); 1061 }); 1062 1063 $(document).on('click', '.store-btn-cart-modal-clear', function(e) { 1064 communityStore.clearCart(true); 1065 $(this).addClass('disabled'); 1066 e.preventDefault(); 1067 }); 1068 1069 $(document).on('click', '.store-btn-cart-modal-update', function(e) { 1070 var update = false; 1071 1072 if ($(this).data('invalid') == '1') { 1073 $(this).data('invalid', '0'); 1074 } else { 1075 if (communityStore.hasFormValidation()) { 1076 if (!$(this).closest('form')[0].checkValidity()) { 1077 $(this).data('invalid', '1'); 1078 $(this).click(); 1079 } else { 1080 update = true; 1081 } 1082 } else { 1083 update = true; 1084 } 1085 1086 if (update) { 1087 var instances = $("#store-modal-cart input[name='instance[]']").map(function() { 1088 return $(this).val(); 1089 }).get(); 1090 var pQty = $("#store-modal-cart input[name='pQty[]']").map(function() { 1091 return $(this).val(); 1092 }).get(); 1093 1094 communityStore.updateMultiple(instances, pQty, true); 1095 $(this).addClass('disabled'); 1096 e.preventDefault(); 1097 } 1098 } 1099 1100 }); 1101 1102 $('.store-cart-modal-link').click(function(e) { 1103 e.preventDefault(); 1104 communityStore.displayCart(false, true); 1105 }); 1106 1107 $('.store-btn-filter').click(function(e) { 1108 e.preventDefault(); 1109 communityStore.submitProductFilter($(this)); 1110 }); 1111 1112 $(document).on('change', '.store-product-filter-block-auto input[type="checkbox"]', function(e) { 1113 communityStore.submitProductFilter($(this)); 1114 }); 1115 1116 $(document).on('click', '.store-btn-filter-clear', function(e) { 1117 communityStore.clearProductFilter($(this)); 1118 }); 1119 1120});
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.