Currently to assign a product attribute to a product variation type you must create an entity reference field that references "Product attribute value", and select the right attribute (Color, size, etc) on the field settings page.
We can make this easier. When you add/edit the product variation type, right on that form we can provide a set of "Product attribute" checkboxes.
Selecting or deselecting Size, Color, etc will create or delete* the appropriate field.
We don't need to store this list on the product type, we can figure it out based on those type's field definitions.
* - We'll refuse to unselect an attribute if the field already has data inside.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff-9-4.txt | 1.59 KB | mglaman |
#10 | allow_product-2689519-10.patch | 6.23 KB | mglaman |
#9 | Edit_Default___Site-Install.png | 59.12 KB | mglaman |
#4 | attributes-variation-form2.png | 105.22 KB | bojanz |
#4 | attributes-variation-form1.png | 82.29 KB | bojanz |
Comments
Comment #2
Londova CreditAttribution: Londova commentedThis is exactly I was looking for.
Comment #3
bojanz CreditAttribution: bojanz commented#2690685: Create an attribute field manager has added the API for this ($attibute_field_manager ->createField(), canDeleteField(), deleteField()), what remains is for ProductVariationTypeForm to use it.
I'll go ahead and do that.
Comment #4
bojanz CreditAttribution: bojanz commentedHere's a working patch.
Looking for visual feedback.
- Is "Attributes" enough for the label? Do we need a description?
- Is there a better wording for the error message shown when there are already variations with that attribute?
Comment #5
mglamanWe should disable it, so they do not have the option to even uncheck it.
Which means we maybe need a description describing the "once added with data, cannot be removed."
Comment #6
bojanz CreditAttribution: bojanz commentedWe can't disable one checkbox out of a set.
Comment #7
bojanz CreditAttribution: bojanz commentedOkay, mglaman confirmed he knows a way. That + a small extension of the ProductVariationTypeFormTest and we're good to go.
Comment #8
skyredwangI tested #4 patch, it works beautifully. Please merge?
Comment #9
mglamanHere is my enhancement that disabled checkboxes which have fields which are not deletable.
Comment #10
mglamanHere is a revised version, and interdiff from #4.
Comment #12
mglamanFix. 821711d had test regression, committed fix to make tests pass.
Comment #13
bojanz CreditAttribution: bojanz commentedCompared to #10 I made the following changes:
1) The #disabled check crashed if only some of the fields were used, since it would pass a non-used field to canDelete().
2) The attribute checkboxes element was not hidden when there are no attributes.
3) The validateForm logic was unneeded with the new #disabled handling.
(Comment was pending until I fixed the tests, Matt figured it out first)
Comment #15
rei CreditAttribution: rei commentedany chance to port this to commerce 1.x ?
Comment #16
mglamanNo, because in 1.x attributes are a field setting when using a List or Reference field.