Skip to content

fix: prevent custom option value duplication in merge mode - #8

Merged
mageaustralia merged 1 commit into
mainfrom
fix/merge-option-values-duplication
May 29, 2026
Merged

fix: prevent custom option value duplication in merge mode#8
mageaustralia merged 1 commit into
mainfrom
fix/merge-option-values-duplication

Conversation

@mageaustralia

Copy link
Copy Markdown
Owner

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 source option_type_id stripped 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(), for drop_down / radio / checkbox / multiple:

  1. Load the existing option's values with their store-0 titles (a freshly load()-ed option does not auto-populate getValues()).
  2. Match incoming values to existing ones by title and reuse the existing option_type_id → core UPDATEs the row in place instead of inserting.
  3. Delete existing values whose title is absent from the source after save, so the option converges to the source set.

Net effect: re-syncing an unchanged product leaves its option values unchanged; option_type_id stays stable (important for historical order/quote selections and dependent-option modules).

Fixes #7

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
mageaustralia merged commit eda8d67 into main May 29, 2026
1 check passed
@mageaustralia
mageaustralia deleted the fix/merge-option-values-duplication branch May 29, 2026 02:06
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).
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.

Custom option values duplicated on every incremental sync (merge mode)

1 participant