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) {