From: Anthony Talarico Date: Mon, 24 Apr 2017 18:06:19 +0000 (-0400) Subject: adding poster form calculations X-Git-Tag: v1.0.11^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=556d6bc421787a35f49045ee59b5497762ed1d95;p=WP-Themes%2Fmackinacbridge.git adding poster form calculations the poster form has 4 new additions of posters. had to remove the option to buy all 4 posters for a set price since there are now 8 posters. had to create calculations to allow a mix and match pricing system. --- diff --git a/js/app.js b/js/app.js index 8ea7077..9a0768b 100644 --- a/js/app.js +++ b/js/app.js @@ -56,6 +56,65 @@ $(document).ready(function () { pdf_form.insertAfter(".gform_confirmation_message"); pdf_form.css("display", "block"); + var poster_form = page.find("#gform_2"); + var poster_input = poster_form.find('.ginput_quantity'); + var prod_values = []; + var price_total; + var poster_array = [3,19,6,7,16,18,17,5]; + var quantity = 0; + + // poster form calculations ////////////////////////////////// + function calculate_poster(){ + price_total = 0; + var qty_total = 0; + for(var i = 3; i < 20; i++){ + if( $.inArray(i, poster_array ) !== -1 ){ + if( $('#ginput_quantity_2_' + i).val() !== undefined && $('#ginput_quantity_2_' + i).val() !== '' ){ + qty_total += parseInt($('#ginput_quantity_2_' + i).val(), 10); + } + } + } + + if(qty_total > 4){ + price_total = (qty_total - 4) * 10 + 30; + } else if( qty_total === 4){ + price_total = 30; + } else if( qty_total < 4){ + price_total = qty_total * 10; + } + + $('.ginput_total_2').text('$' + price_total + '.00'); + $('#input_2_15').val(price_total); + } + + $(window).on("load", function(){ + calculate_poster(); + }); + + poster_input.each(function(index){ + if( $(this).val() !== '') { + quantity += parseInt($(this).val()); + } + $(document).on("change",$(this),calculate_poster); + if( $(this).val() ){ + prod_values.push($(this)); + } + }); + + if(quantity >= 4){ + $.each(prod_values.slice(0,1), function(){ + if( $(this).val() === '1'){ + $(this).prev().prev().val('0'); + } else { + var price_calc = parseInt( $(this).val() ) * 10 - 10; + var new_price = ( price_calc / parseInt( $(this).val() ) ); + $(this).prev().prev().val( new_price ); + } + }); + } + //end poster form calculations /////////////////////////////////// + + // token order form $(document).on("change, keyup", "#ginput_quantity_4_36", function(){ if( $(this).val() > 0){ @@ -73,7 +132,6 @@ $(document).ready(function () { for(var i = 12; i < 36; i++){ if( $.inArray(i, field_array ) == -1 ){ if( $('#ginput_quantity_4_' + i).val() !== undefined && $('#ginput_quantity_4_' + i).val() !== '' ){ - console.log($('#ginput_quantity_4_' + i).val()); qty_total += parseInt($('#ginput_quantity_4_' + i).val(), 10); } } diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index da096b6..bdc89ec 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -47,6 +47,65 @@ $(document).ready(function () { pdf_form.insertAfter(".gform_confirmation_message"); pdf_form.css("display", "block"); + var poster_form = page.find("#gform_2"); + var poster_input = poster_form.find('.ginput_quantity'); + var prod_values = []; + var price_total; + var poster_array = [3,19,6,7,16,18,17,5]; + var quantity = 0; + + // poster form calculations ////////////////////////////////// + function calculate_poster(){ + price_total = 0; + var qty_total = 0; + for(var i = 3; i < 20; i++){ + if( $.inArray(i, poster_array ) !== -1 ){ + if( $('#ginput_quantity_2_' + i).val() !== undefined && $('#ginput_quantity_2_' + i).val() !== '' ){ + qty_total += parseInt($('#ginput_quantity_2_' + i).val(), 10); + } + } + } + + if(qty_total > 4){ + price_total = (qty_total - 4) * 10 + 30; + } else if( qty_total === 4){ + price_total = 30; + } else if( qty_total < 4){ + price_total = qty_total * 10; + } + + $('.ginput_total_2').text('$' + price_total + '.00'); + $('#input_2_15').val(price_total); + } + + $(window).on("load", function(){ + calculate_poster(); + }); + + poster_input.each(function(index){ + if( $(this).val() !== '') { + quantity += parseInt($(this).val()); + } + $(document).on("change",$(this),calculate_poster); + if( $(this).val() ){ + prod_values.push($(this)); + } + }); + + if(quantity >= 4){ + $.each(prod_values.slice(0,1), function(){ + if( $(this).val() === '1'){ + $(this).prev().prev().val('0'); + } else { + var price_calc = parseInt( $(this).val() ) * 10 - 10; + var new_price = ( price_calc / parseInt( $(this).val() ) ); + $(this).prev().prev().val( new_price ); + } + }); + } + //end poster form calculations /////////////////////////////////// + + // token order form $(document).on("change, keyup", "#ginput_quantity_4_36", function(){ if( $(this).val() > 0){ @@ -64,7 +123,6 @@ $(document).ready(function () { for(var i = 12; i < 36; i++){ if( $.inArray(i, field_array ) == -1 ){ if( $('#ginput_quantity_4_' + i).val() !== undefined && $('#ginput_quantity_4_' + i).val() !== '' ){ - console.log($('#ginput_quantity_4_' + i).val()); qty_total += parseInt($('#ginput_quantity_4_' + i).val(), 10); } }