fix: getAllShoppingPrices TypeError on null estimated_total for /kg items; fallback to 1-unit price

This commit is contained in:
dadaloop82
2026-05-07 20:56:03 +00:00
parent 4f98a63414
commit f4dbd151a8
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -6731,7 +6731,7 @@ function getAllShoppingPrices(PDO $db): void {
$est = _calcEstimatedTotal($entry['price_per_unit'], $entry['unit_label'] ?? '', $qty, $unit, $defQty, $pkgUnit);
$prices[$name] = array_merge($entry, [
'estimated_total' => $est,
'estimated_total_label' => _formatPrice($est, $currency),
'estimated_total_label' => $est !== null ? _formatPrice($est, $currency) : null,
'from_cache' => true,
]);
$total += $est ?? 0;
@@ -6773,7 +6773,7 @@ function getAllShoppingPrices(PDO $db): void {
$est = _calcEstimatedTotal($entry['price_per_unit'], $entry['unit_label'], $qty, $unit, $defQty, $pkgUnit);
$prices[$name] = array_merge($entry, [
'estimated_total' => $est,
'estimated_total_label' => _formatPrice($est, $currency),
'estimated_total_label' => $est !== null ? _formatPrice($est, $currency) : null,
'from_cache' => false,
]);
$total += $est ?? 0;
@@ -6828,8 +6828,8 @@ function _calcEstimatedTotal(float $pricePerUnit, string $priceUnitLabel, float
} elseif ($unit === 'kg') {
$weightKg = $qty;
}
// pz / conf without defQty → we don't know the weight → no total
if ($weightKg <= 0) return null;
// pz / conf without defQty → assume 1 unit at price_per_unit (e.g. 1kg of fruit)
if ($weightKg <= 0) return round($pricePerUnit, 2);
return round($pricePerUnit * $weightKg, 2);
}
@@ -6845,7 +6845,7 @@ function _calcEstimatedTotal(float $pricePerUnit, string $priceUnitLabel, float
} elseif ($unit === 'l') {
$volumeL = $qty;
}
if ($volumeL <= 0) return null;
if ($volumeL <= 0) return round($pricePerUnit, 2);
return round($pricePerUnit * $volumeL, 2);
}
+1 -1
View File
@@ -1462,6 +1462,6 @@
</div>
</div>
<script src="assets/js/app.js?v=20260507m"></script>
<script src="assets/js/app.js?v=20260507n"></script>
</body>
</html>