add cart field

master
Gustavo Luigi 2022-09-07 16:04:33 +02:00
parent 3f981767f9
commit eeb8ad675b
3 changed files with 12 additions and 3 deletions

View File

@ -54,9 +54,17 @@ $(window).on('load', function(){
updateProducts(); updateProducts();
$("#successful-submitting-form").delay(4000).slideUp(200, function() { $(this).alert('close'); }); $("#successful-submitting-form").delay(4000).slideUp(200, function() { $(this).alert('close'); });
$('#anfrage').submit(function(){ $('#anfrage').submit(function(){
getInfoFromSelectedProduct().done(function(response, status){
let products = response.contents.map(product => {
product = getProductInfo(product);
product = calculatePrice(product);
return product;
});
$('#ccart').val(JSON.stringify({"total-price": totalPrice, "products": products}));
objProducts = []; objProducts = [];
localStorage.setItem("products", JSON.stringify(objProducts)); localStorage.setItem("products", JSON.stringify(objProducts));
}); });
});
$(document).on('click', '.btn-remove-product', function(){ $(document).on('click', '.btn-remove-product', function(){
if(objProducts.length > 0){ if(objProducts.length > 0){
$('#form-section').show(); $('#form-section').show();

View File

@ -17,7 +17,7 @@ function getQuantityOfProducts(){


function getProductInfo(productInfo){ function getProductInfo(productInfo){
let objProduct = objProducts.find(obj => obj.id == productInfo.id); let objProduct = objProducts.find(obj => obj.id == productInfo.id);
return jQuery.extend([], objProduct, productInfo); return jQuery.extend({}, objProduct, productInfo);
} }


function calculatePrice(objProduct){ function calculatePrice(objProduct){

View File

@ -109,6 +109,7 @@
<br> <br>
@endif @endif
<x-form id="anfrage" id-name="anfrage" channels="bestaetigung,airtable"> <x-form id="anfrage" id-name="anfrage" channels="bestaetigung,airtable">
<input type="hidden" name="cart" id="ccart">
<div class="mb-4"> <div class="mb-4">
<label for="" class="form-label">Anrede</label> <label for="" class="form-label">Anrede</label>
<select class="form-select" name="anrede" aria-label="Default select example"> <select class="form-select" name="anrede" aria-label="Default select example">