Skip to content

Fix duplicate field exception when overriding a default product_variants option field - #263

Merged
duncanmcclean merged 1 commit into
1.xfrom
fix-product-variant-option-field-override
Jul 30, 2026
Merged

Fix duplicate field exception when overriding a default product_variants option field#263
duncanmcclean merged 1 commit into
1.xfrom
fix-product-variant-option-field-override

Conversation

@duncanmcclean

Copy link
Copy Markdown
Owner

This pull request fixes an issue where adding a custom option_fields entry with the same handle as one of the built-in defaults (key, variant, or price) on the product_variants fieldtype throws a DuplicateFieldException.

This was happening because ProductVariants::optionFields() merged the user's configured option_fields onto the built-in defaults using Collection::merge(), which appends rather than overriding by handle. If a user added their own price field (eg. to add numeric validation), the resulting field list ended up with two entries both handled price, 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_fields before merging, so the user's version wins instead of duplicating.

Fixes #261

…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
@duncanmcclean
duncanmcclean merged commit 5424a00 into 1.x Jul 30, 2026
14 checks passed
@duncanmcclean
duncanmcclean deleted the fix-product-variant-option-field-override branch July 30, 2026 12:44
@github-actions

Copy link
Copy Markdown

Released as part of v1.10.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate field [price] on blueprint [product.product_variants].

1 participant