From eeb8ad675b3034e018aafd037e5f213a3e935bde Mon Sep 17 00:00:00 2001 From: Gustavo Luigi <=> Date: Wed, 7 Sep 2022 16:04:33 +0200 Subject: [PATCH] add cart field --- assets/js/checkout.js | 12 ++++++++++-- assets/js/methods.js | 2 +- content/pages/checkout.blade.php | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/assets/js/checkout.js b/assets/js/checkout.js index be20c43..0b6f8f4 100644 --- a/assets/js/checkout.js +++ b/assets/js/checkout.js @@ -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){ diff --git a/assets/js/methods.js b/assets/js/methods.js index b9ee580..30b495d 100644 --- a/assets/js/methods.js +++ b/assets/js/methods.js @@ -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){ diff --git a/content/pages/checkout.blade.php b/content/pages/checkout.blade.php index f1c394a..26e7fa2 100644 --- a/content/pages/checkout.blade.php +++ b/content/pages/checkout.blade.php @@ -109,6 +109,7 @@
@endif +