We are factoring in attribute dependencies when deciding on attribute values. However, we are not following this when selecting the default variation from user input during AJAX operations.

Giffy example.

| Color   |  Size        |
| Blue     |  Small     |
| Black    |  Small     |
| Blue     |  Medium |
| Blue     |  Large     |

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new2.43 KB

PR: https://github.com/drupalcommerce/commerce/pull/342

This ensures we respect attribute dependencies and do not consider variations which do not have matching attributes as we cascade downward.

mglaman’s picture

Issue summary: View changes
StatusFileSize
new68.9 KB

This also preserves any matching attribute selection. Resolving the problem reported in #1286244: Allow dependent attributes to preserve their default options if a matching product exists on an Add to Cart form in 2.x

bojanz’s picture

Status: Needs review » Fixed

Committed, big thanks!

  • bojanz committed 3201dda on 8.x-2.x authored by mglaman
    Issue #2675836 by mglaman: Variation is not properly factoring attribute...
bojanz’s picture

Status: Fixed » Needs work

Reverted.

If you create Red, Blue and Small, Medium attributes, and a variation for each combination, then the new logic will filter by color, then select the first size (Small), making it impossible to ever buy Medium. The tests pass by accident, since there's only one size for the tested Blue color.

  • bojanz committed e96fd59 on 8.x-2.x
    Revert "Issue #2675836 by mglaman: Variation is not properly factoring...
bojanz’s picture

StatusFileSize
new10.64 KB

The reverted patch.

mglaman’s picture

Assigned: Unassigned » mglaman

WOrking on improving the cart and attribute tests.

bojanz’s picture

Title: Variation is not properly factoring attribute dependencies when selecting from user input » Expand the add to cart form test coverage
Category: Bug report » Task

mglaman was unable to repeat the bug in the most recent code, but expanded the tests to ensure it doesn't come back:
https://github.com/drupalcommerce/commerce/pull/359

  • bojanz committed 4209736 on 8.x-2.x authored by mglaman
    Issue #2675836 by mglaman, bojanz: Expand the add to cart form test...
bojanz’s picture

Status: Needs work » Fixed

Committed.

londova’s picture

From my experience, the system sets the Colour as primary attribute and the Size as secondary. How to change their order? Is there any way to change/setup SIZE as primary attribute and COLOUR as secondary?

I wasn't able to make the price changing while changing the attributes (Add to Cart). What I did wrong?

mglaman’s picture

British-Link, I think if you just re-arrange them on the variants form display.. it might. However I'm not sure. Want to open a follow up for controlling the order of attributes? We can discuss it there. If its a support item, we can open a follow up on https://github.com/drupalcommerce/commerce-docs to add it to the docs.

londova’s picture

Changing the order on Variants Form Display doesn't have any effect. In my case, the Size is listed as first/upper variant on Form Display and the Color being on second place. However the Add to Cart form will display the Colour as first variant and the Size as second.

I am 100% sure we need facility to control the order of the attributes.
Should I register this as a separate issue?

agoradesign’s picture

I would say: yes, this is a bug and should be listed as a separate issue. This sounds similar, but still different, as #2691591: ProductVariationStorage::loadEnabled() does not respect field delta, returning items unsorted. I guess, that here also the attributes are queried and/or filtered in a way, that does not respect the weight of the form display configuration

bojanz’s picture

You are right. Opened an issue #2699019: Can't change the ordering of attributes with our options. Please provide feedback.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.