fix: prevent custom option value duplication in merge mode - #8
Merged
Conversation
In merge mode an existing option is reused by title, but its select-type values were re-inserted id-less on every sync, so the values accumulated a duplicate copy each run. Match incoming values to the option's existing values by title and reuse their option_type_id (core then updates in place), and remove values absent from the source. Makes merge idempotent and keeps option_type_id stable for orders/quotes and dependent-option modules. Fixes #7
mageaustralia
pushed a commit
that referenced
this pull request
Jun 2, 2026
Resolve CustomOptionsTrait conflict by taking main's value-level merge (from #8, which superseded this branch's equivalent trait change). Retains this branch's unique changes in Product.php: options_mode default flipped to 'merge' (4 sites) + empty-overwrite guard for attrs with a non-empty default (closes #4).
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.
What
Makes
merge-mode custom-option import idempotent for select-type option values, fixing the duplication described in #7.Why
_createProductOption()reused an existing option (matched by title) but assigned its incoming values with the sourceoption_type_idstripped and no matching against the option's existing values — so the core save inserted every value as new on each run and never removed the prior ones. Result: option values accumulated one duplicate copy per sync.Change
In
CustomOptionsTrait::_createProductOption(), fordrop_down/radio/checkbox/multiple:load()-ed option does not auto-populategetValues()).option_type_id→ core UPDATEs the row in place instead of inserting.Net effect: re-syncing an unchanged product leaves its option values unchanged;
option_type_idstays stable (important for historical order/quote selections and dependent-option modules).Fixes #7