From c952b49920f8bac33d979426436783c40d055f55 Mon Sep 17 00:00:00 2001 From: Bastien Roy Date: Sun, 4 Feb 2024 11:32:12 +0100 Subject: [PATCH] 167 retours Alexis --- .../order/templates/order/grouped_order_detail.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/la_chariotte/order/templates/order/grouped_order_detail.html b/la_chariotte/order/templates/order/grouped_order_detail.html index a1deb2b..726d079 100644 --- a/la_chariotte/order/templates/order/grouped_order_detail.html +++ b/la_chariotte/order/templates/order/grouped_order_detail.html @@ -185,13 +185,15 @@ {% block extra_js %} // Compute total price whenever a value in input is modified document.getElementById("inputs-parent").addEventListener("change", function () { - var inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only - total_price = 0; + inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only + + prices = {{ prices_dict | safe }}; + let total_price = 0; + for (let input of inputs) { input_name = input.getAttribute("name"); item_id = input_name.split("_")[1]; - prices = {{ prices_dict | safe }}; - total_price = Number((total_price + Number((prices[item_id] * input.value).toFixed(2))).toFixed(2)); //Limit precision to 2 digits for each added part and for the total + total_price = Number((total_price + (prices[item_id] * input.value)).toFixed(2)); //Limit precision to 2 digits for each added part and for the total } [].forEach.call(document.getElementsByClassName('total'), function (el) {