1$(document).ready(function() { 2 $("input[name$='refresh']").remove(); 3 var url = window.location + ''; 4 5 // if we have anchors in URL, we reload the page with the proper combinaison 6 window.addEventListener("load", function(event) { 7 if (url.indexOf('#/') != -1) { 8 // get the params to fill from a "normal" url 9 id_product = $('input[name=id_product]').val(); 10 qty = $('input[name=qty]').val(); 11 params = url.substring(url.indexOf('#') + 1, url.length); 12 tabParams = params.split('/'); 13 tabValues = []; 14 if (tabParams[0] == '') 15 tabParams.shift(); 16 17 var len = tabParams.length; 18 for (var i=0; i<len; i++) 19 { 20 tabParams[i] = tabParams[i].replace('-', '-'); 21 tabValues.push(tabParams[i].split('-')); 22 } 23 24 var query = $(event.target.form).serialize() + 'qty='+qty+'&id_product='+id_product+'&ajax=1&action=productrefresh&attributes='+tabValues; 25 var actionURL = seoperf_fo; 26 27 $.post(actionURL, query, null, 'json').then(function(resp) { 28 override_seoperf_ajax_calls(resp); 29 }); 30 } 31 }); 32 33 $('body').on('click', '.quick-view', function(event){ 34 setTimeout( 35 function(){ 36 $("input[name$='refresh']").remove(); 37 }, 38 1000); 39 }) 40 41 $('body').on('change', '.product-variants [data-product-attribute]', function (event, extraParameters) { 42 $("input[name$='refresh']").remove(); 43 var $productRefresh = $(this); 44 45 let eventType = 'updatedProductCombination'; 46 if (typeof extraParameters !== 'undefined' && extraParameters.eventType) { 47 eventType = extraParameters.eventType; 48 } 49 50 var query = $(event.target.form).serialize() + '&ajax=1&action=productrefresh'; 51 var actionURL = seoperf_fo; 52 53 $.post(actionURL, query, null, 'json').then(function(resp) { 54 override_seoperf_ajax_calls(resp); 55 }); 56 }); 57}); 58 59function override_seoperf_ajax_calls(resp) { 60 61 if (typeof resp.refreshUrl == "undefined") { 62 resp.refreshUrl = true; 63 } 64 65 var eventType = resp.eventType; 66 67 let replaceAddToCartSections = ((addCartHtml) => { 68 let $addToCartSnippet = $(addCartHtml); 69 let $addProductToCart = $('.product-add-to-cart'); 70 71 function replaceAddToCartSection(replacement) { 72 let replace = replacement.$addToCartSnippet.find(replacement.targetSelector); 73 74 if ($(replacement.$targetParent.find(replacement.targetSelector)).length > 0) { 75 if (replace.length > 0) { 76 $(replacement.$targetParent.find(replacement.targetSelector)).replaceWith(replace[0].outerHTML); 77 } else { 78 $(replacement.$targetParent.find(replacement.targetSelector)).html(''); 79 } 80 } 81 } 82 83 const productAvailabilitySelector = '.add'; 84 replaceAddToCartSection({ 85 $addToCartSnippet: $addToCartSnippet, 86 $targetParent: $addProductToCart, 87 targetSelector: productAvailabilitySelector 88 }); 89 90 const productAvailabilityMessageSelector = '#product-availability'; 91 replaceAddToCartSection({ 92 $addToCartSnippet: $addToCartSnippet, 93 $targetParent: $addProductToCart, 94 targetSelector: productAvailabilityMessageSelector 95 }); 96 97 const productMinimalQuantitySelector = '.product-minimal-quantity'; 98 replaceAddToCartSection({ 99 $addToCartSnippet: $addToCartSnippet, 100 $targetParent: $addProductToCart, 101 targetSelector: productMinimalQuantitySelector 102 }); 103 }); 104 105 $.post(resp.productUrl, {ajax: '1', action: 'refresh', id_product_attribute: resp.id_product_attribute}, null, 'json').then(function(resp) { 106 $('.product-prices').replaceWith(resp.product_prices); 107 $('.product-customization').replaceWith(resp.product_customization); 108 $('.product-variants').replaceWith(resp.product_variants); 109 $('.product-discounts').replaceWith(resp.product_discounts); 110 $('.images-container').replaceWith(resp.product_cover_thumbnails); 111 $('.product-additional-info').replaceWith(resp.product_additional_info); 112 $('#product-details').replaceWith(resp.product_details); 113 114 // Replace all "add to cart" sections but the quantity input in order to keep quantity field intact i.e. 115 // Prevent quantity input from blinking with classic theme. 116 let $productAddToCart; 117 $(resp.product_add_to_cart).each(function(index, value) { 118 if ($(value).hasClass('product-add-to-cart')) { 119 $productAddToCart = $(value); 120 } 121 }); 122 replaceAddToCartSections($productAddToCart); 123 124 const minimalProductQuantity = parseInt(resp.product_minimal_quantity, 10); 125 const quantityInputSelector = '#quantity_wanted'; 126 let quantityInput = $(quantityInputSelector); 127 const quantity_wanted = quantityInput.val(); 128 129 if (!isNaN(minimalProductQuantity) && quantity_wanted < minimalProductQuantity && eventType !== 'updatedProductQuantity') { 130 quantityInput.attr('min', minimalProductQuantity); 131 quantityInput.val(minimalProductQuantity); 132 } 133 134 if (resp.product_url && !$('.quickview').is(':visible')) { 135 window.history.pushState({id_product_attribute: resp.id_product_attribute}, undefined, resp.product_url); 136 } 137 138 prestashop.emit('updatedProduct', resp); 139 140 }); 141 142};
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.