Add a product type setting, a checkbox, titled "Allow each product to have multiple variations", enabled by default.
When on, the current Variations tab is shown.
When off, a new "commerce_product_single_variation" ("Single variation (Product information)") widget is used for the variations field. In that case, the Variations tab is hidden, as is the "Save and add variations" button. Toggling the checkbox toggles the widget.
The single variation widget shows the variation form inside a "Product information" collapsible fieldset (since "Variations" doesn't make sense as a title when there's always only one variation). We can use the IEF form element for now.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2690681-17.patch | 18.99 KB | bojanz |
|
Comments
Comment #2
johnstorey CreditAttribution: johnstorey commentedBojanz - if there is no objection, I'd like to take a shot at this.
Comment #3
rszrama CreditAttribution: rszrama at Centarro commentedGo for it! : )
Comment #4
johnstorey CreditAttribution: johnstorey commented@Bojanz,
After a couple of hours, the validation seems straightforward enough. Let me know if you see an issue with my plan
I don't see that part of the issue as being too complex, but I'm digging into the Commerce 2.x code for the first time. Am I missing some subtle point?
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedThe validation needs to be in a ConstraintValidator class, Form API invokes the entity validation automatically.
Comment #6
johnstorey CreditAttribution: johnstorey commentedAh, total bad thinking on my part. I see what you are thinking. I was adding the constraint when the product variation was being created, when I can just put it on the product creation form. I don't see that as elegant, but from a code point of view, it is easier to accomplish.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedYou don't need to touch the form at all. The constraint & constraint validator do all the work.
Comment #8
deadbeef CreditAttribution: deadbeef commentedIf this is enforced, how would you handle a product that is, for example, a charitable donation - where the only varying attribute is a range of fixed amounts?
Comment #9
bojanz CreditAttribution: bojanz at Centarro commentedRight, we might need to make this configurable on the product type.
Comment #10
sumanthkumarc CreditAttribution: sumanthkumarc at Azri Solutions commented@bojanz i see the variations field is locked in product type entity. So as you said, can we add a number field in product type form at Drupal\commerce_product\Form\ProductTypeForm form method and in submit, i see
so commerce_product_add_variations_field() function adds a cardinality of unlimited to variations field. Do we need to pass the cardinality, so that user can set it? also should we allow only once on initial creation for changing the cardinality?
Comment #11
SpartyDan CreditAttribution: SpartyDan commentedSprinting at DC Baltimore.
Comment #12
SpartyDan CreditAttribution: SpartyDan commentedComment #13
bojanz CreditAttribution: bojanz at Centarro commentedRetitling.
We need a product type setting, defaulting to true, that says "Allow each product to have multiple variations" or something similar.
Comment #14
bojanz CreditAttribution: bojanz at Centarro commentedInitial work. Needs more tests.
Comment #15
bojanz CreditAttribution: bojanz at Centarro commentedUpdating the summary.
Comment #17
bojanz CreditAttribution: bojanz at Centarro commentedCommitted the final version.