From e16822912cf191a7f8fdab1cbfcbaead2a48d492 Mon Sep 17 00:00:00 2001 From: Gustavo Luigi <=> Date: Wed, 7 Sep 2022 14:50:07 +0200 Subject: [PATCH] . --- assets/js/checkout.js | 119 ++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/assets/js/checkout.js b/assets/js/checkout.js index cf283e9..ecc7223 100644 --- a/assets/js/checkout.js +++ b/assets/js/checkout.js @@ -10,7 +10,67 @@ function getAddressFiedlValue(addressComponents, $field){ let field = addressComponents.find(obj => obj.types.indexOf($field) > -1); return field != undefined?field.long_name:''; } -function initialize() { + +let input = document.querySelector("#ctelefon"); +if(input != undefined){ + let iti = window.intlTelInput(input, { + initialCountry: "de", + preferredCountries: ["de"], + geoIpLookup: function(callback) { + $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) { + let countryCode = (resp && resp.country)?resp.country:"us"; + callback(countryCode); + }); + }, + utilsScript: "/template/assets/libs/intl-tel-input/js/utils.min.js", + }); +} +function updateProducts(){ + $('#list-products').html(''); + if(objProducts.length > 0){ + getInfoFromSelectedProduct().done(function(response, status){ + response.contents.forEach(function(product){ + let objProduct = getProductInfo(product); + let elementProduct = createProductElement(objProduct); + $('#list-products').append(elementProduct); + }); + $('#total-checkout-price').text(numberToEuroFormat(totalPrice)); + }); + $('#form-section').show(); + $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show(); + $('#total-checkout-price').parent().parent().parent().show(); + $('#no-products-in-checkout').hide(); + }else{ + $('#form-section').hide(); + $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide(); + $('#total-checkout-price').parent().parent().parent().hide(); + $('#no-products-in-checkout').show(); + } +} + +// iti.getNumber(); + +$(window).on('load', function(){ + updateProducts(); + $("#successful-submitting-form").delay(4000).slideUp(200, function() { $(this).alert('close'); }); + $('#anfrage').submit(function(){ + objProducts = []; + localStorage.setItem("products", JSON.stringify(objProducts)); + }); + $(document).on('input', '.select-quantity', function(){ + getInfoFromSelectedProduct().done(function(response, status){ + totalPrice = 0; + response.contents.forEach(function(product){ + let objProduct = getProductInfo(product); + objProduct = calculatePrice(objProduct); + totalPrice += objProduct.calc_preis*objProduct.quantity; + }); + $('#total-checkout-price').text(numberToEuroFormat(totalPrice)); + }); + }); +}); + +$(window).on('load', google.maps.event, function(){ let input = document.getElementById('field_location'); let options = { types: ['address'], @@ -56,61 +116,4 @@ function initialize() { } }); }); -} -$(window).on('load', google.maps.event, initialize); -let input = document.querySelector("#ctelefon"); -if(input != undefined){ - let iti = window.intlTelInput(input, { - initialCountry: "de", - preferredCountries: ["de"], - geoIpLookup: function(callback) { - $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) { - let countryCode = (resp && resp.country)?resp.country:"us"; - callback(countryCode); - }); - }, - utilsScript: "/template/assets/libs/intl-tel-input/js/utils.min.js", - }); -} -// iti.getNumber(); -function updateProducts(){ - $('#list-products').html(''); - if(objProducts.length > 0){ - getInfoFromSelectedProduct().done(function(response, status){ - response.contents.forEach(function(product){ - let objProduct = getProductInfo(product); - let elementProduct = createProductElement(objProduct); - $('#list-products').append(elementProduct); - }); - $('#total-checkout-price').text(numberToEuroFormat(totalPrice)); - }); - $('#form-section').show(); - $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show(); - $('#total-checkout-price').parent().parent().parent().show(); - $('#no-products-in-checkout').hide(); - }else{ - $('#form-section').hide(); - $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide(); - $('#total-checkout-price').parent().parent().parent().hide(); - $('#no-products-in-checkout').show(); - } -} -$(window).on('load', function(){ - updateProducts(); - $("#successful-submitting-form").delay(4000).slideUp(200, function() { $(this).alert('close'); }); - $('#anfrage').submit(function(){ - objProducts = []; - localStorage.setItem("products", JSON.stringify(objProducts)); - }); - $(document).on('input', '.select-quantity', function(){ - getInfoFromSelectedProduct().done(function(response, status){ - totalPrice = 0; - response.contents.forEach(function(product){ - let objProduct = getProductInfo(product); - objProduct = calculatePrice(objProduct); - totalPrice += objProduct.calc_preis*objProduct.quantity; - }); - $('#total-checkout-price').text(numberToEuroFormat(totalPrice)); - }); - }); }); \ No newline at end of file