Compare commits

...

2 Commits

Author SHA1 Message Date
Gustavo Luigi e83c43ab03 Merge remote-tracking branch 'refs/remotes/origin/master' 2022-09-08 12:14:29 +02:00
Gustavo Luigi acb1503e8d add try catch in load products 2022-09-08 12:13:43 +02:00
4 changed files with 41 additions and 6 deletions

View File

@ -35,16 +35,32 @@ function updateProducts(){
$('#list-products').append(elementProduct); $('#list-products').append(elementProduct);
}); });
$('#total-checkout-price').text(numberToEuroFormat(totalPrice)); $('#total-checkout-price').text(numberToEuroFormat(totalPrice));
}).fail(function(response){
$('#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').hide();
$('#cart-error-in-checkout').show();
}); });
$('#form-section').show(); $('#form-section').show();
$('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show(); $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show();
$('#total-checkout-price').parent().parent().parent().show(); $('#total-checkout-price').parent().parent().parent().show();
$('#no-products-in-checkout').hide(); $('#no-products-in-checkout').hide();
}else{ $('#cart-error-in-checkout').hide();
}
else if(totalPrice > 0){
$('#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').hide();
$('#cart-error-in-checkout').show();
}
else{
$('#form-section').hide(); $('#form-section').hide();
$('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide(); $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide();
$('#total-checkout-price').parent().parent().parent().hide(); $('#total-checkout-price').parent().parent().parent().hide();
$('#no-products-in-checkout').show(); $('#no-products-in-checkout').show();
$('#cart-error-in-checkout').hide();
} }
} }


@ -60,12 +76,14 @@ $(window).on('load', function(){
let products = response.contents.map(product => { let products = response.contents.map(product => {
product = getProductInfo(product); product = getProductInfo(product);
product = calculatePrice(product); product = calculatePrice(product);
return product; return product.quantity+'x '+product.title+' ('+numberToEuroFormat(product.calc_preis)+')';
}); });
$('#ccart').val(JSON.stringify({"total-price": totalPrice, "products": products})); let cart = products.join('\n')+"\nTotal Price: "+numberToEuroFormat(totalPrice);
objProducts = []; $('#ccart').val(cart);
localStorage.setItem("products", JSON.stringify(objProducts)); console.log($('form').serializeArray());
form.unbind('submit').submit(); //objProducts = [];
//localStorage.setItem("products", JSON.stringify(objProducts));
//form.unbind('submit').submit();
}); });
}); });
$(document).on('click', '.btn-remove-product', function(){ $(document).on('click', '.btn-remove-product', function(){

View File

@ -113,6 +113,15 @@ function updateProductsInLocalStorage(){
$('#list-products-in-bag').append(elementProduct); $('#list-products-in-bag').append(elementProduct);
}); });
$('#total-price').text(numberToEuroFormat(totalPrice)); $('#total-price').text(numberToEuroFormat(totalPrice));
}).fail(function(response){
$('.cart-link').hide();
$(".btn-share").hide();
$('#count-products-in-bag').hide();
$('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').hide();
$('#total-price').parent().parent().parent().hide();
$('#no-products').hide();
$('#cart-error').show();
$('#modal-buttons').hide();
}); });
$('.cart-link').show(); $('.cart-link').show();
$(".btn-share").show(); $(".btn-share").show();
@ -120,6 +129,7 @@ function updateProductsInLocalStorage(){
$('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').show(); $('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').show();
$('#total-price').parent().parent().parent().show(); $('#total-price').parent().parent().parent().show();
$('#no-products').hide(); $('#no-products').hide();
$('#cart-error').hide();
$('#modal-buttons').show(); $('#modal-buttons').show();
cartLink = window.location.origin+'/'+btoa(JSON.stringify(objProducts)); cartLink = window.location.origin+'/'+btoa(JSON.stringify(objProducts));
@ -139,6 +149,7 @@ function updateProductsInLocalStorage(){
$('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').hide(); $('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').hide();
$('#total-price').parent().parent().parent().hide(); $('#total-price').parent().parent().parent().hide();
$('#no-products').show(); $('#no-products').show();
$('#cart-error').hide();
$('#modal-buttons').hide(); $('#modal-buttons').hide();
} }
let productId = $('meta[name="product-id"]').attr('content'); let productId = $('meta[name="product-id"]').attr('content');

View File

@ -106,6 +106,9 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="row"> <div class="row">
<div style="display: none;" class="alert alert-danger" role="alert" id="cart-error">
Fehler beim Laden der Produkte, versuchen Sie, die Seite neu zu laden
</div>
<div style="display: none;" class="col-12 text-center" id="no-products"> <div style="display: none;" class="col-12 text-center" id="no-products">


<br> <br>

View File

@ -58,6 +58,9 @@
<!-- Calendly inline widget end --> <!-- Calendly inline widget end -->
</div> </div>
@else @else
<div style="display: none;" class="alert alert-danger" role="alert" id="cart-error-in-checkout">
Fehler beim Laden der Produkte, versuchen Sie die Seite neu zu laden
</div>
<div style="display: none;" class="col-12 text-center" id="no-products-in-checkout"> <div style="display: none;" class="col-12 text-center" id="no-products-in-checkout">
<br> <br>
<br> <br>