Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have created a product attribute which contains two attributes.
One is called spicy and the other is called size. The spicy is a checkbox which contains three attributes and the size is a select list.
When I add a product and select attributes of spicy, the VARIATIONS TITLE only shows the first choice of spicy.
Comment | File | Size | Author |
---|---|---|---|
#16 | commerce-2927708-attributes_cardinality-16.patch | 1.1 KB | czigor |
| |||
#6 | 2927708-1.patch | 1.01 KB | elicxh |
#3 | wrong3.png | 7.74 KB | elicxh |
wrong1.png | 35.02 KB | elicxh |
Comments
Comment #2
elicxh CreditAttribution: elicxh commentedComment #3
elicxh CreditAttribution: elicxh commentedComment #4
elicxh CreditAttribution: elicxh commentedComment #5
drugan CreditAttribution: drugan as a volunteer commentedNeeds work status is for patches. There is no any patch contributed (and tested to detect the work need).
Also, notice that each product variation it is a unique combination of IDs of all attributes on a given product. So, what you are trying to achieve is to place two combinations (variations) on the one variation at once. Obviously, that machine refuses to understand this.
I'd recommend to always choose select widget for the attributes form display. Though the checkboxes also should work if you never check both Extraspicy and Mediumspicy at once.
Comment #6
elicxh CreditAttribution: elicxh commentedComment #7
skyredwangOne commerce_product_variant can have multiple commerce_product_attribute_values from the same commerce_product_attribute. I think this is a supported use case in DC2.
Comment #8
drugan CreditAttribution: drugan as a volunteer commentedYes, but each attribute on a product variation must give only one value (ID) or NULL or - None - if the attribute is optional field. Actually, the - None - value is also a choice on the attribute, but you can't get it in the current Drupal Commerce without additional code customizations. So, taking one and only one attribute value from each attribute on a product variation we need to get a unique combination of the values (Extraspicy+Large, Mediumspicy+Large, Smallspicy+Large, Extraspicy+Tiny, Mediumspicy+Tiny, Smallspicy+Tiny, etc..)
Think of it in a practical way. Let say you make offer for a customer to buy a t-shirt of size M and having red and green color simultaneously.
What?
Comment #9
skyredwang@drugan sounds like you are saying #7 is not a supported use case. I am fine with that if that's the fact. Then, the remaining of this issue is to remove the "checkbox" form widget, because "checkbox" implies multiple selection.
Comment #10
drugan CreditAttribution: drugan as a volunteer commentedI agree, the checkbox widget for adding/editing variations might confuse some people. Actually, it was also me when I've started to explore Drupal Commerce. The radios widget is enough for those who want all attribute values visually displayed in the form.
But this is hardly might be fixed just because there are a lot of other widgets to choose from. You may create your own fancy widget for making awesome things and it will be displayed in the list, too. So, it is up to admin to decide which is appropriate for their needs.
Comment #11
elicxh CreditAttribution: elicxh commentedThanks a lot for your advice.
The "checkbox" and the "radio buttons" are the same choice in widget form.If someone wants to use the checkbox widget , the settings of "Allowed number of values" must be changed in the Product variation types. Is it possible to lock "number of values" and mention users taking one and only one attribute value from each attribute .
Comment #12
bojanz CreditAttribution: bojanz at Centarro commentedRetitling to clarify what we need to do (as summarized in #11)
Comment #13
czigor CreditAttribution: czigor at Centarro commentedWhat about disabling the cardinality fields on the field UI?
Comment #14
czigor CreditAttribution: czigor at Centarro commentedI mean like this.
Comment #15
bojanz CreditAttribution: bojanz at Centarro commentedWe can shorten this to:
Is there any benefit to #disabled => TRUE instead of #access => FALSE? Do we have a preference on disabling VS hiding?
Comment #16
czigor CreditAttribution: czigor at Centarro commentedMy personal preference is #disabled over #access. It's less confusing to see the same form with some form elements being #disabled by someone than wondering if this is a different form or what happened to the cardinality setting. But I get confused easily. Anyway, #access FALSE makes the code 3 lines shorter, so I switched to that.
Note that in case we're adding the attribute value reference field manually to a variation, the cardinality field will still be there. Only the edit form is affected.
Comment #17
bojanz CreditAttribution: bojanz at Centarro commentedTweaked the alter to always set the cardinality value to 1, therefore ensuring that the form self-corrects.
Thanks!