From 0c6b85f1af32d6d737de0af9dd60bb394ece451d Mon Sep 17 00:00:00 2001 From: supertom01 Date: Wed, 5 Mar 2025 17:51:21 +0100 Subject: [PATCH] Add typechecking --- .../static/js/personal_tab_pos.js | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/amelie/personal_tab/static/js/personal_tab_pos.js b/amelie/personal_tab/static/js/personal_tab_pos.js index 44fcd87..64e7ef3 100644 --- a/amelie/personal_tab/static/js/personal_tab_pos.js +++ b/amelie/personal_tab/static/js/personal_tab_pos.js @@ -431,7 +431,13 @@ function setupCalculator(calculator) { if(!isNaN(inputValue) && inputValue > 0){ // Add to cart // We replace the potential ',' by a '.' for the parseFloat function. - addToCart(productId, productName, parseInt(inputfield.attr('value'), 10), parseFloat(productPrice.replace(",", ".")), productImage); + let price; + if (typeof productPrice === 'string' || productPrice instanceof String) { + price = parseFloat(productPrice.replace(",", ".")) + } else { + price = parseFloat(productPrice) + } + addToCart(productId, productName, parseInt(inputfield.attr('value'), 10), price, productImage); // Clear the input field inputfield.attr('value', ''); // Return to main tab @@ -471,7 +477,14 @@ function setupShopPage(){ resetCart(); var article_elem = $(event.currentTarget.parentElement); var article_id = article_elem.data('id'); - var article_price = parseFloat(article_elem.data('price').replace(",", ".")); // Replace the ',' by a '.' for the Dutch website. + // We replace the potential ',' by a '.' for the parseFloat function. + let price; + if (typeof productPrice === 'string' || productPrice instanceof String) { + price = parseFloat(productPrice.replace(",", ".")) + } else { + price = parseFloat(productPrice) + } + var article_price = price; // Replace the ',' by a '.' for the Dutch website. var article_name = article_elem.data('name'); var article_image = article_elem.data('image'); addToCartInstant(article_id, article_name, 1, article_price, article_image); @@ -481,7 +494,14 @@ function setupShopPage(){ resetCart(); var article_elem = $(event.currentTarget.parentElement); var article_id = article_elem.data('id'); - var article_price = parseFloat(article_elem.data('price').replace(",", ".")); // Replace the ',' by a '.' for the Dutch website. + // We replace the potential ',' by a '.' for the parseFloat function. + let price; + if (typeof productPrice === 'string' || productPrice instanceof String) { + price = parseFloat(productPrice.replace(",", ".")) + } else { + price = parseFloat(productPrice) + } + var article_price = price; // Replace the ',' by a '.' for the Dutch website. var article_name = article_elem.data('name'); var article_image = article_elem.data('image'); addToCartInstant(article_id, article_name, 1, article_price, article_image); @@ -490,7 +510,13 @@ function setupShopPage(){ $('.article-addtocart').click(function(event){ var article_elem = $(event.currentTarget.parentElement); var article_id = article_elem.data('id'); - var article_price = parseFloat(article_elem.data('price').replace(",", ".")); // Replace the ',' by a '.' for the Dutch website. + let price; + if (typeof productPrice === 'string' || productPrice instanceof String) { + price = parseFloat(productPrice.replace(",", ".")) + } else { + price = parseFloat(productPrice) + } + var article_price = price; // Replace the ',' by a '.' for the Dutch website. var article_name = article_elem.data('name'); var article_image = article_elem.data('image'); addToCart(article_id, article_name, 1, article_price, article_image);