Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Product reference
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Aug 2010 at 16:01 UTC
Updated:
24 Jul 2012 at 20:10 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rszrama commentedJust a quick note on this... I've taken a two step approach. I've already committed a change that will use the first value from a multiple value product reference field to pull product fields into the node for display. The Add to Cart form uses this manner of selecting a default right now, too.
The second step, yet to be committed, is to have the Add to Cart form update these fields based on the currently selected product as the customer chooses attributes. This is actually working, but I don't have a generic solution in place to accommodate different contexts for the Add to Cart form (i.e. tell the form what node it is being embedded on). That should be a quick bit of work in the morning and then this will be committed.
It's too exciting not to share, though, and I think these pictures are worth a thousand words. First we have an image of a product display node that references each of the products in my test site. These products have a size field that the Add to Cart form uses to generate product selection widgets instead of just a product title select list:
When the new size is selected, the Add to Cart form refreshes via #ajax with a new default product. We return a set of AJAX replacement commands to re-render the product fields on the page using the new product:
Once I get the context issue sorted out, I'll do another commit, and then I'll make this a little more performant (i.e. only rendering fields that are actually shown, since that's one of the most expensive processes in Drupal).
Comment #2
rszrama commentedThis is now working and just needs some further testing to root out any bugs. Relevant commits:
https://github.com/rszrama/drupalcommerce/commit/f08c544f00dd4cd53eb7c70...
https://github.com/rszrama/drupalcommerce/commit/88b2050b6220ae1d02d0d0f...
https://github.com/rszrama/drupalcommerce/commit/b55fbc4068ccf33ef978ea8...
This was held up for quite a while by the fact that I was doing a full form replacements when the AJAX callback function was called. The problem with re-rendering the whole form is that the ID that I was using to target the form for replacement was being incremented each time by drupal_html_id(), so it turns out I had to duplicate the id in the class of the form and target it by that.
We'll see how this plays out in real use. The only remaining question is what to do if Javascript is off...
Would appreciate anyone's review and feedback.
Comment #3
rszrama commentedJust added support for dependent attributes. Also, I need feedback on this idea... when an attribute select list only has one option, I'm thinking I should disable it so that it's clear the customer doesn't need to choose anything but the information will still be visible in the form. Anyone think otherwise? The only viable alternative I can think of is to leave it enabled with a single value, which is just a little confusing.
Commit (here be dragons): https://github.com/rszrama/drupalcommerce/commit/8b51609383e7c332f45df39...
Comment #4
rszrama commentedI'm attaching a patch so you can test out what it looks like when an attribute select list has only a single option available. Without the patch it will render as a normal select list with a single option. With the patch it will render as a disabled select list in which the single option is still visible.
To get the full benefit, you'll need to configure a product type with two fields that qualify as attribute fields for the Add to Cart form (i.e. a List type field that is required and single value with a definite set of options). Then make products for each option of the first field that have any option for the second field. Then make another product or two that reuse some of the first field's options but use different options for the second field than their counterparts. Fiddle around with it... I'll need to rebuild our demo to show these things off so it's easier to discuss. : P
Comment #5
rszrama commentedActually, I think it's probably better to leave the single option if it exists. Disabled form elements have their own FAPI and usability problems... best to leave it alone for now. This one was done a long time ago, just putting the fork in it.
Comment #7
bogdan1988 commentedTo display node previews in add to cart form you can use information from here. http://html-and-cms.com/blog/drupal-commerce-add-cart-form-alter-enablin...
Comment #8
rszrama commentedThanks for putting together the little snippet. You might also check out http://drupal.org/project/commerce_add_to_cart_extras which allows you to use Views to create a display formatter for a product reference field that adds multiple products to the cart at once. Not the same as your patch, but perhaps that module could be enhanced to allow the View to provide the options for a radio select list instead.