From 7782eb151915d504e90f75c8d81ff9a7ef354821 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Mon, 6 Apr 2026 09:10:29 +0000 Subject: [PATCH] fix: pre-fill conf size from product's weight/volume unit when switching to 'confezioni' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a product was created with unit='g' (or ml/kg/l) and a default_quantity, that value already IS the package size — no need to ask again. Applied in both showAddForm() initial render and onAddUnitChange() toggle. --- assets/js/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assets/js/app.js b/assets/js/app.js index 8e375c3..ee2fc91 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -3183,6 +3183,10 @@ function showAddForm() { if (unit === 'conf' && currentProduct.package_unit && currentProduct.default_quantity > 0) { document.getElementById('add-conf-size').value = currentProduct.default_quantity; document.getElementById('add-conf-unit').value = currentProduct.package_unit; + } else if (unit === 'conf' && ['g', 'ml', 'kg', 'l'].includes(currentProduct.unit) && currentProduct.default_quantity > 0) { + // Product was defined in weight/volume — that quantity IS the package size + document.getElementById('add-conf-size').value = currentProduct.default_quantity; + document.getElementById('add-conf-unit').value = currentProduct.unit; } else if (unit === 'conf') { document.getElementById('add-conf-size').value = ''; document.getElementById('add-conf-unit').value = 'g'; @@ -3359,6 +3363,10 @@ function onAddUnitChange() { if (currentProduct.package_unit && currentProduct.default_quantity > 1) { sizeInput.value = currentProduct.default_quantity; unitSelect.value = currentProduct.package_unit; + } else if (['g', 'ml', 'kg', 'l'].includes(currentProduct.unit) && currentProduct.default_quantity > 0) { + // Product was defined in weight/volume — that quantity IS the package size + sizeInput.value = currentProduct.default_quantity; + unitSelect.value = currentProduct.unit; } else { sizeInput.value = ''; unitSelect.value = 'g';