Fix/table rate shipping by weight#2515
Open
zalito12 wants to merge 2 commits into
Open
Conversation
0ad40a9 to
fd4fec8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Weight-based shipping rate tiers with ×100 scale and configurable weight_unit
Fix #2514
Problem
Weight-based shipping in
lunarphp/table-rate-shippingis broken due to three issues:min_quantityfor weight tiers is stored as a raw integer (e.g.5for 5 kg) butPricingManager::qty(int $qty)truncates floats like2.5to2, causing tier matching failures and precision bugs.'weight.kg'in the Converter call, ignoring theweight_unitattribute onProductVariant. Products stored in grams or pounds would be incorrectly converted.Solution
Scale: ×100 — consistent with
cart_totalmodeWeight thresholds now use the same ×100 pattern as currency amounts in
cart_totalmode:2.5kg → stored as250inmin_quantity(int) round(2.5 * 100)=250→ compares250 >= 250✓This eliminates
PricingManager::qty(int)truncation and float precision issues entirely, since all values are integers.Configurable
weight_unitShipBy.phpreadsweight_unitfrom the shipping method'sdataJSON column (defaulting to'kg'), and uses it to convert all product weights into the same unit before summing:The admin displays the selected weight_unit dynamically via a new getShippingWeightUnit() helper in label, suffix, and helper text.
Testing