Problem/Motivation

When the "Vado group add to cart" form display is set to show the "Product variation attributes" widget, the group selected options don't reset after attribute selection change.

This is a problem, for example when unchecking the add on options, that are set to default on/enabled, and changing a product attribute, the price field displays the full calculated price, but the group options appear unselected.

Additionally, when adding that product variation to the cart, the "unselected" add on options will also be added.

Other than this issue (fixed with this small patch), using the product attributes widget appears to work well.

Steps to reproduce

  1. Set the order item type "Vado group add to cart" form display "Purchased entity" to use the "Product variation attribution" widget.
  2. Add a group with checkboxes (default enabled) to the product variation.
  3. When changing the product attributes, the group options to not clear/reset.

Proposed resolution

There is already a "TODO" comment in the related group add to cart form code.

// @todo currently only supports the variation title widget, not attributes.

Implement that TODO and reset the group add to cart form fields when the product attributes change.

Remaining tasks

MR patch incoming.

User interface changes

When using the group add to cart form and the product variation attributes widget, when changing the product attributes, the group selection will reset to the default configuration.

API changes

N/A

Data model changes

With thanks for the useful module!

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

davidwhthomas created an issue. See original summary.

davidwhthomas’s picture

Title: Clear group add to cart form options with product attributes change » Reset group add to cart form options to default when product attributes change

davidwhthomas’s picture

Status: Active » Needs review
tonytheferg’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for posting. Seems simple enough. NW as this will need test coverage before adding.

davidwhthomas’s picture

Thanks for checking.

I had a look earlier and couldn't find any existing tests related to, for example the group add to cart form and clearing the group widget on product variation title selection change.
As the MR passed the existing pipeline tests, I have assumed this minor update is ok there.
However, do you have any recommendation on where such a test would best be added?

tonytheferg’s picture

I'm away from the office currently, but I'm not basing the requirement of needing tests off existing tests, but rather establishing the support of attributes. Currently the module doesn't claim to support attributes, so if we do offer to support attributes, it needs test coverage.

davidwhthomas’s picture

Fair enough. FWIW in the meantime. Other than the group add to cart form widget not resetting to default when the product attribute selection changes (fixed with this patch), the commerce_vado module appears to work well when using the product attribute widget for the product variation selection.

davidwhthomas’s picture

Issue summary: View changes

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

joshmiller’s picture

Status: Needs work » Reviewed & tested by the community

Added the test coverage tonytheferg asked for in #5 and pushed it to the MR branch (with 3.0.x merged in first, no conflicts):

tests/src/Functional/VadoGroupAttributesTest: a product with a Color attribute (Red/Blue variations, both referencing a checkboxes group that has one default item), rendered with the group add to cart form and the commerce_product_variation_attributes widget. The test changes the colour and the group selection, triggers the attribute element the way the widget's #ajax does (a POST carrying _triggering_element_name, so no JavaScript test is needed) and asserts that the variation switches while the group selection falls back to its default. A second step triggers a group checkbox itself and asserts the customer's selection is kept, so the reset only fires for attribute changes.

The test fails on 3.0.x without the MR change (the default group item is not re-checked after the attribute change) and passes with it; the MR pipeline is green. Drafted with AI assistance (Claude), reviewed and run locally by me on Drupal 11.4.6 / Commerce 3.3.9.

Marking RTBC. Thanks davidwhthomas.

  • joshmiller committed 15d4d1bf on 3.0.x
    Issue #3525364 by davidwhthomas, joshmiller: Reset group add to cart...
joshmiller’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 3.0.x as 15d4d1b (squashed, credit to davidwhthomas and joshmiller). Attributes on the group add to cart form are now covered by a test, so the widget is officially supported from the next release after 3.0.3. 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.

davidwhthomas’s picture

Thanks!!

tonytheferg’s picture

Docs probably need updated as the scope has grown.