Fix Price object cast error when editing tier and customer group prices#2458
Open
krlmrr wants to merge 1 commit into
Open
Fix Price object cast error when editing tier and customer group prices#2458krlmrr wants to merge 1 commit into
krlmrr wants to merge 1 commit into
Conversation
Filament v4's `NumberStateCast` (added by `->numeric()`) calls `floatval()`
on raw state during form hydration, before `formatStateUsing` can run. The
edit form distributes the `Lunar\DataTypes\Price` object straight from the
record's attributes, so hydration throws:
Object of class Lunar\DataTypes\Price could not be converted to float
Mirrors the ordering fix from lunarphp#2441 (which handled `FieldType` values for
attributes) but applied to the Price relation managers, where converting
the value via `mutateRecordDataUsing` is sufficient — Price values come in
through plain record attributes, so we can unwrap them before the form
fills, and the `formatStateUsing` calls become unnecessary.
Affected forms: tier price edit (`PriceRelationManager`) and customer
group pricing edit (`CustomerGroupPricingRelationManager`).
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.
Summary
Fixes a regression in 1.5.0-beta.2 / beta.3 where opening the edit modal for a tier price or customer group price throws:
This is the same ordering bug as #2441 — Filament v4's
NumberStateCast(registered by->numeric()) runsfloatval()on the raw state during hydration, beforeformatStateUsingis given a chance to unwrap the value. The two relation managers that bind aLunar\DataTypes\Priceobject straight to a numericTextInputwere not covered by that fix.PR #2441 solved the equivalent problem for
FieldTypeattribute values by overridinghydrateState. For prices, the values arrive through plain record attributes, soEditAction::mutateRecordDataUsing()runs early enough to convert thePriceobject into its decimal value before child component hydration — which means theformatStateUsingcalls can be removed entirely.Changes
PriceRelationManagerandCustomerGroupPricingRelationManager: addmutateRecordDataUsingon theEditActionto convertPriceobjects to their decimal value via a smallunwrapPriceDatahelper.formatStateUsingcallbacks onprice/compare_pricetext inputs.1.xwithout the fix with the original exception).Test plan
vendor/bin/pest --testsuite=admin --group=resource.productvendor/bin/pest --testsuite=admin --filter='customer group price|tier price'vendor/bin/pint --format agenton touched files1.xwithout the fix (reproducing the originalObject of class Lunar\DataTypes\Price could not be converted to floatexception)