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,8 +54,16 @@ $(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));
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 = [];
localStorage.setItem("products", JSON.stringify(objProducts));
});
});
$(document).on('click', '.btn-remove-product', function(){
if(objProducts.length > 0){

View File

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

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

function calculatePrice(objProduct){

View File

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