From ab65fa7a73ba2ad430a9bafdb6a160189e0eadfb Mon Sep 17 00:00:00 2001 From: Dennis Heinrich Date: Wed, 9 Apr 2025 14:53:48 +0200 Subject: [PATCH] =?UTF-8?q?Kompatibilit=C3=A4t=20zur=20alten=20JSON-Datei?= =?UTF-8?q?=20sowie=20kleinere=20Verbesserungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script/all.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/script/all.js b/assets/script/all.js index 7028828..57d1d99 100644 --- a/assets/script/all.js +++ b/assets/script/all.js @@ -169,6 +169,7 @@ class Product { * Product constructor * @param name {string} Name of the product * @param price {number} Price of the product + * @param deposit {number} Deposit of the product * @param image {string} Image of the product (source url or base64) */ constructor(name, price, deposit, image) { @@ -480,7 +481,7 @@ class CartManager { registerCartResetEvent() { Element.getCartButton().addEventListener('click', () => { CartHistoryManager.addToTotal(this.cartLines.reduce((acc, cartLine) => { - return acc + (cartLine.product.price * cartLine.quantity) + (cartLine.product.deposit * cartLine.quantity); + return acc + (cartLine.product.price * cartLine.quantity) + ((cartLine.product.deposit??0) * cartLine.quantity); }, 0)); this.cartLines = []; this.renderCart(); @@ -525,8 +526,6 @@ class CartManager { if (e.getAttribute('data-template') === null) { e.remove(); } - - console.log(e) }); if(this.cartLines.length === 0) { @@ -544,7 +543,7 @@ class CartManager { let depositTotal = 0; this.cartLines.forEach(cartLine => { - depositTotal += cartLine.product.deposit * cartLine.quantity; + depositTotal += (cartLine.product.deposit??0) * cartLine.quantity; }); if(depositTotal !== 0) { let depositElement = TemplateElement.getDepositTemplate(); @@ -575,7 +574,7 @@ class CartManager { */ calculateCartValue() { let cartValue = this.cartLines.reduce((acc, cartLine) => { - return acc + (cartLine.product.price * cartLine.quantity) + (cartLine.product.deposit * cartLine.quantity); + return acc + (cartLine.product.price * cartLine.quantity) + ((cartLine.product.deposit??0) * cartLine.quantity); }, 0); Element.getCartButton().querySelector('[data-total-value]').textContent = CartManager.getNumberFormatter().format(cartValue); }