From 28999e5486c12cbfd0491cb71935c64107cb2b2b Mon Sep 17 00:00:00 2001 From: w3houde Date: Tue, 2 Jun 2026 16:20:38 +0200 Subject: [PATCH] Fix #34069 read shipping weight, dimensions and quantities as floats (#38549) * Fix #34069 read shipping weight, dimensions and quantities as floats htdocs/expedition/card.php read the package weight, the three box dimensions (sizeH / sizeW / sizeS), the true* fields (trueWeight / trueWidth / trueHeight / trueDepth) and the per-line shipped quantity with GETPOSTINT(). All of these are physical quantities that routinely use decimals (a 1.6 kg parcel, a 0.25 m box edge, a 0.5 unit of service), and GETPOSTINT() silently truncates the fractional part so a 1.6 kg weight was stored as 1 kg and a 0.25 line quantity was stored as 0, breaking the link with the source order line. The reporter ran into both cases on v20 and confirmed it is still present on v22. Replace the GETPOSTINT() reads with GETPOST() + price2num() casts at the six save sites (the initial create from source order, the four 'settrueX' inline actions and the per-line qtyl input) and the displayed weight value, mirroring the float handling that exists in htdocs/commande/card.php and other places. The weight unit and size unit dropdowns stay as GETPOSTINT() since those are dictionary ids. Same code path on 21.0, 22.0, 23.0 and develop; PR targets 21.0. Signed-off-by: Dolicraft * Fix #34069 use GETPOSTFLOAT helper per review Address @eldy review on PR #38549: the develop branch already uses GETPOSTFLOAT() at the same call sites, so backport the helper to v21 instead of inlining (float) price2num(GETPOST(...)). Same semantics (GETPOSTFLOAT wraps the same expression at functions.lib.php line 1152 on 21.0) but shorter and idiomatic with the rest of the codebase. Signed-off-by: Dolicraft --------- Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/expedition/card.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index a804bac3b9b..dda15f9d253 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -251,10 +251,13 @@ if (empty($reshook)) { $object->origin = $origin; $object->origin_id = $origin_id; $object->fk_project = GETPOSTINT('projectid'); - $object->weight = GETPOSTINT('weight') == '' ? "NULL" : GETPOSTINT('weight'); - $object->sizeH = GETPOSTINT('sizeH') == '' ? "NULL" : GETPOSTINT('sizeH'); - $object->sizeW = GETPOSTINT('sizeW') == '' ? "NULL" : GETPOSTINT('sizeW'); - $object->sizeS = GETPOSTINT('sizeS') == '' ? "NULL" : GETPOSTINT('sizeS'); + // Weight and box dimensions are physical measurements that frequently use + // decimals (1.6 kg, 0.25 m, ...), so they must be read as floats and not + // truncated to int (see issue #34069 for the shipping module). + $object->weight = GETPOST('weight', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('weight'); + $object->sizeH = GETPOST('sizeH', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeH'); + $object->sizeW = GETPOST('sizeW', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeW'); + $object->sizeS = GETPOST('sizeS', 'alpha') == '' ? "NULL" : GETPOSTFLOAT('sizeS'); $object->size_units = GETPOSTINT('size_units'); $object->weight_units = GETPOSTINT('weight_units'); @@ -579,18 +582,18 @@ if (empty($reshook)) { $object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml')); } if ($action == 'settrueWeight') { - $object->trueWeight = GETPOSTINT('trueWeight'); + $object->trueWeight = GETPOSTFLOAT('trueWeight'); $object->weight_units = GETPOSTINT('weight_units'); } if ($action == 'settrueWidth') { - $object->trueWidth = GETPOSTINT('trueWidth'); + $object->trueWidth = GETPOSTFLOAT('trueWidth'); } if ($action == 'settrueHeight') { - $object->trueHeight = GETPOSTINT('trueHeight'); + $object->trueHeight = GETPOSTFLOAT('trueHeight'); $object->size_units = GETPOSTINT('size_units'); } if ($action == 'settrueDepth') { - $object->trueDepth = GETPOSTINT('trueDepth'); + $object->trueDepth = GETPOSTFLOAT('trueDepth'); } if ($action == 'setshipping_method_id') { $object->shipping_method_id = GETPOSTINT('shipping_method_id'); @@ -1080,7 +1083,7 @@ if ($action == 'create') { print $langs->trans("Weight"); print ''; print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"'); - print ' '; + print ' '; $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTINT('weight_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); @@ -1357,8 +1360,8 @@ if ($action == 'create') { // Quantity to send print ''; if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || ($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES'))) { - if (GETPOSTINT('qtyl'.$indiceAsked)) { - $deliverableQty = GETPOSTINT('qtyl'.$indiceAsked); + if (GETPOSTISSET('qtyl'.$indiceAsked) && GETPOST('qtyl'.$indiceAsked) !== '') { + $deliverableQty = GETPOSTFLOAT('qtyl'.$indiceAsked, 'MS'); } print ''; print '';