1class BuyClickElement { 2 constructor(params) { 3 this.params = params; 4 this.available_open = false; 5 6 this.selected = { 7 size: false, 8 height: false, 9 store: false, 10 }; 11 } 12 13 init(selected) { 14 if (selected != undefined) { 15 if (selected.size || selected.height) 16 this.selected = selected; 17 } 18 19 if (this.params.OFFERS) { 20 if (this.params.OFFERS.ROST !== undefined) { 21 if (this.selected.size) this.changeParam("size", this.selected.size); 22 else this.redrawParam("size", this.params.OFFERS.ROST); 23 } 24 25 if (this.params.OFFERS.RAZMER !== undefined) { 26 if (this.selected.height) 27 this.changeParam("height", this.selected.height); 28 else this.redrawParam("height", this.params.OFFERS.RAZMER); 29 } 30 } 31 32 this.loadAvailable(); 33 } 34 35 redrawParam(type, array, available = []) { 36 var wrap = type == "size" ? "height" : "size"; 37 // if($(window).width()<992){ 38 // var select = $('.product-one-click select.product__param_'+wrap); 39 // select.empty(); 40 // $.each(array, function(index, val) { 41 // if(typeof Product != 'undefined'){ 42 // if(!Product.selected[wrap]) Product.selected[wrap] = val; 43 // } 44 // select.append('<option value="'+val+'">'+val+'</div>'); 45 // }); 46 47 // if(this.selected[wrap]) 48 // select.val(this.selected[wrap]) 49 50 // if(select.val() != this.selected[wrap]) 51 // this.selected[wrap] = false; 52 53 // $('.custom-select').selectpicker('refresh'); 54 // }else{ 55 $(".product-one-click .product__param_" + wrap).empty(); 56 $.each(array, function (index, val) { 57 $(".product-one-click .product__param_" + wrap).append( 58 '<div class="product-param ' + 59 ($.inArray(val, available) == -1 && available.length > 0 60 ? "unavailable" 61 : "") + 62 ' " data-entity="param" data-type="' + 63 wrap + 64 '" data-val="' + 65 val + 66 '">' + 67 val + 68 "</div>" 69 ); 70 }); 71 $( 72 ".product-one-click [data-type=" + 73 wrap + 74 "][data-val=" + 75 this.selected[wrap] + 76 "]" 77 ).addClass("active"); 78 79 if ($(".product-one-click [data-type=" + wrap + "].active").length === 0) 80 this.selected[wrap] = false; 81 // } 82 } 83 84 loadParams(url, redraw_photo = false, selected = false) { 85 $.ajax({ 86 url: url, 87 type: "GET", 88 dataType: "json", 89 data: { ajax: "y" }, 90 }).done(function (data) { 91 $(".product-one-click .product__info .title").html(data.NAME); 92 93 Buy1Product.params = data; 94 Buy1Product.init(selected); 95 96 if (redraw_photo) { 97 Buy1Product.redrawPhoto(); 98 } 99 }); 100 } 101 102 redrawPhoto() { 103 $(".product-one-click .product__img").css( 104 "background-image", 105 "url(" + this.params.PHOTO[0].RESIZE + ")" 106 ); 107 } 108 109 changeFit(url) { 110 this.loadParams(url); 111 } 112 113 changeColor(url) { 114 this.loadParams(url, true); 115 } 116 117 changeParam(type, val) { 118 if (type == "size") { 119 120 this.selected.size = val; 121 122 var available = []; 123 var array = this.params.OFFERS.ROST; 124 $.each(this.params.OFFERS.TREE, function (size, item) { 125 if (size == val && Object.keys(item).length > 0) { 126 Object.keys(item).forEach((height) => { 127 available.push(height); 128 }); 129 } 130 }); 131 132 this.redrawParam("size", array, available); 133 } 134 135 if (type == "height") { 136 this.selected.height = val; 137 138 var array = this.params.OFFERS.RAZMER; 139 var available = []; 140 $.each(this.params.OFFERS.TREE, function (size, item) { 141 if (item[val]) { 142 available.push(size); 143 } 144 }); 145 this.redrawParam("height", array, available); 146 } 147 148 this.loadAvailable(); 149 } 150 151 order() { 152 var product_id = this.params.PRODUCT_ID; 153 var offer_id = false; 154 var costume = this.params.COSTUME ? 1 : 0; 155 156 157 158 if (this.validate()) { 159 return; 160 } 161 162 if (this.params.OFFERS != undefined) { 163 if (this.params.OFFERS.RAZMER && !this.selected.size) { 164 $(".product-one-click [data-type=size]")
165 .closest(".note") 166 .addClass("note_active"); 167 return; 168 } 169 170 if (this.params.OFFERS.ROST && !this.selected.height) { 171 $(".product-one-click [data-type=height]") 172 .closest(".note") 173 .addClass("note_active"); 174 return; 175 } 176 } 177 178 //доÑÑаем id оÑÑеÑа 179 // if ( 180 // this.selected.height != "false" && 181 // this.selected.height != "undefined" 182 // ) { 183 // var offer_id = 184 // this.params.OFFERS.TREE[this.selected.size][this.selected.height]; 185 // } else if ( 186 // this.selected.size != "false" && 187 // this.selected.size != "undefined" 188 // ) { 189 // offer_id = this.params.OFFERS.TREE[this.selected.size]; 190 // } else { 191 // offer_id = product_id; 192 // } 193 194 if (this.selected.height !== false && this.selected.height !== undefined) { 195 if (!this.params.OFFERS || !this.params.OFFERS.TREE) { 196 console.log("Ðоле TREE пÑÑÑое или не ÑÑÑеÑÑвÑеÑ"); 197 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 198 $(".one-click-order input").attr("disabled", "disabled"); 199 } else { 200 if ( 201 this.params.OFFERS.TREE[this.selected.size] && 202 this.params.OFFERS.TREE[this.selected.size][this.selected.height] 203 ) { 204 offer_id = 205 this.params.OFFERS.TREE[this.selected.size][this.selected.height]; 206 } else { 207 console.warn( 208 "Height not found in offers tree for the selected size." 209 ); 210 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 211 } 212 console.log("Ðоле TREE ÑодеÑÐ¶Ð¸Ñ Ð´Ð°Ð½Ð½Ñе:", this.params.OFFERS.TREE); 213 $(".one-click-order input").attr("disabled", "disabled"); 214 } 215 } else if ( 216 this.selected.size !== false && 217 this.selected.size !== undefined 218 ) { 219 if (this.params.OFFERS.TREE[this.selected.size]) { 220 offer_id = this.params.OFFERS.TREE[this.selected.size]; 221 } else { 222 console.warn("Size not found in offers tree."); 223 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 224 } 225 $(".one-click-order input").attr("disabled", "disabled"); 226 } else { 227 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 228 } 229 230 var name = $('.name').val(); 231 var phone = $('.phone').val(); 232 var email = $('.email').val(); 233 234 grecaptcha.ready(function () { 235 grecaptcha 236 .execute("6Ldr9e8pAAAAAJnG9c_g-eEDcdV3Aegdls5HnBFH", { 237 action: "one_click_buy", 238 }) 239 .then(function (token) { 240 var formData = $(".one-click-order").serializeArray(); 241 formData.push({ name: "offer_id", value: offer_id }); 242 formData.push({ name: "product_id", value: product_id }); 243 formData.push({ name: "costume", value: costume }); 244 formData.push({ name: "order", value: "Y" }); 245 formData.push({ name: "g-recaptcha-response", value: token }); 246 247 formData.push({ name: "name", value: name }); 248 formData.push({ name: "phone", value: phone }); 249 formData.push({ name: "email", value: email }); 250 251 252 console.log(formData); 253 $.ajax({ 254 url: "/local/components/madmen/buy1click/ajax.php", 255 type: "GET", 256 dataType: "json", 257 data: formData, 258 }).done(function (data) { 259 $(".one-click-order input").attr("disabled", false); 260 if (data.success) { 261 window.location.href = 262 "/personal/cart/?ORDER_ID=" + data.order_id; 263 } else { 264 modal.close(".m-buy-one-click"); 265 modal.open(".m-order-error"); 266 } 267 }); 268 }); 269 }); 270 } 271 272 validate() { 273 var error = false; 274 $(".product-one-click .one-click-order input.required").each(function ( 275 index, 276 el 277 ) { 278 if (!$(el).val().length) { 279 $(el).addClass("error"); 280 error = true; 281 } 282 }); 283 284 // ТелеÑон 285 // $(".product-one-click .one-click-order .phone.required").each(function ( 286 // index, 287 // el 288 // ) { 289 // const phone = document.getElementById("product_phone").value; 290 // console.log(phone.length); 291 292 // if (phone.length > 16) { 293 // $("#result").text("ТелеÑон коÑÑекÑен."); 294 // $(el).removeClass("error"); 295 // error = false;
296 // } else { 297 // $("#result").text( 298 // "ТелеÑон некоÑÑекÑен. Ðолжно бÑÑÑ Ð±Ð¾Ð»ÑÑе 9 Ñимволов." 299 // ); 300 // $(el).addClass("error"); 301 // error = true; 302 // } 303 // }); 304 305 // ÐÐ¼Ñ 306 $(".product-one-click .one-click-order .name").each(function ( 307 index, 308 el 309 ) { 310 const name = $('.name').val().trim(); 311 312 if (name.length > 3) { 313 console.log("ÐÐ¼Ñ ÐºÐ¾ÑÑекÑен."); 314 $(el).removeClass("error"); 315 error = false; 316 } else { 317 console.log("ÐÐ¼Ñ Ð½Ðµ коÑÑекÑен."); 318 $(el).addClass("error"); 319 error = true; 320 } 321 }); 322 323 $(".product-one-click .one-click-order select.required").each(function ( 324 index, 325 el 326 ) { 327 if (!$(el).val()) { 328 $(el).closest(".bootstrap-select.custom-select").addClass("error"); 329 error = true; 330 } 331 }); 332 333 return error; 334 } 335 336 loadAvailable() { 337 if (!$(".product-one-click .store-select").length) return; 338 var id = this.params.PRODUCT_ID; 339 340 //доÑÑаем id оÑÑеÑа 341 if (this.selected.height && this.selected.size && $('.product__param_height').length > 0 && $('.product__param_size').length > 0) { 342 var id = 343 this.params.OFFERS.TREE[this.selected.size][this.selected.height]; 344 345 BX.ajax 346 .runComponentAction("madmen:buy1click", "getStores", { 347 mode: "class", 348 data: { 349 offer_id: id, 350 }, 351 }) 352 .then(function (response) { 353 $("select.store-select").empty(); 354 $.each(response.data, function (index, elem) { 355 $(".product-one-click .store-select").removeClass('disabled'); 356 $("select.store-select").append( 357 new Option(elem.NAME, elem.PROPERTIES.ID_STORE.VALUE) 358 ); 359 }); 360 361 $("select.store-select").selectpicker("destroy"); 362 if (Buy1Product.selected.store) { 363 $("select.store-select").selectpicker( 364 "val", 365 Buy1Product.selected.store 366 ); 367 } 368 369 $("select.store-select").selectpicker("selectpicker"); 370 }); 371 } else if (this.selected.size && $('.product__param_size').length > 0 && $('.product__param_height').length == 0) { 372 id = this.params.OFFERS.TREE[this.selected.size]; 373 374 BX.ajax 375 .runComponentAction("madmen:buy1click", "getStores", { 376 mode: "class", 377 data: { 378 offer_id: id, 379 }, 380 }) 381 .then(function (response) { 382 $("select.store-select").empty(); 383 // console.log(response); 384 $.each(response.data, function (index, elem) { 385 $(".product-one-click .store-select").removeClass('disabled'); 386 $("select.store-select").append( 387 new Option(elem.NAME, elem.PROPERTIES.ID_STORE.VALUE) 388 ); 389 }); 390 391 $("select.store-select").selectpicker("destroy"); 392 if (Buy1Product.selected.store) { 393 $("select.store-select").selectpicker( 394 "val", 395 Buy1Product.selected.store 396 ); 397 } 398 399 $("select.store-select").selectpicker("selectpicker"); 400 }); 401 } else if ($('.product__param_height').length == 0 && $('.product__param_size').length == 0) { 402 BX.ajax 403 .runComponentAction("madmen:buy1click", "getStores", { 404 mode: "class", 405 data: { 406 offer_id: id, 407 }, 408 }) 409 .then(function (response) { 410 $("select.store-select").empty(); 411 // console.log(response); 412 $.each(response.data, function (index, elem) { 413 $(".product-one-click .store-select").removeClass('disabled'); 414 $("select.store-select").append( 415 new Option(elem.NAME, elem.PROPERTIES.ID_STORE.VALUE) 416 ); 417 }); 418 419 $("select.store-select").selectpicker("destroy"); 420 if (Buy1Product.selected.store) { 421 $("select.store-select").selectpicker( 422 "val", 423 Buy1Product.selected.store 424 ); 425 } 426 427 $("select.store-select").selectpicker("selectpicker"); 428 }); 429 } 430 } 431} 432 433class BuyClickElementPart { 434 constructor(params) { 435 this.params = params; 436 this.partStatus = true; 437 this.available_open = false;
438 439 this.selected = { 440 'BLAZER': { size: false, height: false }, 441 'PANTS': { size: false, height: false }, 442 'JACKET': { size: false, height: false } 443 }; 444 445 } 446 447 init(selected = null) { 448 // 1. пÑименÑем ÑÐ¾Ñ ÑанÑннÑй вÑÐ±Ð¾Ñ (еÑли еÑÑÑ) 449 if (selected) { 450 for (let part in selected) { 451 if (!this.selected[part]) continue; 452 453 this.selected[part] = { 454 size: selected[part].size ?? null, 455 height: selected[part].height ?? null 456 }; 457 } 458 } 459 460 461 // 2. пеÑвиÑÐ½Ð°Ñ Ð¾ÑÑиÑовка вÑÐµÑ Ð¿Ð°ÑамеÑÑов ÐÐÐ ÑилÑÑÑаÑии 462 if (!this.params?.OFFERS) return; 463 464 for (let part in this.params.OFFERS) { 465 const data = this.params.OFFERS[part]; 466 if (!data) continue; 467 468 // SIZE 469 if (Array.isArray(data.SIZES) && data.SIZES.length) { 470 this.redrawParamPart( 471 part, 472 'size', 473 data.SIZES 474 ); 475 } 476 477 // HEIGHT 478 if (Array.isArray(data.HEIGHTS) && data.HEIGHTS.length) { 479 this.redrawParamPart( 480 part, 481 'height', 482 data.HEIGHTS 483 ); 484 } 485 } 486 // 3. единÑй пеÑеÑÑÑÑ Ð´Ð¾ÑÑÑпноÑÑи поÑле init 487 this.recalcAllParts(); 488 489 // 4. еÑли еÑÑÑ Ð³Ð¾ÑовÑй оÑÑÐµÑ â гÑÑзим налиÑие 490 this.updateSelectedOffer(); 491 } 492 493 recalcAllParts() { 494 for (let part in this.params.OFFERS) { 495 this.redrawPart(part); 496 } 497 } 498 499 getAvailableValues(part, type) { 500 let values = new Set(); 501 502 for (let otherPart in this.params.OFFERS) { 503 const offers = this.getOffersBySelection(otherPart); 504 if (!offers.length) continue; 505 506 const tree = this.params.OFFERS[part].TREE; 507 508 for (let size in tree) { 509 if (type === 'size') { 510 const ids = this.flattenTree(tree[size]); 511 if (ids.some(id => offers.includes(id))) { 512 values.add(size); 513 } 514 } else {
515 if (typeof tree[size] === 'object') { 516 for (let h in tree[size]) { 517 const ids = tree[size][h]; 518 if (ids.some(id => offers.includes(id))) { 519 values.add(h); 520 } 521 } 522 } 523 } 524 } 525 } 526 527 return [...values]; 528 } 529 530 flattenTree(node) { 531 if (Array.isArray(node)) return node; 532 533 let ids = []; 534 for (let k in node) { 535 ids = ids.concat(node[k]); 536 } 537 return ids; 538 } 539 540 getAvailable(part, type) { 541 const result = new Set(); 542 543 for (let p in this.params.OFFERS) { 544 const offers = this.getOffersBySelection(p); 545 546 if (!offers.length) continue; 547 548 const tree = this.params.OFFERS[part].TREE; 549 550 for (let size in tree) { 551 const node = tree[size]; 552 553 if (type === 'size') { 554 const ids = this.flatten(node); 555 // console.log(node, ids) 556 if (ids.some(id => offers.includes(id))) { 557 result.add(size); 558 } 559 } else { 560 if (Array.isArray(node)) { 561 for (let h in node) { 562 if (offers.includes(h)) { 563 result.add(h); 564 } 565 } 566 } else { 567 for (let h in node) { 568 if (node[h].some(id => offers.includes(id))) { 569 result.add(h); 570 } 571 } 572 } 573 } 574 } 575 } 576 577 return [...result]; 578 } 579 580 flatten(node) { 581 if (Array.isArray(node)) return node; 582 return Object.values(node).flat(); 583 } 584 585 586 redrawPart(part) { 587 const data = this.params.OFFERS[part]; 588 if (!data) return; 589 590 const available = { 591 size: this.getAvailable(part, 'size'), 592 height: this.getAvailable(part, 'height') 593 }; 594 595 if (data.HEIGHTS) { 596 this.redrawParamPart(part, 'height', data.HEIGHTS, available.height); 597 } 598 599 if (data.SIZES) { 600 this.redrawParamPart(part, 'size', data.SIZES, available.size); 601 } 602 603 } 604 605 606 getOffersBySelection(part) { 607 const tree = this.params.OFFERS[part].TREE; 608 const sel = this.selected[part]; 609 610 if (!tree) return []; 611 612 if (sel.size == 'false') { 613 sel.size = JSON.parse(sel.size) 614 } 615 if (sel.height == 'false') { 616 sel.height = JSON.parse(sel.height) 617 } 618 619 // ÐÐ¸Ð»ÐµÑ / без ÑазмеÑов 620 if (tree[''] && !sel.size && !sel.height) { 621 return tree['']; 622 } 623 624 if (sel.size && sel.height) { 625 return tree?.[sel.size]?.[sel.height] || []; 626 } 627 628 if (sel.size) { 629 630 const node = tree[sel.size]; 631 632 if (Array.isArray(node)) return node; 633 634 let ids = []; 635 636 for (let h in node) { 637 ids = ids.concat(node[h]); 638 } 639 640 return ids; 641 } 642 643 return []; 644 } 645 646 647 redrawParamPart(part, type, values, available = []) { 648 // type: 'size' | 'height' 649 // values: ÑпиÑок знаÑений (SIZES или HEIGHTS) 650 // available: допÑÑÑимÑе знаÑÐµÐ½Ð¸Ñ (опÑионалÑно) 651 652 const $wrap = $( 653 `.params[data-part="${part}"][data-type="${type}"]` 654 ); 655 656 if (!$wrap.length) return; 657 658 $wrap.empty(); 659 660 values.forEach(val => { 661 const isUnavailable = 662 available.length > 0 && !available.includes(val.toString()); 663 664 const isActive = 665 this.selected?.[part]?.[type].toString() === val; 666 $wrap.append(` 667 <div class="product-param one_click-param 668 ${isActive ? 'active' : ''} 669 ${isUnavailable ? 'unavailable' : ''}" 670 data-part="${part}" 671 data-type="${type}" 672 data-val="${val}"> 673 ${val} 674 </div> 675 `); 676 }); 677 678 // еÑли акÑивнÑй ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑÑал недоÑÑÑпен â ÑбÑаÑÑваем 679 if ( 680 this.selected?.[part]?.[type] && 681 available.length && 682 !available.includes(this.selected[part][type].toString()) 683 ) { 684 this.selected[part][type] = null; 685 $wrap.find('.active').removeClass('active'); 686 } 687 } 688 689 690 loadParams(url, redraw_photo = false, selected = false) { 691 692 693 $.ajax({ 694 url: url, 695 type: "GET", 696 dataType: "json", 697 data: { ajax: "y" }, 698 }).done(function (data) { 699 700 $(".product-one-click .product__info .title").html(data.NAME); 701 702 Buy1Product.params = data; 703 Buy1Product.init(selected); 704 705 if (redraw_photo) { 706 Buy1Product.redrawPhoto(); 707 } 708 }); 709 } 710 711 redrawPhoto() { 712 $(".product-one-click .product__img").css( 713 "background-image", 714 "url(" + this.params.PHOTO[0].RESIZE + ")" 715 ); 716 } 717 718 changeFit(url) { 719 this.loadParams(url); 720 } 721 722 changeColor(url) { 723 this.loadParams(url, true); 724 } 725 726 changePartParam(part, type, value) { 727 728 this.selected[part][type] = value; 729 730 // поÑле вÑбоÑа â пеÑеÑÑиÑÑваем вÑе ÑаÑÑи 731 for (let p in this.params.OFFERS) { 732 this.redrawPart(p); 733 } 734 735 this.updateSelectedOffer(); 736 737 738 } 739 740 updateSelectedOffer() { 741 let intersect = null; 742 743 for (let part in this.params.OFFERS) { 744 const offers = this.getOffersBySelection(part); 745 if (!offers.length) continue; 746 747 intersect = intersect === null 748 ? offers 749 : intersect.filter(id => offers.includes(id)); 750 } 751 752 this.currentOfferId = intersect?.[0] || null; 753 754 this.loadAvailable(); 755 756 } 757 758 759 760 order() { 761 var product_id = this.params.PRODUCT_ID; 762 var offer_id = false;
763 var costume = this.params.COSTUME ? 1 : 0; 764 765 766 767 if (this.validate()) { 768 return; 769 } 770 771 if (this.params.OFFERS != undefined) { 772 if (this.params.OFFERS.RAZMER && !this.selected.size) { 773 $(".product-one-click [data-type=size]") 774 .closest(".note") 775 .addClass("note_active"); 776 return; 777 } 778 779 if (this.params.OFFERS.ROST && !this.selected.height) { 780 $(".product-one-click [data-type=height]") 781 .closest(".note") 782 .addClass("note_active"); 783 return; 784 } 785 } 786 787 788 //доÑÑаем id оÑÑеÑа 789 // if ( 790 // this.selected.height != "false" && 791 // this.selected.height != "undefined" 792 // ) { 793 // var offer_id = 794 // this.params.OFFERS.TREE[this.selected.size][this.selected.height]; 795 // } else if ( 796 // this.selected.size != "false" && 797 // this.selected.size != "undefined" 798 // ) { 799 // offer_id = this.params.OFFERS.TREE[this.selected.size]; 800 // } else { 801 // offer_id = product_id; 802 // } 803 804 if (this.selected.height !== false && this.selected.height !== undefined) { 805 if (!this.params.OFFERS || !this.params.OFFERS.TREE) { 806 console.log("Ðоле TREE пÑÑÑое или не ÑÑÑеÑÑвÑеÑ"); 807 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 808 $(".one-click-order input").attr("disabled", "disabled"); 809 } else { 810 if ( 811 this.params.OFFERS.TREE[this.selected.size] && 812 this.params.OFFERS.TREE[this.selected.size][this.selected.height] 813 ) { 814 offer_id = 815 this.params.OFFERS.TREE[this.selected.size][this.selected.height]; 816 } else { 817 console.warn( 818 "Height not found in offers tree for the selected size." 819 ); 820 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 821 } 822 console.log("Ðоле TREE ÑодеÑÐ¶Ð¸Ñ Ð´Ð°Ð½Ð½Ñе:", this.params.OFFERS.TREE); 823 $(".one-click-order input").attr("disabled", "disabled"); 824 } 825 } else if ( 826 this.selected.size !== false && 827 this.selected.size !== undefined 828 ) { 829 if (this.params.OFFERS.TREE[this.selected.size]) { 830 offer_id = this.params.OFFERS.TREE[this.selected.size]; 831 } else { 832 console.warn("Size not found in offers tree."); 833 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 834 } 835 $(".one-click-order input").attr("disabled", "disabled"); 836 } else { 837 offer_id = product_id; // УÑÑановка знаÑÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 838 } 839 840 if (Product && Product.getActiveOfferId()) { 841 offer_id = Product.getActiveOfferId() 842 } 843 844 var name = $('.name').val(); 845 var phone = $('.phone').val(); 846 var email = $('.email').val(); 847 848 grecaptcha.ready(function () { 849 grecaptcha 850 .execute("6Ldr9e8pAAAAAJnG9c_g-eEDcdV3Aegdls5HnBFH", { 851 action: "one_click_buy", 852 }) 853 .then(function (token) { 854 var formData = $(".one-click-order").serializeArray(); 855 formData.push({ name: "offer_id", value: offer_id }); 856 formData.push({ name: "product_id", value: product_id }); 857 formData.push({ name: "costume", value: costume }); 858 formData.push({ name: "order", value: "Y" }); 859 formData.push({ name: "g-recaptcha-response", value: token }); 860 861 formData.push({ name: "name", value: name }); 862 formData.push({ name: "phone", value: phone }); 863 formData.push({ name: "email", value: email }); 864 865 $.ajax({ 866 url: "/local/components/madmen/buy1click/ajax.php", 867 type: "GET", 868 dataType: "json", 869 data: formData, 870 }).done(function (data) { 871 872 $(".one-click-order input").attr("disabled", false); 873 if (data.success) { 874 window.location.href = 875 "/personal/cart/?ORDER_ID=" + data.order_id; 876 } else { 877 modal.close(".m-buy-one-click"); 878 modal.open(".m-order-error"); 879 } 880 }); 881 }); 882 }); 883 } 884 885 validate() { 886 var error = false;
887 $(".product-one-click .one-click-order input.required").each(function ( 888 index, 889 el 890 ) { 891 if (!$(el).val().length) { 892 $(el).addClass("error"); 893 error = true; 894 } 895 }); 896 897 // ТелеÑон 898 // $(".product-one-click .one-click-order .phone.required").each(function ( 899 // index, 900 // el 901 // ) { 902 // const phone = document.getElementById("product_phone").value; 903 // console.log(phone.length); 904 905 // if (phone.length > 16) { 906 // $("#result").text("ТелеÑон коÑÑекÑен."); 907 // $(el).removeClass("error"); 908 // error = false; 909 // } else { 910 // $("#result").text( 911 // "ТелеÑон некоÑÑекÑен. Ðолжно бÑÑÑ Ð±Ð¾Ð»ÑÑе 9 Ñимволов." 912 // ); 913 // $(el).addClass("error"); 914 // error = true; 915 // } 916 // }); 917 918 // ÐÐ¼Ñ 919 $(".product-one-click .one-click-order .name").each(function ( 920 index, 921 el 922 ) { 923 const name = $('.name').val().trim(); 924 925 if (name.length > 3) { 926 console.log("ÐÐ¼Ñ ÐºÐ¾ÑÑекÑен."); 927 $(el).removeClass("error"); 928 error = false; 929 } else { 930 console.log("ÐÐ¼Ñ Ð½Ðµ коÑÑекÑен."); 931 $(el).addClass("error"); 932 error = true; 933 } 934 }); 935 936 $(".product-one-click .one-click-order select.required").each(function ( 937 index, 938 el 939 ) { 940 if (!$(el).val()) { 941 $(el).closest(".bootstrap-select.custom-select").addClass("error"); 942 error = true; 943 } 944 }); 945 946 return error; 947 } 948 949 loadAvailable() { 950 if (!this.available_open) return; 951 if (!this.currentOfferId) return; 952 953 $.ajax({ 954 url: '/local/ajax/available_stores.php', 955 type: 'GET', 956 data: { ajax: 'y', id: this.currentOfferId } 957 }).done(data => { 958 $('[data-entity=available_store] .info__body').html(data); 959 }); 960 } 961} 962 963$(document).ready(function () { 964 $("body").on("click", ".product-one-click [data-entity=color]", function () { 965 var url = $(this).attr("data-url"); 966 967 $(this).addClass("active").siblings().removeClass("active"); 968 Buy1Product.changeColor(url); 969 }); 970 971 $("body").on("click", ".product-one-click [data-entity=fit]", function () { 972 var url = $(this).attr("data-url"); 973 974 $(this).addClass("active").siblings().removeClass("active"); 975 Buy1Product.changeFit(url); 976 }); 977 978 $("body").on("change", ".product-one-click [data-entity=fit]", function () { 979 var url = $(this).val(); 980 Buy1Product.changeFit(url); 981 }); 982 983 $("body").on( 984 "click", 985 ".product-one-click [data-entity=param]:not(.unavailable)", 986 function () { 987 var value = $(this).attr("data-val"); 988 var type = $(this).attr("data-type"); 989 990 $(this).addClass("active").siblings().removeClass("active"); 991 $("[data-type=" + type + "]")
992 .closest(".note") 993 .removeClass("note_active"); 994 995 if ($(this).hasClass("unavailable")) { 996 $(this).removeClass("unavailable"); 997 switch (type) { 998 case "size": 999 type = "height"; 1000 break; 1001 1002 case "height": 1003 type = "size"; 1004 break; 1005 } 1006 Buy1Product.selected[type] = false; 1007 $(".product-one-click [data-type=" + type + "]").removeClass("active"); 1008 } 1009 Buy1Product.changeParam(type, value); 1010 1011 } 1012 ); 1013 1014 1015 $("body").on("submit", ".product-one-click .one-click-order", function (e) { 1016 e.preventDefault(); 1017 1018 Buy1Product.order(); 1019 }); 1020 1021 // $("body").on("keyup", "input", function () { 1022 // if ($(this).val()) $(this).removeClass("error"); 1023 // }); 1024 1025 $("body").on("change", "select", function () { 1026 if ($(this).val()) 1027 $(this).closest(".bootstrap-select.custom-select").removeClass("error"); 1028 }); 1029});
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.