Skip to content

Commit f3b368d

Browse files
committed
Fix weight conversion error in shipping rate calculation and clean up min_quantity casting
1 parent 46dd8cf commit f3b368d

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

packages/table-rate-shipping/src/Drivers/ShippingMethods/ShipBy.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ public function resolve(ShippingOptionRequest $shippingOptionRequest): ?Shipping
7272

7373
if ($chargeBy == 'weight') {
7474
$tier = $cart->lines->sum(function ($line) {
75-
$weightUnit = $line->purchasable->weight_unit ?: 'kg';
76-
77-
$unitWeightKg = Converter::from("weight.{$weightUnit}")
78-
->to('weight.kg')
79-
->value($line->purchasable->weight_value)
80-
->convert()
81-
->getValue();
75+
try {
76+
$unitWeightKg = Converter::from("weight.{$line->purchasable->weight_unit}")
77+
->to('weight.kg')
78+
->value($line->purchasable->weight_value)
79+
->convert()
80+
->getValue();
81+
} catch (\Exception $e) {
82+
return 0;
83+
}
8284

8385
return $unitWeightKg * $line->quantity;
8486
});

packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function ($price) use ($chargeBy, $currencies) {
259259
if ($chargeBy == 'cart_total') {
260260
$price['min_quantity'] = (int) ($price['min_quantity'] * $currency->factor);
261261
} else {
262-
$price['min_quantity'] = (int) ($price['min_quantity']);
262+
$price['min_quantity'] = (int) $price['min_quantity'];
263263
}
264264

265265
$price['price'] = (int) ($price['price'] * $currency->factor);

0 commit comments

Comments
 (0)