Problem/Motivation

Since #3089040: Single product with multiple variation types, AddToCartForm::setFormDisplay() (modules/cart/src/Form/AddToCartForm.php, lines 156-178) switches the purchased entity widget from commerce_product_variation_attributes to commerce_product_variation_title as soon as a product's enabled variations span more than one variation type.

That fallback is needed when the variation types have different attribute fields. But it also applies when every type has exactly the same attribute fields. In that case the attributes widget works unchanged: ProductVariationAttributeMapper already selects across variation types when the attribute field names match.

Example: a product sold as "1 year" and "1-month trial". The two variations use separate variation types only because a per-type setting differs (e.g. Commerce License's allow_renewal), and both types carry the same attribute_plan field. Customers get a select list of variation titles instead of the plan radios.

Steps to reproduce

  1. Create a product attribute "Plan" with the values "Year" and "Trial", and set its element type to radios.
  2. Create a second product variation type that uses the same order item type as the default one, and add the "Plan" attribute to both variation types.
  3. Allow both variation types on the default product type.
  4. Create a product with one variation of each type, "Year" and "Trial".
  5. View the product: the add to cart form shows a select list of variation titles instead of the "Plan" radios.

Proposed resolution

Only fall back to the title widget when the variation types do not share their attribute fields. Keep the attributes widget when every variation type used by the product's enabled variations:

  • has the same attribute fields, in the same order, and
  • uses the same order item type.

Products with a single variation type, and products whose variation types differ, keep the current behavior.

Remaining tasks

  • Review the merge request: the change in AddToCartForm::setFormDisplay() and a kernel test covering both cases (shared attributes keep the attributes widget, different attributes fall back to the title widget).

User interface changes

Products with mixed variation types that share their attribute fields show the attribute widgets instead of the variation title select list.

API changes

None. AddToCartForm gets a new protected $attributeFieldManager property and a protected variationTypesShareAttributes() method.

Data model changes

None.

Issue fork commerce-3629640

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

zaporylie created an issue. See original summary.

jsacksick made their first commit to this issue’s fork.

  • jsacksick committed 0ad5ed3d on 3.x authored by zaporylie
    feat: #3629640 Keep the attributes widget when a product's variation...
jsacksick’s picture

Status: Active » Fixed

Implemented a different approach and merged, thanks!

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.