Fix weight-based shipping rate breakpoints evaluation#2382
Fix weight-based shipping rate breakpoints evaluation#2382Huncsuga wants to merge 6 commits intolunarphp:1.xfrom
Conversation
Sync 05.10.2025
Sync 14.12.2025
…convert cart lines weight to Kg
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where weight-based shipping rate breakpoints were evaluated incorrectly due to inconsistent weight unit handling. The fix ensures cart weights and pricing tier thresholds are normalized to kilograms before comparison, allowing weight-based shipping tiers to apply correctly.
Key Changes:
- Normalized all weight calculations to kilograms using the Converter facade
- Removed incorrect scaling factor (×100) when saving and loading weight-based pricing breakpoints
- Added UI helper text and suffix to clarify that weight thresholds should be entered in kg
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/table-rate-shipping/src/Drivers/ShippingMethods/ShipBy.php | Converts product weights to kg before calculating total cart weight |
| packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php | Removes ×100 scaling for weight values and adds kg suffix/helper text to form field |
| packages/table-rate-shipping/resources/lang/en/relationmanagers.php | Adds English helper text indicating weight should be entered in kg |
| packages/table-rate-shipping/resources/lang/ro/relationmanagers.php | Adds Romanian helper text indicating weight should be entered in kg |
| packages/table-rate-shipping/resources/lang/hu/relationmanagers.php | Adds Hungarian helper text indicating weight should be entered in kg |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/table-rate-shipping/src/Drivers/ShippingMethods/ShipBy.php
Outdated
Show resolved
Hide resolved
packages/table-rate-shipping/src/Drivers/ShippingMethods/ShipBy.php
Outdated
Show resolved
Hide resolved
...able-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php
Outdated
Show resolved
Hide resolved
alecritson
left a comment
There was a problem hiding this comment.
Thanks @Huncsuga Sorry for the lengthy delay in getting to look at this. Only a couple of comments if you're happy to pick this back up.
Also one concern is now we're not multiplying the value by 100 we need to ensure the pricing manager still works on the table-rate-shipping add-on. We'd need some tests to ensure everything this changes is covered.
| ->convert() | ||
| ->getValue(); | ||
| } catch (\Exception $e) { | ||
| return 0; |
There was a problem hiding this comment.
This silently excludes the line's weight from the total, potentially qualifying the cart for a cheaper shipping tier. A fallback like $line->purchasable->weight_unit ?: 'kg' would be safer than silently zeroing the weight.
| $price['min_quantity'] = (int) ($price['min_quantity'] * $currency->factor); | ||
| } else { | ||
| $price['min_quantity'] = (int) ($price['min_quantity'] * 100); | ||
| $price['min_quantity'] = (int) $price['min_quantity']; |
There was a problem hiding this comment.
Any existing installation with weight-based shipping rates stored as multiplied integers (e.g., 500 meaning 5 kg) will have breakpoints that never match after upgrade, since 5.0 >= 500 is false.
A state class would be needed to rescale existing min_quantity values would be needed
Description
Related Issue
Type
What was changed
Expected Outcome
How to test