Fix duplicate field exception when overriding a default product_variants option field - #263
Merged
Merged
Conversation
…ants` option field previously, configuring a custom `option_fields` entry with the same handle as one of the built-in defaults (`key`, `variant`, `price`) on the `product_variants` fieldtype would throw a `DuplicateFieldException` once the resulting blueprint's fields were resolved, since `optionFields()` appended the configured fields onto the defaults instead of overriding them. fixes #261
|
Released as part of v1.10.1. |
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.
This pull request fixes an issue where adding a custom
option_fieldsentry with the same handle as one of the built-in defaults (key,variant, orprice) on theproduct_variantsfieldtype throws aDuplicateFieldException.This was happening because
ProductVariants::optionFields()merged the user's configuredoption_fieldsonto the built-in defaults usingCollection::merge(), which appends rather than overriding by handle. If a user added their ownpricefield (eg. to addnumericvalidation), the resulting field list ended up with two entries both handledprice, which threw once the blueprint's fields were resolved.This PR fixes it by rejecting any built-in default field whose handle is already present in the user's configured
option_fieldsbefore merging, so the user's version wins instead of duplicating.Fixes #261