Follow-up to #3635025: ProductVariationAttributeMapper::prepareAttributes() is quadratic in the number of attributes and throws for mixed variation types.

Problem/Motivation

ProductVariationAttributeMapper::selectVariation() calls getAttributeValueId() for every submitted attribute value on every variation. When a product has variations of more than one type, a variation that lacks one of the submitted attribute fields makes getAttributeValueId() throw InvalidArgumentException: Unknown attribute field name. This happens when the add-to-cart form is rebuilt (AJAX attribute change) or submitted.

Proposed resolution

As in #3635025, read each variation's attribute values once with getAttributeValueIds() and compare with $values[$field_name] ?? NULL, stopping at the first mismatch. A variation without an attribute is treated as not matching it.

Remaining tasks

  • Kernel test for mixed variation types.

API changes

None.

Issue fork commerce-3635059

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jsacksick created an issue. See original summary.

  • jsacksick committed 18b386d1 on 3.x
    fix: #3635059 ProductVariationAttributeMapper::selectVariation() throws...
jsacksick’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.