From 7c3fb41b43978270ed6739afeb97eb64419d7068 Mon Sep 17 00:00:00 2001 From: morgane Date: Thu, 18 Jun 2026 17:09:55 +0000 Subject: [PATCH] Actualiser api/index.php --- api/index.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/index.php b/api/index.php index 9a06c69..56fccfe 100644 --- a/api/index.php +++ b/api/index.php @@ -3158,8 +3158,9 @@ function addToInventory(PDO $db): void { // NOTE: default_quantity is the PACKAGE SIZE, not the quantity being added — // do NOT overwrite it here. It is managed via product_save / the edit form. if ($unit) { - $stmt = $db->prepare("UPDATE products SET unit = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); - $stmt->execute([$unit, $productId]); + $displayUnitKey = $input['display_unit_key'] ?? null; + $stmt = $db->prepare("UPDATE products SET unit = ?, display_unit_key = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$unit, $displayUnitKey, $productId]); } else { // Auto-set default_quantity if product has none (first add sets package size) $stmt = $db->prepare("SELECT default_quantity, unit FROM products WHERE id = ?"); @@ -3764,12 +3765,13 @@ function updateInventory(PDO $db): void { // silently revert the user's correction on the next scan. if (isset($input['unit']) && isset($input['product_id'])) { $newUnit = $input['unit']; + $newDisplayUnitKey = $input['display_unit_key'] ?? null; if ($newUnit === 'pz') { - $stmt = $db->prepare("UPDATE products SET unit = ?, default_quantity = CASE WHEN default_quantity < 1 THEN 1 ELSE default_quantity END, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt = $db->prepare("UPDATE products SET unit = ?, display_unit_key = ?, default_quantity = CASE WHEN default_quantity < 1 THEN 1 ELSE default_quantity END, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); } else { - $stmt = $db->prepare("UPDATE products SET unit = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt = $db->prepare("UPDATE products SET unit = ?, display_unit_key = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); } - $stmt->execute([$newUnit, $input['product_id']]); + $stmt->execute([$newUnit, $newDisplayUnitKey, $input['product_id']]); } // Update package info if provided