--- commerce-edit-attributes-1211278-77.patch	2015-08-10 13:26:56.000000000 -0400
+++ 1211278-78.update_cart_attributes.patch	2015-08-10 13:26:41.000000000 -0400
@@ -11,10 +11,10 @@ index d7195fc..a59be05 100644
  files[] = includes/views/handlers/commerce_cart_handler_area_empty_text.inc
  
 diff --git a/modules/cart/commerce_cart.module b/modules/cart/commerce_cart.module
-index 77c90f8..93b2e11 100644
+index 77c90f8..2faa77f 100644
 --- a/modules/cart/commerce_cart.module
 +++ b/modules/cart/commerce_cart.module
-@@ -2369,6 +2369,16 @@ function commerce_cart_add_to_cart_form_attributes_refresh($form, $form_state) {
+@@ -2369,6 +2369,31 @@ function commerce_cart_add_to_cart_form_attributes_refresh($form, $form_state) {
  }
  
  /**
@@ -23,7 +23,22 @@ index 77c90f8..93b2e11 100644
 + */
 +function commerce_cart_add_to_cart_views_form_refresh($form, $form_state) {
 +  $commands[] = array();
-+  $commands[] = ajax_command_replace('.' . drupal_html_class('commerce-line-item-views-form'), drupal_render($form));
++
++  // Extract the View from the form's arguments and derive its DOM ID class.
++  $view = $form_state['build_info']['args'][0];
++  $dom_id_class = drupal_html_class('view-dom-id-' . $view->dom_id);
++
++  // Unset the form related variables from the $_POST array. Otherwise, when we
++  // rebuild the View, the Views form will fetch these values to rebuild the
++  // form state and resubmit the form.
++  foreach (array('form_build_id', 'form_token', 'form_id') as $key) {
++    unset($_POST[$key]);
++  }
++
++  // Render afresh the the output of the View and return it for replacement.
++  $output = commerce_embed_view($view->name, $view->current_display, $view->args, $view->override_url);
++  $commands[] = ajax_command_replace('.' . $dom_id_class, $output);
++
 +  return array('#type' => 'ajax', '#commands' => $commands);
 +}
 +
@@ -53,10 +68,10 @@ index 4ced3f0..8d4b909 100644
  /**
 diff --git a/modules/cart/includes/views/handlers/commerce_cart_handler_field_edit_attributes.inc b/modules/cart/includes/views/handlers/commerce_cart_handler_field_edit_attributes.inc
 new file mode 100644
-index 0000000..9e39c7b
+index 0000000..6fca73b
 --- /dev/null
 +++ b/modules/cart/includes/views/handlers/commerce_cart_handler_field_edit_attributes.inc
-@@ -0,0 +1,107 @@
+@@ -0,0 +1,132 @@
 +<?php
 +
 +/**
@@ -67,6 +82,9 @@ index 0000000..9e39c7b
 +
 +class commerce_cart_handler_field_edit_attributes extends views_handler_field {
 +
++  /**
++   * Overrides views_handler_field::construct().
++   */
 +  function construct() {
 +    parent::construct();
 +    $this->additional_fields['line_item_id'] = 'line_item_id';
@@ -75,7 +93,11 @@ index 0000000..9e39c7b
 +    $this->real_field = 'line_item_id';
 +  }
 +
++  /**
++   * Overrides views_handler_field::render().
++   */
 +  function render($values) {
++    // Render the field as a placeholder for eventual Views form replacement.
 +    return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
 +  }
 +
@@ -100,6 +122,11 @@ index 0000000..9e39c7b
 +      $product_ids = commerce_cart_add_to_cart_form_product_ids($line_item);
 +      $form_id = commerce_cart_add_to_cart_form_id($product_ids);
 +
++      // Ensure the current line item is a product line item.
++      if (!in_array($line_item->type, commerce_product_line_item_types())) {
++        continue;
++      }
++
 +      // Fetch the Add to Cart form and put the attributes section into this
 +      // field's part of the form if it exists.
 +      $subform_state = $form_state;
@@ -121,15 +148,28 @@ index 0000000..9e39c7b
 +      $subform = commerce_cart_add_to_cart_form($subform, $subform_state, $line_item);
 +
 +      // If an Ajax refresh resulted in an updated product ID, update the line
-+      // item accordingly and rebuild the subform.
++      // item accordingly and rebuild the subform. Note that for line items
++      // that group products such that a product select list is required, we
++      // have to fetch the current product ID differently than if it is stored
++      // in a hidden form field.
 +      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
 +
-+      if(isset($subform['product_id']['#value'])) {
-+        if ($subform['product_id']['#value'] != $line_item_wrapper->commerce_product->raw()) {
-+          $line_item_wrapper->commerce_product = $subform['product_id']['#value'];
-+          $line_item_wrapper->save();
-+          $form_state['rebuild'] = TRUE;
++      if (!empty($subform['product_id'])) {
++        $product_id = NULL;
++
++        if (in_array($subform['product_id']['#type'], array('hidden', 'value'))) {
++          $product_id = $subform['product_id']['#value'];
++        }
++        else {
++          $product_id = $subform['product_id']['#default_value'];
++        }
++
++        if (isset($product_id) && $product_id != $line_item_wrapper->commerce_product->raw()) {
++          $line_item_wrapper->commerce_product = $product_id;
++          commerce_line_item_save($line_item);
++          commerce_cart_order_refresh($line_item->order_id);
 +
++          // Rebuild the subform array.
 +          $subform_state = $form_state;
 +          $subform_state['build_info'] = array(
 +            'form_id' => $form_id,
@@ -164,4 +204,3 @@ index 0000000..9e39c7b
 +    }
 +  }
 +}
-\ No newline at end of file
