Closed jornwildenbeest closed 1 day ago
The following code calculates the weight in KG:
private function _getOrderWeightInKg(Order $order): ?string { $weight = $order->getTotalWeight(); if ($weight <= 0) { return null; } $weightUnit = Commerce::getInstance()->getSettings()->weightUnits; $totalWeight = match ($weightUnit) { 'g' => $weight * 1000, 'lb' => $weight * 0.453, default => $weight, }; return (string)$totalWeight; }
But there is an miscalculation here.
If the weightUnit is grams (g). You want to divide by 1000, not multiply.
Explanation: if the weight is set to 850 Gram, to get KG's you need to divide by 1000.
The fix would be:
$totalWeight = match ($weightUnit) { 'g' => $weight / 1000, 'lb' => $weight * 0.453, default => $weight, };
Hi @jornwildenbeest, Just tagged 4.0.1 with the fix
The following code calculates the weight in KG:
But there is an miscalculation here.
If the weightUnit is grams (g). You want to divide by 1000, not multiply.
Explanation: if the weight is set to 850 Gram, to get KG's you need to divide by 1000.
The fix would be: