1export function quote_change_recalculate_prices_listener($, price_input, quantity_input, subtotal_row, subtotal_quote, product_row) { 2 $(document).on('change', price_input + ', ' + quantity_input, function() { 3 const row = $(this).closest('tr'); 4 recalculate_quote_prices($, row, price_input, quantity_input, subtotal_row, subtotal_quote, product_row); 5 }); 6 7} 8 9export function cart_data_ajax_import($, textarea, action_button, errorbox, action, nonce) { 10 action_button.on('click', function(e) { 11 e.preventDefault(); 12 const textareaValue = textarea.val(); 13 errorbox.empty().hide(); 14 15 if(textareaValue.length < 1) { 16 errorbox.html('Field above can not be empty.').show(); 17 return; 18 } 19 20 $.ajax({ 21 url: ajaxurl, 22 type: 'POST', 23 data: { 24 'action': action, 25 'import_data': textareaValue, 26 'datatype': 'copypaste', 27 'nonce': nonce 28 }, 29 beforeSend: function() { 30 action_button.addClass('loading'); 31 }, 32 success: function(response) { 33 if (response.success) { 34 location.reload(); 35 } else { 36 errorbox.html('Error: ' + response.data.message).fadeIn(250); 37 action_button.removeClass('loading'); 38 } 39 }, 40 error: function(xhr, status, error) { 41 $('#cart_import_status').html('An error occurred: ' + error).show(); 42 action_button.removeClass('loading'); 43 } 44 }); 45 }); 46} 47 48function recalculate_quote_prices($, row, price_input, quantity_input, subtotal_row, subtotal_quote, product_row) { 49 recalculate_quote_row($, row, price_input, quantity_input, subtotal_row); 50 recalculate_quote_totals($, row, price_input, quantity_input, subtotal_row, subtotal_quote, product_row); 51} 52 53function recalculate_quote_row($, row, price_input, quantity_input, subtotal_row) { 54 const requested_price = $(price_input.split(' ')[1], row).val(); 55 const requested_qty = $(quantity_input.split(' ')[1], row).val(); 56 const price_per_qty = $(price_input.split(' ')[1], row).attr('data-price-qty'); 57 const requested_subtotal = parseFloat((requested_price * requested_qty) / price_per_qty).toFixed(2); 58 const subtotal_html = 59 '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>' + 60 requested_subtotal + 61 '</span>'; 62 63 $(subtotal_row, row).html(subtotal_html); 64} 65 66function recalculate_quote_totals($, row, price_input, quantity_input, subtotal_row, subtotal_quote, product_row) { 67 let subtotal = 0; 68 $(row).parent().find(product_row).each(function (k, v) { 69 const row_price = parseFloat($(subtotal_row, v).html().replace(',', '').match(/-?(?:\d+(?:\.\d*)?|\.\d+)/)[0]); 70 subtotal += row_price; 71 }); 72 73 const requested_total = 74 '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>' + 75 parseFloat(subtotal).toFixed(2) + 76 '</span>'; 77 78 $(subtotal_quote).html(requested_total); 79}
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.