From 77113efe69ec9b765eb0b2cacef52d8a4953acae Mon Sep 17 00:00:00 2001
From: Trevor Simonton <trevor@westernascent.com>
Date: Wed, 7 Nov 2012 13:57:24 -0700
Subject: [PATCH 1/2] Issue #1833924 by tmsimont: Fixed handling of entity field parents on checkout registration form

---
 includes/commerce_registration.checkout_pane.inc |   22 +++++-----------------
 1 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/includes/commerce_registration.checkout_pane.inc b/includes/commerce_registration.checkout_pane.inc
index 594fe26..f014b6d 100755
--- a/includes/commerce_registration.checkout_pane.inc
+++ b/includes/commerce_registration.checkout_pane.inc
@@ -103,6 +103,11 @@ function commerce_registration_information_checkout_form($form, &$form_state, $c
             ':input[name="' . $find_name .'"]' => array('value' => REGISTRATION_REGISTRANT_TYPE_ANON),
           ),
         );
+        $form[$prodkey][$prodkey . '-reg-' . $i]['#parents'] = array(
+          'registration_information',
+          $prodkey,
+          $prodkey . '-reg-' . $i
+        );
         // Attach the entity's fields to the form.
         field_attach_form(
           'registration',
@@ -111,23 +116,6 @@ function commerce_registration_information_checkout_form($form, &$form_state, $c
           $form_state
         );
         $fields = &$form[$prodkey][$prodkey . '-reg-' . $i];
-        foreach ($fields as $key => $data) {
-          if (is_array($data) && drupal_substr($key, 0, 1) != '#') {
-            // We set the parents on just fields so we can find them in
-            // form_state later; fields in the form array don't start with a #.
-            $fields[$key]['#parents'] = array(
-              'registration_information',
-              $prodkey,
-              $prodkey . '-reg-' . $i,
-              $key,
-            );
-            // This allows the fields to work with Conditional Fields module.
-            $fields[$key][LANGUAGE_NONE]['#field_parents'] = $fields[$key]['#parents'];
-            // Remove the last value from the array (name of the field itself),
-            // as it is not a field parent for itself.
-            array_pop($fields[$key][LANGUAGE_NONE]['#field_parents']);
-          }
-        }
         // -------------------------------------------------------------------------
         $form['register_entities'][$prodkey][$i] = array(
           '#type' => 'value',
-- 
1.7.4.msysgit.0


From 73d87a4400fd23ad8ccc41eedcddd5d89f8e9901 Mon Sep 17 00:00:00 2001
From: Trevor Simonton <trevor@westernascent.com>
Date: Thu, 8 Nov 2012 10:01:16 -0700
Subject: [PATCH 2/2] Issue #1833924 by tmsimont: Removed commerce_registration_entity_update_fields() because it was corrupting entity field structure on checkout submission.

---
 includes/commerce_registration.checkout_pane.inc |   35 ----------------------
 1 files changed, 0 insertions(+), 35 deletions(-)

diff --git a/includes/commerce_registration.checkout_pane.inc b/includes/commerce_registration.checkout_pane.inc
index f014b6d..fe9fc07 100755
--- a/includes/commerce_registration.checkout_pane.inc
+++ b/includes/commerce_registration.checkout_pane.inc
@@ -253,8 +253,6 @@ function commerce_registration_information_checkout_form_validate($form, &$form_
 
 /**
  * Commerce checkout pane form submit callback.
- *
- * @see commerce_registration_entity_update_fields().
  */
 function commerce_registration_information_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {
   $order->data['register_entities'] = array();
@@ -295,11 +293,6 @@ function commerce_registration_information_checkout_form_submit($form, &$form_st
           $form['registration_information'][$prodkey][$prodkey . '-reg-' . $i],
           $form_state
         );
-        // We add the field values to our entity so they are stored properly.
-        commerce_registration_entity_update_fields(
-          $entity,
-          $form_state['values']['registration_information'][$prodkey][$prodkey . '-reg-' . $i]
-        );
         $order->data['register_entities'][$prodkey][$i] = $entity;
       }
     }
@@ -371,34 +364,6 @@ function commerce_registration_information_settings_form($checkout_pane) {
 }
 
 /**
- * Updates the attached entity with field values.
- *
- * Example $values array:
- * @code
- * $values = array(
- *   'field_passport' => array(
- *     'und' => array(
- *       0 => array('value' => 'MY FIELD VALUE')
- *     )
- *   )
- * );
- * @endcode
- *
- * @param stdClass $entity
- *   The referenced entity to update.
- * @param array $values
- *   Array of values to add to the entity.
- */
-function commerce_registration_entity_update_fields(&$entity, $values) {
-  if (empty($values)) {
-    return;
-  }
-  foreach ($values as $key => $value) {
-    $entity->$key = $value;
-  }
-}
-
-/**
  * Helper function to create a new registration for a product.
  *
  * @param int $product_id
-- 
1.7.4.msysgit.0

