Skip to content

Fix hub product variants mapping unmatched permutations to first SKU - #2593

Open
wychoong wants to merge 1 commit into
lunarphp:1.4from
wychoong:fix/map-variants-false-index
Open

Fix hub product variants mapping unmatched permutations to first SKU#2593
wychoong wants to merge 1 commit into
lunarphp:1.4from
wychoong:fix/map-variants-false-index

Conversation

@wychoong

@wychoong wychoong commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a bug in MapVariantsToProductOptions where unmatched cartesian option permutations were incorrectly bound to the first product variant.
  • Cause: collect()->search() returns false on no match, and PHP coerces $variants[false] to $variants[0].
  • With fillMissing: false (used by the Product Options / Variants hub widget), unmatched permutations are now skipped instead of inventing mislabelled rows.
  • Adds regression coverage for sparse option matrices and for fillMissing: true leaving unmatched rows without an existing SKU.

Reproduction

On a product with shared options and a non-cartesian variant matrix (for example Size/Colour/Length combinations that do not all exist), /hub/products/{id}/variants could show the first SKU under the wrong option labels.

Test plan

  • Added Pest unit coverage in MapVariantsToProductOptionsTest
  • Run ./vendor/bin/pest tests/admin/Unit/Actions/Products/MapVariantsToProductOptionsTest.php
  • Confirm /hub/products/{id}/variants Option column matches each variant’s pivot values for a sparse shared-option product

When collect()->search() finds no match it returns false, and PHP coerces
$variants[false] to $variants[0], so sparse option matrices steal the first
variant's SKU. Only map real matches, and skip unmatched rows when fillMissing is false.

Co-authored-by: Cursor <cursoragent@cursor.com>
@wychoong
wychoong force-pushed the fix/map-variants-false-index branch from f0878c7 to a057cfb Compare August 4, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant