We're using commerce for a small site that sells phrases that are printed on various types of products (t-shirts, pendants, etc). As such, in most cases more than one type of product is referenced by the product display node (the product display is a "phrase", and the products associated could be shirts with different sizes/colors, hats with colors only, etc). In Commerce currently, when the add to cart form encounters more than one type referenced by a product, it just defaults to displaying a simple select list with all the referenced products, since different product types may have different fields requiring choices (such as some with just color, some with color and size, etc).
I would propose providing an option (perhaps as part of the display field settings, much like where you choose whether or not to combine products when added to the cart) to allow managers to choose whether this default behavior is applied, or if the first field shown in the add to cart form should be a select list of product types referenced by the display node. Then the customer would first choose a product type, and then the cart form could proceed to build the form as if there was only one referenced product type instead of multiple. Then you keep the cool ajax product field selectors (such as size, color, etc) since the cart form only ever would work with one type of product at a time. This would be a major improvement when a display node may reference a large number of products from varying types, which provides a confusing UI for the customer since they have to pick from a super long list of products instead of the normal process where you make choices on product fields and Commerce selects the product to match those fields.
Hopefully my explanation hasn't made this super confusing! I've attached a pretty rough patch against 1.0 that I used to get it running on my project. It doesn't include the ability to choose the cart format as I suggested in the field settings above, but it does provide the suggested functionality in the add to cart form.
| Comment | File | Size | Author |
|---|---|---|---|
| commerce_cart_product_type.patch | 6.81 KB | stockliasteroid |
Comments
Comment #1
rszrama commentedWhat you're requesting sounds perfectly reasonable, though it's not going to be high on my priority list to review (I'm sure you understand : ). I'll have to consider whether it's good for inclusion post-1.0 or if it should wait for 2.x. Can the same functionality be achieved via a contributed module aside from duplicating the entire Add to Cart form widget?
Comment #2
stockliasteroid commentedThanks for checking it out!
I looked at doing it via form_alter, but that looked like it was going to be pretty gnarly due to the ajax form rebuilds, etc. It could also probably be accomplished via another formatter that wraps the existing add to cart form, though. I'll check that out in a bit when I have some time.
We'll maintain this patch against our own code for now, but this definitely seems like a useful core improvement if you're going to allow people to associate varying product types with the product reference field, since it keeps the "magic" add to cart form alive with varying product fields ;)...
Comment #3
bojanz commentedToo late to do this in 1.x.
2.x doesn't allow variations of different types on the same add to cart form.