1/*quitado para que el modal de funcione*/ 2//prestashop.blockcart.showModal = null; 3if(typeof baseDir==="undefined" && typeof prestashop!=="undefined") 4 baseDir = prestashop.urls.base_url; 5 6var arrayMPDProduct = new Array(); 7var dataCutting = null; 8 9//check if exist div id mpd-table-combinations 10if($('#mpd-table-combinations').length){ 11 $("body").addClass('mpd-table-combinations-product') 12} 13 14function awTablelistProduct(){ 15 addMpdDatatable(); 16} 17function awTableListInputblur(el){ 18 var qty = parseInt($(el).val()); 19 var max = parseInt($(el).attr('max')); 20 var blurinput = $(el).attr('blurinput'); 21 if(max!=0 && qty>max) 22 { 23 $(el).addClass('mpd-input-error'); 24 }else 25 { 26 $(el).removeClass('mpd-input-error'); 27 } 28 if(blurinput){ 29 sendToCartLineMPD($(el).parents('tr:first')); 30 } 31} 32function awTableListEvents(){ 33 $('.mpd-plus-prod').unbind('click').on('click', function (e) { 34 mpd_changeInput(this,'plus'); 35 }) 36 $('.mpd-minus-prod').unbind('click').on('click', function (e) { 37 mpd_changeInput(this,'minus'); 38 }); 39 $('.mpd-add-to-cart-productlist').unbind('click').on('click', function (e) { 40 mpd_changeInput(this,'equal'); 41 }); 42} 43function mpd_changeInput(el,action){ 44 var currentObj = $(el).closest('.mpd_productlist'); 45 var currentQty = parseInt($(el).parent().find('.p-quantity').val()); 46 var addTotal = 0 47 if(action=='plus'){ 48 var max = parseInt($(currentObj).find('.mega-comb-qty-table').attr('max')); 49 currentQty+=1; 50 if(currentQty>max) 51 return; 52 addTotal+=1; 53 } else if(action=='minus'){ 54 if(currentQty>1){ 55 56 } else { 57 mpd_changebutton(currentObj, "button", 0); 58 } 59 60 currentQty-=1; 61 addTotal -= 1; 62 } else if(action=='equal'){ 63 currentQty = 1; 64 mpd_changebutton(currentObj, "number", 1); 65 addTotal+=1; 66 } 67 $(el).parent().find('.p-quantity').val(currentQty); 68 $(currentObj).find('.mega-comb-qty-table').val(currentQty).blur(); 69 if ($('.blockcart .cart-products-count').length){ 70 var currentqty = parseInt($('.blockcart .cart-products-count').text()); 71 currentqty = currentqty + addTotal; 72 $('.blockcart .cart-products-count').text(currentqty); 73 } 74} 75 76function mpd_changebutton(obj, type = "button", qty = 1){ 77 if (type == "number"){ 78 obj.find('.mpd-add-to-cart-productlist').addClass("hide"); 79 obj.find('.product-quantity').addClass("show"); 80 obj.find('.product-quantity').find('.p-quantity').val(qty); 81 } 82 else { 83 obj.find('.mpd-add-to-cart-productlist').removeClass("hide"); 84 obj.find('.product-quantity').removeClass("show"); 85 obj.find('.product-quantity').find('.p-quantity').val(qty); 86 } 87} 88 89$(document).ready(function(){ 90 $('#newRowTableMPD').click(function(){ 91 newTableRowMPD(); 92 }); 93 $('.deleteRowMPD').click(function(){ 94 deleteRowMPD(this); 95 }); 96 $('#sendTableMPD').click(function(){ 97 sendTableMPD(); 98 }); 99 100 101 102 103 $('#calculeCutTableMPD').click(function(){ 104 calculeCutTableMPD(); 105 }); 106 $('.mpd-input-measure').blur(function(){ 107 var row = $(this).parents('tr:first'); 108 showPriceMPD(row); 109 }); 110 $('.mpd-input-measure').bind('keyup mouseup',function(){ 111 var row = $(this).parents('tr:first'); 112 showPriceMPD(row); 113 }); 114 $('.mpd-attributes,.mpd-attributes-checkbox').change(function(){ 115 var row = $(this).parents('tr:first'); 116 showPriceMPD(row); 117 }); 118 119 $('.mpd-qty').blur(function(){ 120 var row = $(this).parents('tr:first'); 121 showPriceMPD(row); 122 }); 123 124 125 126 $('.mpd-product').change(function(){ 127 var id_product = parseInt($(this).val()); 128 if(id_product==0 || $(this).val()=='') 129 return; 130 var row = $(this).parents('tr:first'); 131 getMDRowConfig(id_product,row); 132 }); 133 if($('#mpd-table-combinations').length) 134 { 135 /*$('#sendCombinationsTableMPD').click(function(){ 136 sendCombinationsTableMPD(); 137 });*/ 138 addMpdDatatable(); 139 addToCartLines(); 140 } 141 else if($('#mpd-table-groups').length){ 142 $('#sendGroupTableMPD').click(function(){ 143 sendGroupTableMPD(); 144 }); 145 addToCartLines2(); 146 } 147 else if($('#mpd-table-accesories').length) 148 { 149 $('#mpd-table-accesories tr').each(function(){ 150 var id_product = $(this).find('.mega-comb-qty-table').data('product'); 151 getMDRowConfig(id_product,$(this)); 152 }); 153 $('#sendAccessoryTableMPD').click(function(){ 154 sendAccessoryTableMPD(); 155 }); 156 157 } 158 else 159 { 160 newTableRowMPD(); 161 } 162 // Hide Attributes 163 if(typeof mpdHideAttributes!='undefined' && mpdHideAttributes==1) 164 { 165 $('.product_attributes,.product-actions').hide(); 166 $('#add_to_cart').hide(); 167 } 168 if(typeof mpdHideAccessories!='undefined' && mpdHideAccessories==1) 169 { 170 $('.accessories-block').parent().hide(); 171 $('.product-accessories').hide(); 172 } 173 174 awTableListEvents(); 175 176 $('.awtp-qty').click(function(){ 177 var qty = $(this).data('qty');
178 if($(this).parent().find('.qtydisc_name:first').length){ 179 qty = $(this).parents('.qtydisc_name:first').find('#awtp-qty-steps').val(); 180 } 181 loadQtyWanted(qty); 182 }); 183 $('#awtp-qty-steps').change(function(){ 184 var qty = $(this).val(); 185 $(this).parents('.qtydisc_name:first').find('.awtp-qty').attr('checked','checked'); 186 loadQtyWanted(qty); 187 }); 188 $(document).on('click', '.awtp-measure-up', function(e){ 189 e.preventDefault(); 190 fieldName = $(this).data('field-qty'); 191 changeTableMeasureQuantity(fieldName,'up',0); 192 193 }); 194 // The button to decrement the product value 195 $(document).on('click', '.awtp-measure-down', function(e){ 196 e.preventDefault(); 197 fieldName = $(this).data('field-qty'); 198 changeTableMeasureQuantity(fieldName,'down',0); 199 }); 200 201 $(document).on('click', '.right_grelated .add-to-cart-productlist-more', function(e){ 202 e.preventDefault(); 203 $(this).closest('.item').find('.table-container').slideToggle(); 204 }); 205}); 206function loadQtyWanted(qty){ 207 $('#quantity_wanted').val(qty); 208 $('#quantity_wanted').change(); 209} 210function changeTableMeasureQuantity(fieldName,applyValue,defaultValue) 211{ 212 var minqty = parseFloat($('#'+fieldName).attr('min')); 213 var maxqty = parseFloat($('#'+fieldName).attr('max')); 214 var stepqty = parseFloat($('#'+fieldName).attr('step')); 215 if(minqty==0) 216 return; 217 qty = stepqty; 218 currentVal = parseFloat($('#'+fieldName).val()); 219 quantityAvailableT = 10000000; 220 var changeVal = 0 221 if(!isNaN(maxqty) && maxqty!=0) 222 quantityAvailableT = maxqty; 223 if (!isNaN(currentVal) && currentVal < quantityAvailableT){ 224 newval = currentVal; 225 if(applyValue=='up') 226 newval = currentVal + qty; 227 else if(applyValue=='down') 228 newval = currentVal - qty; 229 else{ 230 231 if(currentVal%qty!=0){ 232 newval = Math.ceil(currentVal/qty)*qty; 233 } 234 } 235 if(newval<minqty) 236 newval = minqty; 237 changeVal = newval; 238 $('#'+fieldName).val(newval).trigger('keyup'); 239 } 240 241 else{ 242 $('#'+fieldName).val(quantityAvailableT); 243 changeVal = quantityAvailableT; 244 } 245 246 247 $('#'+fieldName).change(); 248 var price = $('#'+fieldName).data('price'); 249 if($('#'+fieldName).parents('.mlpdiscountline:first').find('.awtp-qty-price')){ 250 251 price=price*changeVal; 252 price = parseFloat(price.toFixed(6)); 253 price = price.toFixed(2)+' '+prestashop.currency.sign; 254 $('#'+fieldName).parents('.mlpdiscountline:first').find('.awtp-qty-price').html(price); 255 } 256 if($('#'+fieldName).parents('.mlpdiscountline:first').find('.awtp-qty-baseprice')){ 257 var price = $('#'+fieldName).data('baseprice'); 258 price=price*changeVal; 259 price = parseFloat(price.toFixed(6)); 260 price = price.toFixed(2)+' '+prestashop.currency.sign; 261 $('#'+fieldName).parents('.mlpdiscountline:first').find('.awtp-qty-baseprice').html(price); 262 } 263 264} 265 266function addToCartLines() 267{ 268 if($('.mpd-addcart-line').length) 269 $('.mpd-addcart-line').each(function(){ 270 $(this).click(function(){ 271 sendToCartLineMPD($(this).parents('tr:first')); 272 }); 273 }); 274} 275function addToCartLines2() 276{ 277 if($('.mpd-addcart-line').length) 278 $('.mpd-addcart-line').each(function(){ 279 $(this).click(function(){ 280 sendToCartLineMPD($(this).parents('td:first')); 281 }); 282 }); 283} 284function addMpdDatatable() 285{ 286 var otable = $('.mpd-table-combinations').not('.dataTable').DataTable({ 287 "bJQueryUI": true, 288 "bPaginate": false, 289 "bLengthChange": false, 290 "bFilter": true, 291 "bSort": true, 292 "order": [], 293 "bInfo": false, 294 "bAutoWidth": false, 295 "oLanguage": { 296 "sLengthMenu": sLengthMenu, 297 "sZeroRecords": sZeroRecords, 298 "sInfo": sInfo, 299 "sInfoEmpty": sInfoEmpty, 300 "sInfoFiltered": sInfoFiltered, 301 "sSearch": sSearch 302 }, 303 initComplete: function () 304 { 305 if(typeof mpdShowFilters!='undefined' && mpdShowFilters==0) 306 return; 307 var api = this.api(); 308 309 // Apply the search 310 api.columns('.dt-filter-text').every(function () 311 { 312 var that = this; 313 314 $('input', this.footer()).on('keyup change', function () 315 { 316 if (that.search() !== this.value) 317 { 318 that 319 .search(this.value) 320 .draw(); 321 } 322 }); 323 }); 324 api.columns('.dt-filter-select').every(function () 325 { 326 var column = this; 327 var select = $('<br/><select><option value=""></option></select>') 328 .appendTo($(column.header())) 329 .on('change', function () 330 { 331 var val = $.fn.dataTable.util.escapeRegex( 332 $(this).val() 333 ); 334 column.search(val ? '^' + val + '$' : '', true, false).draw(); 335 }); 336 column.data().unique().sort().each(function (d, J) 337 { 338 var strValue = d.replace("<div class='Scrollable'>", ''); 339 strValue = strValue.replace("</div>", ''); 340 select.append('<option value="' + strValue + '">' + strValue + '</option>') 341 }); 342 }); 343 } 344 }); 345 346 var otable = $('.mpd-table-combinations2').not('.dataTable').DataTable({ 347 "bJQueryUI": true, 348 "bPaginate": false, 349 "bLengthChange": false, 350 "bFilter": true, 351 "bSort": true, 352 "order": [], 353 "bInfo": false, 354 "bAutoWidth": false, 355 "oLanguage": { 356 "sLengthMenu": sLengthMenu, 357 "sZeroRecords": sZeroRecords, 358 "sInfo": sInfo, 359 "sInfoEmpty": sInfoEmpty, 360 "sInfoFiltered": sInfoFiltered, 361 "sSearch": sSearch 362 }, 363 initComplete: function () 364 { 365 if(typeof mpdShowFilters!='undefined' && mpdShowFilters==0) 366 return; 367 var api = this.api(); 368 369 // Apply the search 370 api.columns('.dt-filter-text').every(function () 371 { 372 var that = this; 373 374 $('input', this.footer()).on('keyup change', function () 375 { 376 if (that.search() !== this.value) 377 { 378 that 379 .search(this.value) 380 .draw(); 381 } 382 }); 383 }); 384 api.columns('.dt-filter-select').every(function () 385 { 386 var column = this; 387 var select = $('<br/><select><option value=""></option></select>') 388 .appendTo($(column.header())) 389 .on('change', function () 390 { 391 var val = $.fn.dataTable.util.escapeRegex( 392 $(this).val() 393 ); 394 column.search(val ? '^' + val + '$' : '', true, false).draw(); 395 }); 396 column.data().unique().sort().each(function (d, J) 397 { 398 var strValue = d.replace("<div class='Scrollable'>", ''); 399 strValue = strValue.replace("</div>", ''); 400 select.append('<option value="' + strValue + '">' + strValue + '</option>') 401 }); 402 }); 403 } 404 }); 405 406 407} 408function sendAccessoryTableMPD() 409{ 410 411 var arraySend = new Array(); 412 413 $('#mpd-table-accesories .mega-comb-qty-table').each(function(){ 414 var input = $(this); 415 obj = checInputMPDValue(input); 416 if(obj) 417 arraySend.push(obj); 418 }); 419 if(arraySend.length==0) 420 return; 421 var ajaxData = { ajaxArray: JSON.stringify(arraySend) };
422 //send the ajax request to the server 423 $.ajax({ 424 type: 'POST', 425 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCart&batchsend=1', 426 async: false, 427 cache: false, 428 dataType : 'json', 429 data: ajaxData, 430 success: function(jsonData) 431 { 432 433 } 434 }); 435 window.location.href = 'index.php?controller=order'; 436} 437function sendGroupTableMPD() 438{ 439 440 var arraySend = new Array(); 441 442 $('#mpd-table-groups .mega-comb-qty-table').each(function(){ 443 var input = $(this); 444 obj = checInputMPDValue(input); 445 if(obj) 446 arraySend.push(obj); 447 }); 448 if(arraySend.length==0) 449 return; 450 var ajaxData = { ajaxArray: JSON.stringify(arraySend) }; 451 //send the ajax request to the server 452 $.ajax({ 453 type: 'POST', 454 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCart&batchsend=1', 455 async: false, 456 cache: false, 457 dataType : 'json', 458 data: ajaxData, 459 success: function(jsonData) 460 { 461 462 } 463 }); 464 window.location.href = 'index.php?controller=order'; 465} 466function checInputMPDValue(input) 467{ 468 var applycartqty = $(input).attr('cartqty'); 469 if($(input).val()=='') 470 $(input).val(0); 471 if($(input).val()!=0 || applycartqty) 472 { 473 var qty = parseInt($(input).val()); 474 var max = parseInt($(input).attr('max')); 475 var min = parseInt($(input).attr('min')); 476 if(max!=0 && qty>max) 477 { 478 $(input).addClass('mpd-input-error'); 479 return -2; 480 } 481 if(min>1 && qty<min) 482 { 483 $(input).addClass('mpd-input-error'); 484 return -2; 485 } 486 if(applycartqty){ 487 var cartqty = $(input).attr('data-cartqty'); 488 $(input).attr('data-cartqty',qty); 489 qty = qty-parseInt(cartqty); 490 if(qty==0) 491 return -3; 492 } 493 if(qty==0) 494 return -2; 495 var id_product = $(input).data('product'); 496 var ipa = $(input).data('combination'); 497 var obj = { 498 id_product: id_product, 499 ipa: ipa, 500 qty:qty 501 }; 502 return obj; 503 504 } 505 return -1; 506} 507 508function sendToCartLineMPD(row) 509{ 510 arraySend = new Array(); 511 var input = $(row).find('.mega-comb-qty-table'); 512 var cartqty = $(input).attr('cartqty'); 513 obj = checInputMPDValue(input); 514 if(obj==-3 || obj==-2 || obj==-1) 515 return; 516 517 arraySend.push(obj); 518 519 if(arraySend.length==0) 520 return; 521 522 var ajaxData = { ajaxArray: JSON.stringify(arraySend) }; 523 //send the ajax request to the server 524 $.ajax({ 525 type: 'POST', 526 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCart&batchsend=1', 527 async: false, 528 cache: false, 529 dataType : 'json', 530 data: ajaxData, 531 success: function(jsonData) 532 { 533 if(!cartqty) 534 $(row).find('.mpd-addcart-line').parent('td').find('img').remove(); 535 if(jsonData.error){ 536 $(row).find('.mpd_productlist').html(jsonData.error); 537 538 return; 539 } 540 if(jsonData.send) 541 { 542 //$(row).find('.mpd-addcart-line').hide(); 543 var url = $(row).find('.mpd-addcart-line').data('available'); 544 545 if(!cartqty) 546 $(row).find('.mpd-addcart-line').parent('td').find('button').append($('<img src="'+url+'">')); 547 548 if(typeof jsonData.id_product!="undefined"){ 549 prestashop.emit('updateCart', { 550 reason: { 551 idProduct: jsonData.id_product, 552 idProductAttribute: jsonData.id_product_attribute, 553 linkAction: 'add-to-cart', 554 555 }, 556 resp: jsonData 557 }); 558 559 } 560 561 } else 562 { 563 var url = $(row).find('.mpd-addcart-line').data('notavailable'); 564 $(row).find('.mpd-addcart-line').parent('td').find('button').append($('<img src="'+url+'">')); 565 } 566 } 567 }); 568 569} 570 571function sendCombinationsTableMPD(el) 572{ 573 var tableComb = $(el).parents('.mpd-table:first').find('.mpd-table-combinations'); 574 var arraySend = new Array(); 575 var sendProducts = true; 576 $('.mpd-input-error').removeClass('mpd-input-error'); 577 $(tableComb).find('tbody tr').each(function(){ 578 var input = $(this).find('.mega-comb-qty-table'); 579 if($(this).find('.mega-comb-qty-table').length){ 580 obj = checInputMPDValue(input); 581 if(obj==-2) 582 sendProducts = false; 583 else if(obj!=-1) 584 arraySend.push(obj); 585 } 586 }); 587 if(!sendProducts || arraySend.length==0) 588 return; 589 590 var ajaxData = { ajaxArray: JSON.stringify(arraySend) };
591 //send the ajax request to the server 592 $.ajax({ 593 type: 'POST', 594 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCart&batchsend=1', 595 async: false, 596 cache: false, 597 dataType : 'json', 598 data: ajaxData, 599 success: function(jsonData) 600 { 601 if(typeof mpdRedirectCheckout!='undefined' && mpdRedirectCheckout) 602 window.location.href = 'index.php?controller=cart&action=show'; 603 else{ 604 prestashop.emit('updateCart', { 605 reason: { 606 idProduct: jsonData.id_product, 607 idProductAttribute: jsonData.id_product_attribute, 608 linkAction: 'add-to-cart', 609 /* cart: jsonData.cart*/ 610 }, 611 resp: jsonData 612 }); 613 } 614 615 616 } 617 }); 618 619 620} 621function getMDRowConfig(id_product,row) 622{ 623 if(typeof arrayMPDProduct[id_product]!='undefined') 624 { 625 rowConfig(arrayMPDProduct[id_product],row); 626 return; 627 } 628 var attributes = ''; 629 var combinations = '&combinations=0'; 630 var images = '&images=0'; 631 var arrayAttr = new Array(); 632 $(row).find('.mpd-attributes').each(function(){ 633 arrayAttr.push($(this).attr('data-option')); 634 }); 635 if(arrayAttr.length) 636 attributes = '&attrIds='+arrayAttr.join('-'); 637 if($(row).find('.mpd-combinations').length) 638 combinations = '&combinations=1'; 639 if($(row).find('.mpd-image').length) 640 images = '&images=1'; 641 $.ajax({ 642 type: 'POST', 643 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax', 644 async: true, 645 cache: false, 646 dataType : "json", 647 data: 'action=getConfig&id_product='+id_product+attributes+combinations+images, 648 success: function(jsonData) 649 { 650 if(jsonData) 651 { 652 if(typeof arrayMPDProduct[id_product]=='undefined') 653 arrayMPDProduct[id_product] = jsonData; 654 rowConfig(jsonData,row); 655 656 } 657 } 658 }); 659} 660function instantMPDSearch(row) 661{ 662 var $input = $(row).find('.mpd-input-search'); 663 var $value = $(row).find('.mpd-product'); 664 665 $input.autocomplete(baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=getProducts&id_mpd='+$('#id_mpd').val(), 666 { 667 minChars: 3, 668 max: 10, 669 width: 500, 670 selectFirst: false, 671 scroll: false, 672 dataType: "json", 673 formatItem: function(data, i, max, value, term) { 674 return value; 675 }, 676 parse: function(data) { 677 var mytab = []; 678 for (var i = 0; i < data.length; i++) 679 mytab[mytab.length] = { data: data[i], value: data[i].cname + ' > ' + data[i].pname }; 680 return mytab; 681 }, 682 extraParams: { 683 ajaxSearch: 1, 684 id_lang: $('#mpd-search-lang').val() 685 } 686 }) 687 .result(function(event, data, formatted) { 688 $input.val(data.pname); 689 $value.val(data.cname); 690 getMDRowConfig(data.cname,row); 691 //document.location.href = data.product_link; 692 }); 693 694} 695function rowConfig(data,row) 696{ 697 // Width 698 var measures = ["width", "height", "long"]; 699 700 var config = data['config']; 701 var groups = data['groups']; 702 var combinations = data['combinations']; 703 var images = data['images']; 704 705 var typeproduct = config['type']; 706 for(var i=0;i<measures.length;i++) 707 { 708 var type = measures[i]; 709 if($(row).find('.mpd-'+type).length) 710 { 711 712 var input = $(row).find('.mpd-'+type); 713 $(input).show(); 714 if(config[type+'_min']!=0) 715 { 716 $(input).attr('min',config[type+'_min']); 717 } 718 if(config[type+'_max']!=0) 719 { 720 $(input).attr('max',config[type+'_max']); 721 } 722 if(config[type+'_text']!=0) 723 { 724 $(input).attr('placeholder',config[type+'_text']); 725 //$(input).attr('title',config[type+'_text']); 726 } 727 if(config[type+'_sections']!=0) 728 { 729 $(input).attr('step',config[type+'_sections']); 730 } 731 if(typeproduct=='M2') 732 { 733 if(type=='long') 734 { 735 $(input).hide(); 736 } 737 } 738 if(typeproduct=='D') 739 { 740 if(type=='width' || type=='height') 741 { 742 $(input).hide(); 743 } 744 } 745 } 746 } 747 /*$(row).find('.mpd-attributes').each(function(){ 748 var id_group = $(this).attr('data-option'); 749 var selectinput = $(this); 750 $(selectinput).hide(); 751 752 $(groups).each(function(index, item, key) 753 { 754 for(var id in item) 755 { 756 if(id==id_group) 757 { 758 $(selectinput).show(); 759 760 //$(selectinput).remove(); 761 $(selectinput).find('option').remove().end(); 762 var options = groups[id]['attributes']; 763 addSelectOptions(selectinput,options); 764 } 765 } 766 }); 767 });*/ 768 changeMpdRowImage(row,images,0); 769 if($(row).find('.mpd-combinations').length) 770 { 771 var selectcomb = $(row).find('.mpd-combinations'); 772 $(selectcomb).show(); 773 if(combinations.length==0) 774 $(selectcomb).hide(); 775 $(selectcomb).find('option').remove(); 776 777 addSelectCombinationsOptions($(selectcomb),combinations); 778 changeMpdRowQuantity(row,selectcomb); 779 $(selectcomb).unbind().change(function(){ 780 var id_image = $(this).find('option:selected').attr('data-image'); 781 changeMpdRowQuantity(row,selectcomb); 782 changeMpdRowImage(row,images,id_image); 783 }); 784 $('.mpd-combinations').change(function(){ 785 var row = $(this).parents('tr:first'); 786 showPriceMPD(row); 787 }); 788 789 } 790 791 792} 793function changeMpdRowImage(row,images,id_image) 794{ 795 if($(row).find('.mpd-image').length) 796 { 797 798 $(row).find('.mpd-image').show(); 799 var addimage = false;
800 for(var id in images) 801 { 802 if(id_image==0 && images[id]['cover']==1) 803 { 804 addimage = true; 805 $(row).find('.mpd-image').attr('src',images[id]['url']); 806 } 807 else if(id_image!=0 && id==id_image) 808 { 809 addimage = true; 810 $(row).find('.mpd-image').attr('src',images[id]['url']); 811 } 812 } 813 814 if(!addimage) 815 { 816 $(row).find('.mpd-image').attr('src',''); 817 $(row).find('.mpd-image').hide(); 818 } 819 } 820} 821function changeMpdRowQuantity(row,selectcomb) 822{ 823 if($(row).find('.mpd-qty').length) 824 { 825 var qty = $(selectcomb).find('option:selected').attr('data-qty'); 826 $(row).find('.mpd-qty').attr('max',qty); 827 if($(row).find('.mega-comb-qty-table').length) 828 $(row).find('.mega-comb-qty-table').attr('data-combination',$(selectcomb).val()); 829 } 830} 831function addSelectCombinationsOptions(el,options) 832{ 833 //options = jQuery.makeArray(options); 834 for(var id in options) 835 { 836 var value = options[id]['name']; 837 var quantity = options[id]['quantity']; 838 var id_image = options[id]['id_image']; 839 if(id_image==null) 840 id_image = 0; 841 if(options[id]['quantity']>0) 842 $(el).append("<option data-image='"+id_image+"' data-qty='"+options[id]['quantity']+"' value='"+id+"'>"+value+" ("+quantity+")</option>"); 843 } 844} 845function addSelectOptions(el,options) 846{ 847 //options = jQuery.makeArray(options); 848 for(var id in options) 849 { 850 if(typeof options[id]['name']!='undefined') 851 var value = options[id]['name']; 852 else 853 var value = options[id]; 854 $(el).append("<option value='"+id+"'>"+value+"</option>"); 855 } 856} 857function newTableRowMPD() 858{ 859 $('.mpdtable tbody>tr:first').clone(true).insertAfter('.mpdtable tbody>tr:last').show(); 860 861 var newRow = $('.mpdtable tbody>tr:last'); 862 863 if($(newRow).find('.mpd-product').length && $(newRow).find('.mpd-product').val()!=0) 864 { 865 var id_product = $(newRow).find('.mpd-product').val(); 866 getMDRowConfig(id_product,$(newRow)); 867 } 868 instantMPDSearch(newRow); 869 disableTableMegaFields(newRow); 870 871 872 //$(newRow).insertAfter('.mpdtable tbody>tr:last').show(); 873} 874function convertUrlMPToArray(url) 875{ 876 if(url=='') 877 return; 878 var arraySplit = url.split('&'); 879 var arrayReturn = new Array(); 880 for(var i=0;i<arraySplit.length;i++){ 881 var arrayData = arraySplit[i].split('='); 882 if(arrayData.length==2) 883 { 884 var urlkey= arrayData[0]; 885 var urlvalue= arrayData[1]; 886 arrayReturn[urlkey] = urlvalue; 887 } 888 889 } 890 return arrayReturn; 891 892} 893function getMPProductData(quantity) 894{ 895 var sendgroups=''; 896 897 var resultAttrs = listAttrIds(); 898 899 if(resultAttrs[0]==1) 900 { 901 showErrorAlert(resultAttrs[1]); 902 return false; 903 } 904 else 905 { 906 sendgroups +=resultAttrs[1]; 907 } 908 909 910 var resultProducts = listProductIds(quantity); 911 912 if(resultProducts[0]==1) 913 { 914 showErrorAlert(resultProducts[1]); 915 916 return false; 917 } 918 else 919 { 920 sendgroups +=resultProducts[1]; 921 } 922 var resultQuantities = listQuantityIds(); 923 if(resultQuantities[0]==1) 924 { 925 showErrorAlert(resultQuantities[1]); 926 927 return false; 928 } 929 else 930 { 931 sendgroups +=resultQuantities[1]; 932 } 933 //sendgroups += listCombinationIds(); 934 var resultPersonalization = listPersonalization(); 935 if(resultPersonalization[0]==1) 936 { 937 showErrorAlert(resultPersonalization[1]); 938 939 return false; 940 } 941 else 942 { 943 sendgroups +=resultPersonalization[1]; 944 } 945 return sendgroups; 946} 947function deleteRowMPD(el) 948{ 949 $(el).parents('tr:first').remove(); 950} 951function getDataRow(row,format) 952{ 953 var measures = ["width", "height", "long", "qty", "cut"]; 954 var data = ''; 955 var arrayData = new Array(); 956 var arrayObject = {}; 957 if($(row).find('.mpd-product').length) 958 { 959 var value = $(row).find('.mpd-product').val(); 960 if(value=='') 961 return; 962 arrayData['id_product'] = value; 963 arrayObject['id_product'] = value; 964 965 } 966 else 967 return ''; 968 for(var i=0;i<measures.length;i++) 969 { 970 var type = measures[i]; 971 if($(row).find('.mpd-'+type).length && $(row).find('.mpd-'+type).is(":visible")) 972 { 973 var value = $(row).find('.mpd-'+type).val(); 974 if(type=='qty' && value==0) 975 value=1; 976 arrayData[type] = value; 977 arrayObject[type] = value; 978 if(type=='qty' && value=='') 979 return ''; 980 } 981 } 982 var arrayIds = new Array(); 983 $(row).find('.mpd-attributes option:selected').each(function(){ 984 var id = parseInt($(this).val()); 985 if(!$(this).hasClass('hideTableMegaField') && $(this).parents('.hideTableMegaField').length==0) 986 arrayIds.push(id); 987 }); 988 $(row).find('.mpd-attributes-checkbox:checked').each(function(){ 989 var id = parseInt($(this).val()); 990 if(!$(this).hasClass('hideTableMegaField') && $(this).parents('.hideTableMegaField').length==0) 991 arrayIds.push(id); 992 }); 993 994
995 arrayData['attrIds'] = arrayIds; 996 arrayObject['attrIds'] = arrayIds; 997 998 if(format=='ids') 999 return arrayIds; 1000 1001 arrayData['ipa'] = arrayObject['ipa'] = 0; 1002 if($(row).find('.mpd-combinations').length) 1003 arrayData['ipa'] = arrayObject['ipa'] = $(row).find('.mpd-combinations').val(); 1004 1005 var mpdurl = '' 1006 /*if($('#megaproduct').length) 1007 { 1008 mpdurl = getMPProductData(arrayData['qty']); 1009 var arrayMP = convertUrlMPToArray(mpdurl); 1010 for (var k in arrayMP){ 1011 arrayData[k] = arrayMP[k]; 1012 arrayObject[k] = arrayMP[k]; 1013 1014 } 1015 }*/ 1016 1017 1018 if(format=='array') 1019 return arrayData; 1020 if(format=='object') 1021 return arrayObject; 1022 else if(format=='url') 1023 { 1024 for(var key in arrayData) 1025 { 1026 if(key=='attrIds' && arrayData[key].constructor === Array) 1027 arrayData[key] = arrayData[key].join("-"); 1028 data += '&'+key+'='+arrayData[key]; 1029 } 1030 if($('#megaproduct').length) 1031 data += mpdurl; 1032 return data; 1033 } 1034 return ''; 1035} 1036function showPriceMPD(row) 1037{ 1038 disableTableMegaFields(row); 1039 1040 if(!$(row).find('.mpd-price').length) 1041 return; 1042 1043 if(!$(row).find('.mpd-qty').length || $(row).find('.mpd-qty').val()=='') 1044 return; 1045 1046 1047 var idCombination = 0; 1048 1049 if($(row).find('.mpd-combinations').length && $(row).find('.mega-comb-qty-table').length){ 1050 idCombination = $(row).find('.mpd-combinations').val(); 1051 $(row).find('.mega-comb-qty-table').attr('data-combination',idCombination); 1052 } 1053 1054 1055 1056 var id_product = $(row).find('.mpd-product').val(); 1057 1058 var url = baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=showPrice'; 1059 if(typeof arrayMPDProduct[id_product]!='undefined' && arrayMPDProduct[id_product]['isMega']==true) 1060 url = baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxmegaproduct&type=showprice'; 1061 1062 var sendgroups = getDataRow(row,'url'); 1063 1064 if($('#mpdshowprice').length) 1065 sendgroups += '&mpdshowprice='+$('#mpdshowprice').val(); 1066 1067 $.ajax({ 1068 type: 'POST', 1069 url: url, 1070 async: false, 1071 cache: false, 1072 dataType : "json", 1073 data: sendgroups, 1074 success: function(jsonData,textStatus,jqXHR) 1075 { 1076 if(jsonData) 1077 { 1078 $(row).find('.mpd-price').html(jsonData['price']); 1079 $(row).find('.mpd-price-sum').html(jsonData['pricenumber']); 1080 } 1081 } 1082 }); 1083} 1084function toObject(arr) { 1085 var rv = {}; 1086 for (var i = 0; i < arr.length; ++i) 1087 rv[i] = arr[i]; 1088 return rv; 1089} 1090function sendTableMPD(tb) 1091{ 1092 var sendtable=''; 1093 var arraySend = new Array(); 1094 $('.mpdtable tbody > tr').each(function(el) 1095 { 1096 if($(this).is(":visible")) 1097 { 1098 //var p = $(this).find('.mpd-product'); 1099 if($(this).find('.mpd-product').length) 1100 { 1101 var sendgroups = getDataRow(this,'object'); 1102 arraySend.push(sendgroups); 1103 } 1104 } 1105 }); 1106 var ajaxData = { ajaxArray: JSON.stringify(arraySend) }; 1107 //send the ajax request to the server 1108 $.ajax({ 1109 type: 'POST', 1110 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCart&batchsend=1', 1111 async: false, 1112 cache: false, 1113 dataType : 'json', 1114 data: ajaxData, 1115 success: function(jsonData) 1116 { 1117 1118 } 1119 }); 1120 window.location.href = 'index.php?controller=cart&action=show'; 1121 1122} 1123function sendCutTableMPD() 1124{ 1125 var sendgroups = ''; 1126 if(typeof returnSendGroups!='') 1127 sendgroups = returnSendGroups(1); 1128 if(!sendgroups) 1129 return false; 1130 1131 $('#btnAddCuts').attr('disabled',true); 1132 var ajaxData = { ajaxArray: JSON.stringify(dataCutting) }; 1133 //send the ajax request to the server 1134 $.ajax({ 1135 type: 'POST', 1136 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=sendCutCart&batchsend=1'+sendgroups, 1137 async: false, 1138 cache: false, 1139 dataType : 'json', 1140 data: ajaxData, 1141 success: function(jsonData) 1142 { 1143 window.location.href = 'index.php?controller=order'; 1144 } 1145 }); 1146} 1147function getAttrCutMeasuresRules() 1148{ 1149 var measures = ''; 1150 var attrmeasures = $('#attrmeasures').val(); 1151 if(attrmeasures!=''){ 1152 var arrayIds = attrmeasures.split('-'); 1153 1154 for(var i=0;i<arrayIds.length;i++){ 1155 var id = arrayIds[i]; 1156 var hasDisabled = hasAttrIdDisabled(id); 1157 if(!hasDisabled){ 1158 if(measures!='') 1159 measures +='-'; 1160 measures +=id; 1161 } 1162 1163 } 1164 } 1165 return measures; 1166 1167} 1168function hasAttrIdDisabled(id){ 1169 if($('option[value='+id+']').length && $('option[value='+id+']').hasClass('hideMegaField')) 1170 return true; 1171 return false;
1172} 1173 1174 1175function calculeCutTableMPD() 1176{ 1177 var sendtable=''; 1178 var arraySend = new Array(); 1179 $('.mpdtable tbody > tr').each(function(el) 1180 { 1181 if($(this).is(":visible")) 1182 { 1183 var p = $(this).find('.mpd-product'); 1184 if($(this).find('.mpd-product').length) 1185 { 1186 var sendgroups = getDataRow(this,'object'); 1187 arraySend.push(sendgroups); 1188 } 1189 } 1190 }); 1191 var id_product = $('#product_page_product_id').val(); 1192 var ajaxData = { ajaxArray: JSON.stringify(arraySend) }; 1193 1194 var sendgroups = ''; 1195 if(typeof returnSendGroups!='') 1196 sendgroups = returnSendGroups(1); 1197 if(!sendgroups) 1198 return false; 1199 1200 sendgroups += '&allowmeasures='+ getAttrCutMeasuresRules(); 1201 1202 //send the ajax request to the server 1203 $.ajax({ 1204 type: 'POST', 1205 url: baseDir + 'index.php?fc=module&module=awtableproducts&controller=ajax&action=calculeCutProduct&id_product='+id_product+sendgroups, 1206 async: false, 1207 cache: false, 1208 dataType : 'json', 1209 data: ajaxData, 1210 success: function(json) 1211 { 1212 //if(json.error) 1213 $('#mpdresult').html(json.html); 1214 if(json.data!=null) 1215 dataCutting = json.data; 1216 $('#btnAddCuts').click(function(){ 1217 sendCutTableMPD(); 1218 }); 1219 } 1220 }); 1221} 1222function disableTableMegaFields(row) 1223{ 1224 if(typeof rulesArray=='undefined') 1225 return; 1226 1227 $(row).find('.hideTableMegaField').removeClass('hideTableMegaField'); 1228 1229 var width = $(row).find('.mpd-width').val(); 1230 var height = $(row).find('.mpd-height').val(); 1231 var long = $(row).find('.mpd-long').val(); 1232 var totalmeasure = _MP.getTotalMeasure(); 1233 var quantity = $(row).find('.mpd-qty').val(); 1234 var arrayIdGroups = new Array(); 1235 var arrayIdBoolGroups = new Array(); 1236 if(rulesArray.length>0) 1237 { 1238 for (var i=0; i<rulesArray.length; i++) 1239 { 1240 var selected_fields = new Array(); 1241 if(rulesArray[i]['selected_fields']!='') 1242 selected_fields = rulesArray[i]['selected_fields'].split("|"); 1243 1244 var disabled_fields = rulesArray[i]['disabled_fields'].split("|"); 1245 var applyRule = true; 1246 var type = parseInt(rulesArray[i]['rule']); 1247 var logical = rulesArray[i]['logical']; 1248 var groupId = parseInt(rulesArray[i]['groupId']); 1249 var message = rulesArray[i]['message']; 1250 var attrIds = getDataRow(row,'ids'); 1251 if(true) 1252 { 1253 var existAttr = false; 1254 for(var m=0; m<selected_fields.length; m++) 1255 { 1256 $arraySelect = selected_fields[m].split('-'); 1257 if(type==0 || type==3 || type==1) 1258 var selectedRule = false; 1259 else 1260 var selectedRule = true; 1261 if($arraySelect.length==2) 1262 { 1263 if($.inArray(parseInt($arraySelect[1]),attrIds)>=0) 1264 { 1265 existAttr = true 1266 if(type==0 || type==3) 1267 { 1268 selectedRule = true; 1269 } 1270 else 1271 selectedRule = false; 1272 } 1273 } 1274 if(logical=='and' && !selectedRule) 1275 applyRule = false; 1276 } 1277 if(!existAttr && type!=2) 1278 applyRule = false; 1279 if(selected_fields.length==0) 1280 applyRule = true; 1281 } 1282 1283 if(applyRule) 1284 { 1285 launchTableDisableFields(type,row, disabled_fields); 1286 } 1287 } 1288 if(arrayIdBoolGroups.length) 1289 { 1290 for(var m=0;m<arrayIdBoolGroups.length;m++) 1291 { 1292 if(arrayIdBoolGroups[m]) 1293 { 1294 var rulesGroupLaunch = arrayIdGroups[m]; 1295 for(var ja=0;ja<rulesGroupLaunch.length;ja++) 1296 { 1297 launchDisableFields(rulesGroupLaunch[ja]['type'],rulesGroupLaunch[ja]['megaGroups'], rulesGroupLaunch[ja]['disabled_fields'],message); 1298 } 1299 } 1300 } 1301 } 1302 } 1303 function launchTableDisableFields(type, row, disabled_fields) 1304 { 1305 for(var j=0; j<disabled_fields.length; j++) 1306 { 1307 $arrayDisabled = disabled_fields[j].split('-'); 1308 if($arrayDisabled.length==2) 1309 { 1310 1311 // If disable rule 1312 if($arrayDisabled[0]=='g') 1313 { 1314 $(row).find('.mpdGroup'+$arrayDisabled[1]).addClass('hideTableMegaField'); 1315 1316 } 1317 else if($arrayDisabled[0]=='a') 1318 { 1319 if($(row).find('.mpd-attributes option[value="'+$arrayDisabled[1]+'"]').length){ 1320 $(row).find('.mpd-attributes option[value="'+$arrayDisabled[1]+'"]').addClass('hideTableMegaField'); 1321 } 1322 else if($(row).find('.mptCheck'+$arrayDisabled[1]).length){ 1323 $(row).find('.mptCheck'+$arrayDisabled[1]).addClass('hideTableMegaField'); 1324 } 1325 } 1326 } 1327 } 1328 } 1329 1330 1331}
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.