diff -upPr uc_salesforce-HEAD/README.txt uc_salesforce/README.txt
--- uc_salesforce-HEAD/README.txt	2010-02-23 09:52:01.000000000 -0500
+++ uc_salesforce/README.txt	2010-10-06 14:54:27.000000000 -0400
@@ -14,7 +14,7 @@ OpportunityContactRole objects connect O
 
 If you have multiple Order Products in a single order, these can be mapped independently now, and will be associated with the Order (if you set that up in the Fieldmap).
 
-If you use the OpportunityContactRole, you need to create a custom node type (you may call it whatever you want, but I use "opportunity_contact_role"), and add a CCK field of type "text" to it. The field must be named "order_id" (so it ends up being called "field_order_id").
+If you choose to automatically synch OpportunityContactRoles, uc_sf_order will use the content type "Opportunity Contact Role" that ships with this module. Most users will not need to change any of the fields on this content type, nor edit the default fieldmap.
 
 Make sure to go to the Salesforce settings page, and choose the appropriate "Ubercart Integration" fieldmaps for use, after they have been defined, and to check the appropriate checkboxes.
 
diff -upPr uc_salesforce-HEAD/uc_sf_order/uc_sf_order.defaults.inc uc_salesforce/uc_sf_order/uc_sf_order.defaults.inc
--- uc_salesforce-HEAD/uc_sf_order/uc_sf_order.defaults.inc	1969-12-31 19:00:00.000000000 -0500
+++ uc_salesforce/uc_sf_order/uc_sf_order.defaults.inc	2010-10-06 14:54:27.000000000 -0400
@@ -0,0 +1,76 @@
+<?php 
+
+function _uc_sf_order_node_info() {
+  $items = array(
+    'opportunity_contact_role' => array(
+      'name' => t('Opportunity Contact Role'),
+      'module' => 'node',
+      'description' => t('Opportunity Contact Role is used for Ubercart SalesForce integration.'),
+      'has_title' => FALSE,
+      'title_label' => '',
+      'has_body' => FALSE,
+      'body_label' => '',
+      'min_word_count' => '0',
+      'help' => '',
+      'node_options' => array(
+          'status' => FALSE,
+          'promote' => FALSE,
+          'sticky' => FALSE,
+          'revision' => FALSE,
+  )));
+  return $items;
+}
+
+function _uc_sf_order_content_default_fields() {
+  $fields = array();
+  $fields[] = array(
+    'label' => 'Ubercart Order ID',
+    'field_name' => 'field_order_id',
+    'type_name' => 'opportunity_contact_role',
+    'type' => 'text',
+    'widget_type' => 'text_textfield',
+    'widget_active' => '1',
+    'weight' => '31',
+    'active' => '1',
+    'rows' => 1,
+    'size' => '60',
+    'description' => '',
+    'default_value_php' => '',
+    'default_value_widget' => NULL,
+    'required' => 0,
+    'multiple' => '0',
+    'text_processing' => '0',
+    'max_length' => '',
+    'allowed_values' => '',
+    'allowed_values_php' => '',
+    'module' => 'text',
+    'widget_module' => 'text',
+    'columns' => array('value' => 
+      array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => false,
+        'sortable' => FALSE,
+        'views' => true,
+      )),
+    'display_settings' => array(
+      'weight' => 0,
+      'parent' => '',
+      'label' => array(
+        'format' => 'above',
+        'exclude' => 0,
+      ),
+      'teaser' => array(
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+      'full' => array(
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+      'token' => array(
+        'format' => 'default',
+        'exclude' => 0,
+      )));
+  return $fields;
+}
diff -upPr uc_salesforce-HEAD/uc_sf_order/uc_sf_order.info uc_salesforce/uc_sf_order/uc_sf_order.info
--- uc_salesforce-HEAD/uc_sf_order/uc_sf_order.info	2010-02-21 22:11:21.000000000 -0500
+++ uc_salesforce/uc_sf_order/uc_sf_order.info	2010-10-06 14:57:10.000000000 -0400
@@ -4,6 +4,7 @@ name = Ubercart Salesforce Order
 description = Integrates the ubercart order with the Salesforce API.
 dependencies[] = salesforce_api
 dependencies[] = uc_order
+dependencies[] = content
 package = Salesforce
 core = 6.x
 
diff -upPr uc_salesforce-HEAD/uc_sf_order/uc_sf_order.install uc_salesforce/uc_sf_order/uc_sf_order.install
--- uc_salesforce-HEAD/uc_sf_order/uc_sf_order.install	1969-12-31 19:00:00.000000000 -0500
+++ uc_salesforce/uc_sf_order/uc_sf_order.install	2010-10-06 14:54:27.000000000 -0400
@@ -0,0 +1,27 @@
+<?php 
+
+function uc_sf_order_enable() {
+  // To avoid hard dependency on features module, this is lifted from
+  // features.content.inc::content_features_rebuild
+  module_load_include('inc', 'content', 'includes/content.crud');
+  module_load_include('inc', 'uc_sf_order', 'uc_sf_order.defaults');
+  content_clear_type_cache(TRUE);
+  $fields = _uc_sf_order_content_default_fields();
+  foreach ($fields as $field) {
+    $existing_field = content_fields($field['field_name']);
+    $existing_instance = content_fields($field['field_name'], $field['type_name']);
+    if ($existing_field && $existing_instance) {
+      content_field_instance_update($field, FALSE);
+    }
+    else {
+      content_field_instance_create($field, FALSE);
+    }
+  }
+  variable_set('menu_rebuild_needed', TRUE);
+}
+
+function uc_sf_order_update_1() {
+  uc_sf_order_enable();
+  return array(array('success' => TRUE, 'query' => 'Added CCK fields to "Opportunity Contact Role" content type.'));
+}
+
diff -upPr uc_salesforce-HEAD/uc_sf_order/uc_sf_order.module uc_salesforce/uc_sf_order/uc_sf_order.module
--- uc_salesforce-HEAD/uc_sf_order/uc_sf_order.module	2010-03-08 22:03:40.000000000 -0500
+++ uc_salesforce/uc_sf_order/uc_sf_order.module	2010-10-06 15:12:42.000000000 -0400
@@ -31,12 +31,17 @@ function uc_sf_order_perm() {
 }
 
 /**
+ * Implementation of hook_node_info
+ */
+function uc_sf_order_node_info() {
+  require_once drupal_get_path('module', 'uc_sf_order') . '/uc_sf_order.defaults.inc';
+  return _uc_sf_order_node_info();
+}
+
+/**
  * Implementation of hook_form_alter().
  */
 function uc_sf_order_form_alter(&$form, $form_state, $form_id) {
-  //~ dpm($form_id, 'uc_sf_order_form_alter: form_id');
-  //~ dpm(array('form' => $form, 'form_state' => $form_state, 'form_id' => $form_id));
-
   if ($form_id == 'salesforce_api_settings_form') {
     $form['uc_sf_order'] = array(
       '#type' => 'fieldset',
@@ -60,15 +65,16 @@ function uc_sf_order_form_alter(&$form, 
 
     // Get an array of fieldmaps that export uc_orders to Salesforce.
     $order_options = salesforce_api_fieldmap_options('uc_order');
+    $user_options = salesforce_api_fieldmap_options(NULL, 'Contact');
     $order_product_options = salesforce_api_fieldmap_options('uc_order_products');
-    $order_ocr_options = salesforce_api_fieldmap_options('node_opportunity_contact_role');
+    $order_ocr_options = salesforce_api_fieldmap_options(NULL,  'OpportunityContactRole');
 
     // If no corresponding fieldmaps were found...
     if (count($order_options) == 0) {
       // Display a message appropriate to the user's permissions.
       if (user_access('administer salesforce')) {
-        $form['uc_sf_order']['export_default']['#description'] = t('No Ubercart Order fieldmaps available.  You must first <a href="!url">add fieldmaps</a> that export ubercart orders (and optionally ubercart order products).');
-        $form['uc_sf_order']['import_default']['#description'] = t('No Ubercart Order fieldmaps available.  You must first <a href="!url">add fieldmaps</a> that imports ubercart orders (and optionally ubercart order products).');
+        $form['uc_sf_order']['export_default']['#description'] = t('No Ubercart Order fieldmaps available.  You must first <a href="!url">add fieldmaps</a> that export ubercart orders (and optionally ubercart order products).', array('!url' => url("admin/settings/salesforce/fieldmap/add")));
+        $form['uc_sf_order']['import_default']['#description'] = t('No Ubercart Order fieldmaps available.  You must first <a href="!url">add fieldmaps</a> that imports ubercart orders (and optionally ubercart order products).', array('!url' => url("admin/settings/salesforce/fieldmap/add")));
       }
       else {
         $form['uc_sf_order']['export_default']['#description'] = t('No Ubercart Order fieldmaps available.  Please contact a site administrator to add a fieldmap that exports ubercart orders.');
@@ -101,6 +107,14 @@ function uc_sf_order_form_alter(&$form, 
         '#prefix' => '<div style="margin-left: 20px;">',
         '#suffix' => '</div>',
       );
+      $form['uc_sf_order']['export_default']['user_fieldmap'] = array(
+        '#description' => 'SalesForce expects a Contact record for its orders. Please choose a fieldmap to use to create the Contact.',
+        '#type' => 'select',
+        '#default_value' => variable_get('uc_sf_order_user_export_fieldmap', FALSE),
+        '#options' => $user_options,
+        '#prefix' => '<div style="margin-left: 20px;">',
+        '#suffix' => '</div>',
+        );
       $form['uc_sf_order']['export_default']['order_auto_sync_product'] = array(
         '#type' => 'checkbox',
         '#title' => t('Also attempt to  sync product details with Salesforce upon each purchase, using the following default order product export fieldmap:'),
@@ -117,7 +131,7 @@ function uc_sf_order_form_alter(&$form, 
       );
       $form['uc_sf_order']['export_default']['order_auto_sync_ocr'] = array(
         '#type' => 'checkbox',
-        '#title' => t('Also attempt to create and sync opportunity-Contact-role for the order using the following default order opportunity-contact-role export fieldmap (Requires setup of custom opportunity_contact_role content type):'),
+        '#title' => t('Also attempt to create and sync Opportunity-Contact-role for the order using the following default order opportunity-contact-role export fieldmap (Requires setup of custom opportunity_contact_role content type):'),
         '#default_value' => variable_get('uc_sf_order_auto_sync_ocr', 0),
         '#prefix' => '<div style="margin-left: 20px;">',
         '#suffix' => '</div>',
@@ -131,21 +145,21 @@ function uc_sf_order_form_alter(&$form, 
       );
 
 
-      //~ $form['uc_sf_order']['import_default']['order_fieldmap'] = array(
-        //~ '#type' => 'select',
-        //~ '#title' => t('Choose the default order import fieldmap'),
-        //~ '#options' => $order_options,
-      //~ );
-      //~ $form['uc_sf_order']['import_default']['order_product_fieldmap'] = array(
-        //~ '#type' => 'select',
-        //~ '#title' => t('Choose the default order product import fieldmap'),
-        //~ '#options' => $order_product_options,
-      //~ );
-      //~ $form['uc_sf_order']['import_default']['order_ocr_fieldmap'] = array(
-        //~ '#type' => 'select',
-        //~ '#title' => t('Choose the default order opportunity-contact-role import fieldmap'),
-        //~ '#options' => $order_ocr_options,
-      //~ );
+       $form['uc_sf_order']['import_default']['order_fieldmap'] = array(
+         '#type' => 'select',
+         '#title' => t('Choose the default order import fieldmap'),
+         '#options' => $order_options,
+       );
+       $form['uc_sf_order']['import_default']['order_product_fieldmap'] = array(
+         '#type' => 'select',
+         '#title' => t('Choose the default order product import fieldmap'),
+         '#options' => $order_product_options,
+       );
+       $form['uc_sf_order']['import_default']['order_ocr_fieldmap'] = array(
+         '#type' => 'select',
+         '#title' => t('Choose the default order opportunity-contact-role import fieldmap'),
+         '#options' => $order_ocr_options,
+       );
     }
     $form['#submit'][] = 'uc_sf_order_salesforce_api_settings_form_submit';
   }
@@ -155,10 +169,6 @@ function uc_sf_order_form_alter(&$form, 
  * submit handler for uc_sf_order part of the salesforce_api_settings_form
  */
 function uc_sf_order_salesforce_api_settings_form_submit(&$form, &$form_state) {
-  //~ dpm('uc_sf_order_salesforce_api_settings_form_submit:');
-  //~ dpm('form'); dpm($form, 'form');
-  //~ dpm('form_state'); dpm($form_state, 'form_state');
-
   $order_export_fieldmap = $form_state['values']['uc_sf_order']['export_default']['order_fieldmap'];
   $order_product_export_fieldmap = $form_state['values']['uc_sf_order']['export_default']['order_product_fieldmap'];
   $order_ocr_export_fieldmap = $form_state['values']['uc_sf_order']['export_default']['order_ocr_fieldmap'];
@@ -171,13 +181,6 @@ function uc_sf_order_salesforce_api_sett
   $order_auto_sync_product = $form_state['values']['uc_sf_order']['export_default']['order_auto_sync_product'];
 
 
-  //$order_import_fieldmap = $form_state['values']['uc_sf_order']['import_default']['order_fieldmap'];
-  //$order_product_import_fieldmap = $form_state['values']['uc_sf_order']['import_default']['order_product_fieldmap'];
-
-  //~ dpm($uc_sf_order_export_fieldmap, 'uc_sf_order_export_fieldmap');
-  //~ dpm($uc_sf_order_import_fieldmap, 'uc_sf_order_import_fieldmap');
-  // dpm($order_always_create_new_user_contact, 'order_always_create_new_user_contact');
-
   variable_set('uc_sf_order_order_export_fieldmap', $order_export_fieldmap);
   variable_set('uc_sf_order_order_product_export_fieldmap', $order_product_export_fieldmap);
   variable_set('uc_sf_order_order_ocr_export_fieldmap', $order_ocr_export_fieldmap);
@@ -188,42 +191,38 @@ function uc_sf_order_salesforce_api_sett
   variable_set('uc_sf_order_auto_sync_ocr', $order_auto_sync_ocr);
   variable_set('uc_sf_order_auto_sync_product', $order_auto_sync_product);
 
-  //variable_set('uc_sf_order_order_import_fieldmap', $order_import_fieldmap);
-  //variable_set('uc_sf_order_order_product_import_fieldmap', $order_product_import_fieldmap);
 }
 
 /**
  * Implementation of hook_order in uc_order.
  */
 function uc_sf_order_order($op, &$order, $arg1 = NULL) {
-  //~ dpm($op, 'uc_sf_order_order: $op');
-
   switch ($op) {
     case 'load':
-    //~ case 'can_update':
-    //~ case 'can_delete':
-      //~ dpm(array('op' => $op, 'order' => $order, 'arg1' => $arg1), 'args');
+    case 'can_update':
+    case 'can_delete':
       $order->salesforce = salesforce_api_id_load('uc_order', $order->order_id);
-      //~ dpm(array('op' => $op, 'order' => $order, 'arg1' => $arg1), 'args');
+      if (!isset($order->salesforce->sfid)) {
+        $order->salesforce->sfid = NULL;
+      }
+      if (!isset($order->salesforce->name)) {
+        $order->salesforce->name = NULL;
+      }
       break;
 
-    //~ case 'save':
+    case 'save':
     case 'update':
-        //~ dpm($op, 'uc_sf_order_order: op');
-        //~ dpm($order->order_status, 'uc_sf_order_order: order_status');
-        //~ dpm(func_get_args(), 'uc_sf_order_order: args');
-
         // only do a sync if the order is associated with a user - otherwise, it's too early
         // only do an update if the order has been exported/synchronized
-        if (($order->uid > 0) && (!empty($order->salesforce['sfid']))) {
+        if (($order->uid > 0) && (!empty($order->salesforce->sfid))) {
           if ($op == 'update') {
             $create_or_update = 'update';
-            $sfid = $order->salesforce['sfid'];
+            $sfid = $order->salesforce->sfid;
           }
-          //~ else {
-            //~ $create_or_update = 'create';
-            //~ $sfid = NULL;
-          //~ }
+           else {
+             $create_or_update = 'create';
+             $sfid = NULL;
+           }
 
           _uc_sf_order_do_export($order, $create_or_update, $sfid);
         }
@@ -244,7 +243,8 @@ function uc_sf_order_fieldmap_objects($t
       'fields' => array(
         'order_id' => array('label' => t('Order ID'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
         'uid' => array('label' => t('User ID'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
-        'order_status' => array('label' => t('Order Status'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
+        'order_status' => array('label' => t('Order Status (ID)'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
+        'order_status_title' => array('label' => t('Order Status (Title)'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY, 'export' => '_uc_sf_order_export_order_status_title'),
         'order_total' => array('label' => t('Order Total'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
         'primary_email' => array('label' => t('Primary E-mail address'), 'type' => SALESFORCE_FIELD_REQUIRED),
         'delivery_first_name' => array('label' => t('Delivery First Name'), 'group' => 'Delivery Information', 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
@@ -274,7 +274,7 @@ function uc_sf_order_fieldmap_objects($t
         'payment_details' => array('label' => t("Payment Details (Array)")),
         'sfautogen_created_date' => array('label' => t('Created date (as XSD:Date)')),
         'sfautogen_modified_date' => array('label' => t('Last modified date (as XSD:Date)')),
-        'sfautogen_user_sfid' => array('label' => t('Donor\'s SalesForce UserID')),
+        'sfautogen_user_sfid' => array('label' => t('Order User\'s SalesForce UserID')),
       ),
     );
     $objects['uc_order_products'] = array(
@@ -293,9 +293,15 @@ function uc_sf_order_fieldmap_objects($t
         'data' => array('label' => t('Data'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
         'sfautogen_order_sfid' => array('label' => t('Order Salesforce-ID'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
         'sfautogen_product_sfid' => array('label' => t('Product-Node Salesforce-ID'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
-        'sfautogen_user_sfid' => array('label' => t('Donor\'s SalesForce UserID'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
+        'sfautogen_user_sfid' => array('label' => t('Order User\'s SalesForce Contact ID'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
       ),
     );
+    $objects['uc_order_contact_role'] = array(
+      'label' => t('Ubercart order contact role'),
+      'fields' => array(
+        'sfautogen_product_sfid' => array('label' => t('Product-Node Salesforce-ID'), 'group' => t('Order Product Information'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY),
+        ),
+      );
   }
 
   return $objects;
@@ -305,14 +311,11 @@ function uc_sf_order_fieldmap_objects($t
  * Implementation of hook_fieldmap_objects_alter().
  */
 function uc_sf_order_fieldmap_objects_alter(&$objects) {
-  // Define the data fields available for Drupal objects.
-  $extra_fields = array();
-
   // Use first, last & organization fields if module installed.
-  $extra_fields = array_merge($extra_fields, array(
-    'uc_sf_order_user_sfid' => array('label' => t('Donor\'s SalesForce UserID [for OCR]'), 'group' => t('OpportunityContactRole Integration'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY, 'export' => '_uc_sf_order_export_values'),
+  $extra_fields = array(
+    'uc_sf_order_user_sfid' => array('label' => t('Order User\'s SalesForce UserID [for OCR]'), 'group' => t('OpportunityContactRole Integration'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY, 'export' => '_uc_sf_order_export_values'),
     'uc_sf_order_order_sfid' => array('label' => t('Order Salesforce-ID [for OCR]'), 'group' => t('OpportunityContactRole Integration'), 'type' => SALESFORCE_FIELD_SOURCE_ONLY, 'export' => '_uc_sf_order_export_values'),
-  ));
+  );
 
   foreach ($extra_fields as $obj_key => $obj_def) {
     foreach ($objects['drupal'] as $obj_key => $obj_def) {
@@ -323,9 +326,23 @@ function uc_sf_order_fieldmap_objects_al
   }
 }
 
+/**
+ * Export callback for Order Status (Title) - which corresponds to Ubercart
+ * order workflow states. 
+ *
+ * @see admin/store/settings/orders/edit/workflow
+ */
+function _uc_sf_order_export_order_status_title($order, $fieldname, $drupal_field_definition, $sf_field_definition) {
+  foreach (uc_order_status_list() as $status) {
+    if ($status['id'] == $order->order_status) {
+      return $status['title'];
+    }
+  }
+  return null;
+}
 
 /**
- * Returns the value of a Location field from the primary or first location.
+ * Returns values for OpportunityContactRole custom fields.
  *
  * @param $source
  *   Object containing the user account / node.
@@ -335,76 +352,27 @@ function uc_sf_order_fieldmap_objects_al
  *   Field value.
  */
 function _uc_sf_order_export_values($source, $field) {
-  //~ ddebug_backtrace();
   $ret_val = NULL;
   if ($field == 'uc_sf_order_order_sfid') {
     $order_id = $source->field_order_id[0]['value'];
     $order_sf_info = salesforce_api_id_load('uc_order', $order_id);
-    $order_sfid = $order_sf_info['sfid'];
-    //~ dpm(array('source' => $source, 'order_id' => $order_id, 'order_sfid' => $order_sfid));
+    $order_sfid = $order_sf_info->sfid;
     $ret_val = $order_sfid;
   }
   elseif ($field == 'uc_sf_order_user_sfid') {
     $account_id = $source->uid;
     $account_sf_info = salesforce_api_id_load('user', $account_id);
-    $account_sfid = $account_sf_info['sfid'];
-    //~ dpm(array('source' => $source, 'account_id' => $account_id, 'account_sfid' => $account_sfid));
+    $account_sfid = $account_sf_info->sfid;
     $ret_val = $account_sfid;
   }
 
-  //~ dpm(array('source' => $source, 'field' => $field, 'ret_val' => $ret_val));
-
   return $ret_val;
 }
 
 /**
- * return a fieldmap
- * @param map_type  the type of map ('user', 'node_<type>', 'uc_order', etc.)
- * @param map_use   'any' => return all maps; 'create' => return maps set to automatic-on-create; 'update' => return maps set to automatic on update
- */
-function _uc_sf_order_get_fieldmap($map_type, $map_use = 'any') {
-  //~ dpm("_uc_sf_order_get_fieldmap: map_type => $map_type, map_use => $map_use");
-
-  if ($map_use == 'create') {
-    $qfrags = "automatic > 0";
-  }
-  else if ($map_use == 'update') {
-    $qfrags = "automatic > 1";
-  }
-  else /* $map_use == 'any' */ {
-    $qfrags = "";
-  }
-
-  $sql = "SELECT fieldmap FROM {salesforce_field_map} WHERE drupal = '%s'";
-  if ($qfrags) {
-    $sql .= ' AND '. $qfrags;
-  }
-
-  // Are there any automatic fieldmaps for uc_order?
-  $result = db_query($sql, $map_type);
-  $fieldmap = db_fetch_object($result);
-  if (!$fieldmap) {
-    return FALSE;
-  }
-
-  // Use the first fieldmap.
-  $fieldmap = $fieldmap->fieldmap;
-
-  // Check if there is more than one fieldmap in the result.
-  if (user_access('administer salesforce') and db_fetch_object($result)) {
-    drupal_set_message(t('Warning: more than one "automatic" salesforce mapping detected. Used fieldmap @map.', array('@map' => $fieldmap)), 'error');
-  }
-
-  //~ dpm("_uc_sf_order_get_fieldmap: fieldmap => $fieldmap");
-
-  return $fieldmap;
-}
-
-/**
  * conditional_actions action handler
  */
 function uc_sf_order_export_action($order, $settings) {
-  //~ dpm(func_get_args(), 'args');
   _uc_sf_order_do_export($order, 'create');
 }
 
@@ -412,12 +380,9 @@ function uc_sf_order_export_action($orde
  * perform an order export
  */
 function _uc_sf_order_do_export($order, $create_or_update = 'create', $sfid = NULL) {
-  //~ dpm(func_get_args(), 'args');
-
   // Load the ubercart order if we didn't get a full object.
   if (is_numeric($order)) {
     $order = uc_order_load($order);
-    //~ dpm($order, 'order');
   }
 
   if ($order->uid <= 0) {
@@ -430,49 +395,31 @@ function _uc_sf_order_do_export($order, 
   // get user info
   $buyer_user_info = user_load($order->uid);
 
-  // get user fieldmap
-  $user_fieldmap = _uc_sf_order_get_fieldmap('user');
-
-  //~ dpm($user_fieldmap, 'user_fieldmap');
-
-  if ($user_fieldmap === FALSE) {
-    // only export an order if there is a valid user associated with it
-    //~ dpm('error: no user fieldmap');
-    drupal_set_message(t('ubercart-salesforce export: no user fieldmap found.  Not exporting.'), 'error');
-    return;
-  }
-
   // perform user export
-  if (variable_get('uc_sf_order_auto_sync_user', 0)) {
+  $user_fieldmap = variable_get('uc_sf_order_user_export_fieldmap', FALSE);
+  if ($user_fieldmap && variable_get('uc_sf_order_auto_sync_user', 0)) {
     if (variable_get('uc_sf_order_always_create_new_user_contact', 0)) {
-      sf_user_export($order->uid, $user_fieldmap);  // Always create new Contact record on Salesforce.  Most people should not need this.  It should become irrelevant in the next uc_salesforce release (where pieces are split into separate modules).
+      sf_user_export($order->uid, $user_fieldmap); // Always create new Contact record on Salesforce.  Most people should not need this.  It should become irrelevant in the next uc_salesforce release (where pieces are split into separate modules).
     }
     else {
-      sf_user_export($order->uid, $user_fieldmap, $buyer_user_info->salesforce['sfid']);
+      sf_user_export($order->uid, $user_fieldmap, $buyer_user_info->salesforce->sfid);
     }
+    // reload user info
+    $buyer_user_info = user_load($order->uid);
   }
 
-  // reload user info
-  $buyer_user_info = user_load($order->uid);
-
-  //~ dpm('buyer_user_info');
-  //~ dpm($buyer_user_info, 'buyer_user_info');
-
   // export the order
 
   // get uc_order fieldmap
-  //~ $uc_order_fieldmap = _uc_sf_order_get_fieldmap('uc_order', $create_or_update);
-  $uc_order_fieldmap = variable_get('uc_sf_order_order_export_fieldmap', -1);
-
-  //~ dpm($uc_order_fieldmap, 'uc_order_fieldmap');
+  $uc_order_fieldmap = variable_get('uc_sf_order_order_export_fieldmap', FALSE);
 
   // add custom items to order
   $order->sfautogen_created_date = date('Y-m-d', $order->created);
   $order->sfautogen_modified_date = date('Y-m-d', $order->modified);
-  $order->sfautogen_user_sfid = $buyer_user_info->salesforce['sfid'];
+  $order->sfautogen_user_sfid = $buyer_user_info->salesforce->sfid;
 
   // perform the uc_order export
-  return uc_sf_order_export($order, $uc_order_fieldmap, $order->salesforce['sfid']);
+  return uc_sf_order_export($order, $uc_order_fieldmap, $order->salesforce->sfid);
 }
 
 // Displays the Salesforce synchronization form.
@@ -496,7 +443,7 @@ function uc_sf_order_salesforce_form(&$f
   );
 
   // Display an export button if the node hasn't been exported before.
-  if (!$order->salesforce['sfid']) {
+  if (!$order->salesforce->sfid) {
     $form['export'] = array(
       '#type' => 'fieldset',
       '#title' => t('Export order to Salesforce'),
@@ -534,38 +481,34 @@ function uc_sf_order_salesforce_form(&$f
     // Otherwise add synchronization information.
     $form['sfid'] = array(
       '#type' => 'value',
-      '#value' => $order->salesforce['sfid'],
+      '#value' => $order->salesforce->sfid,
     );
     $form['fieldmap'] = array(
       '#type' => 'value',
-      '#value' => $order->salesforce['fieldmap'],
+      '#value' => $order->salesforce->name,
     );
 
     // Retrieve the object from Salesforce.
     $sf = salesforce_api_connect();
-    $data = $sf->retrieve(array($order->salesforce['sfid']), $order->salesforce['fieldmap']);
+    $data = $sf->retrieve(array($order->salesforce->sfid), $order->salesforce->name);
 
     // Load the fieldmap data.
-    $map = salesforce_api_fieldmap_load($order->salesforce['fieldmap']);
+    $map = salesforce_api_fieldmap_load($order->salesforce->fieldmap);
 
     // Load the object definitions.
-    $drupal_object = salesforce_api_fieldmap_objects_load('drupal', $map['drupal']);
-    $object = salesforce_api_fieldmap_objects_load('salesforce', $map['salesforce']);
-
-    //~ dpm($map);
-    //~ dpm($drupal_object);
-    //~ dpm($object);
+    $drupal_object = salesforce_api_fieldmap_objects_load('drupal', $map->drupal);
+    $object = salesforce_api_fieldmap_objects_load('salesforce', $map->salesforce);
 
-    $header = array(t('Field name'), t('Drupal ubercart order value'), t('Salesforce @type value', array('@type' => salesforce_api_fieldmap_object_label('salesforce', $map['salesforce']))));
+    $header = array(t('Field name'), t('Drupal ubercart order value'), t('Salesforce @type value', array('@type' => salesforce_api_fieldmap_object_label('salesforce', $map->salesforce))));
     $rows = array();
 
-    foreach ($map['fields'] as $key => $value) {
+    foreach ($map->fields as $key => $value) {
       // allow fixed values
-      if (is_array($map['fields'][$key]) && $map['fields'][$key]['type'] == 'fixed' && !empty($map['fields'][$key]['value']))  {
-        $drupal_value = $map['fields'][$key]['value'];
+      if (is_array($map->fields[$key]) && $map->fields[$key]['type'] == 'fixed' && !empty($map->fields[$key]['value']))  {
+        $drupal_value = $map->fields[$key]['value'];
       }
       elseif (isset($drupal_object['fields'][$value]['export'])) {
-        $drupal_value = $drupal_object['fields'][$value]['export']($order, $value);
+        $drupal_value = $drupal_object['fields'][$value]['export']($order, $value, $drupal_object['fields'][$value], $object['fields'][$key]);
       }
       elseif (isset($order->$value)) {
         $drupal_value = $order->$value;
@@ -584,7 +527,7 @@ function uc_sf_order_salesforce_form(&$f
     $form['mapped'] = array(
       '#type' => 'fieldset',
       '#title' => t('Mapped field values'),
-      '#description' => t('These fields have been mapped through <a href="!url">fieldmap @index</a>.', array('!url' => url(SALESFORCE_PATH_FIELDMAPS .'/'. $order->salesforce['fieldmap'] .'/edit'), '@index' => $order->salesforce['fieldmap'])),
+      '#description' => t('<a href="!url">Edit this fieldmap</a>.', array('!url' => url(SALESFORCE_PATH_FIELDMAPS .'/'. $order->salesforce->name .'/edit'))),
     );
     $form['mapped']['fieldmap_values'] = array(
       '#value' => theme('table', $header, $rows),
@@ -595,18 +538,18 @@ function uc_sf_order_salesforce_form(&$f
       '#value' => t('Export changes to Salesforce'),
       '#attributes' => array('class' => 'sf-confirm'),
     );
-    //~ $form['mapped']['import_values'] = array(
-      //~ '#type' => 'submit',
-      //~ '#value' => t('Import changes from Salesforce'),
-      //~ '#attributes' => array('class' => 'sf-confirm'),
-    //~ );
+     $form['mapped']['import_values'] = array(
+       '#type' => 'submit',
+       '#value' => t('Import changes from Salesforce'),
+       '#attributes' => array('class' => 'sf-confirm'),
+     );
 
     // Create a table for the unmapped fields.
-    $header = array(t('Field name'), t('Salesforce @type value', array('@type' => salesforce_api_fieldmap_object_label('salesforce', $map['salesforce']))));
+    $header = array(t('Field name'), t('Salesforce @type value', array('@type' => salesforce_api_fieldmap_object_label('salesforce', $map->salesforce))));
     $rows = array();
 
     foreach ((array) $data as $key => $value) {
-      if (!isset($map['fields'][$key]) && isset($object['fields'][$key])) {
+      if (!isset($map->fields[$key]) && isset($object['fields'][$key])) {
         $rows[] = array(
           $object['fields'][$key]['label'],
           $value,
@@ -663,8 +606,7 @@ function uc_sf_order_salesforce_form_sub
   switch ($form_state['values']['op']) {
     // Export the user to Salesforce.
     case t('Export ubercart order'):
-      //~ if (uc_sf_order_export($form_state['values']['order_id'], $form_state['values']['fieldmap'])) {
-      if (_uc_sf_order_do_export($form_state['values']['order_id'], 'create', NULL)) {
+       if (uc_sf_order_export($form_state['values']['order_id'], $form_state['values']['fieldmap'])) {
         drupal_set_message(t('Ubercart order successfully exported to Salesforce.'));
       }
       else {
@@ -674,8 +616,7 @@ function uc_sf_order_salesforce_form_sub
 
     // Export changes to Salesforce.
     case t('Export changes to Salesforce'):
-      //~ if (uc_sf_order_export($form_state['values']['order_id'], $form_state['values']['fieldmap'], $form_state['values']['sfid'])) {
-      if (_uc_sf_order_do_export($form_state['values']['order_id'], 'update', $form_state['values']['sfid'])) {
+       if (uc_sf_order_export($form_state['values']['order_id'], $form_state['values']['fieldmap'], $form_state['values']['sfid'])) {
         drupal_set_message(t('Changes successfully exported to Salesforce.'));
       }
       else {
@@ -702,190 +643,216 @@ function uc_sf_order_salesforce_form_sub
  *
  * @param $order
  *   The ubercart order object to export (also accepts a numeric order id).
- * @param $fieldmap
- *   The index of the fieldmap to use to create the export object.
+ * @param $name
+ *   The name of the fieldmap to use to create the export object.
  * @param $sfid
  *   The Salesforce ID of the object you want to update.  If left NULL, a new
  *     object will be created at Salesforce.
  * @return
  *   TRUE or FALSE indicating the success of the operation.
  */
-function uc_sf_order_export($order, $fieldmap, $sfid = NULL) {
-  //~ dpm('uc_sf_order_export');
-  //~ dpm(array('order' => $order, 'fieldmap' => $fieldmap, 'sfid' => $sfid), 'args');
-
-  if (variable_get('uc_sf_order_auto_sync_order', 0)) {
-
-    // if no valid fieldmap, abort
-    if ($fieldmap < 0) {
-      drupal_set_message(t('uc_sf_order_export: invalid fieldmap: !fieldmap.  Remember to set the Ubercart fieldmaps to use in the Salesforce settings.', array('!fieldmap' => $fieldmap)), 'error');
-      return FALSE;
-    }
-
-    // Attempt to connect to Salesforce.
-    $sf = salesforce_api_connect();
-
-    // Load the ubercart order if we didn't get a full object.
-    if (is_numeric($order)) {
-      $order = uc_order_load($order);
-      //~ dpm($order, 'order');
-    }
-
-    // Create an object for export based on the specified fieldmap.
-    $object = salesforce_api_fieldmap_export_create($fieldmap, $order);
-
-    // Load the fieldmap so we can get the object name.
-    $map = salesforce_api_fieldmap_load($fieldmap);
-
-    //~ dpm(array('map' => $map, 'fieldmap' => $fieldmap));
-
-    if (empty($sfid)) {
-      // Export the object to Salesforce.
-      try {
-        $response = $sf->client->create(array($object), $map['salesforce']);
-        //~ dpm('uc_sf_order_export: post-create-order');
-        //~ dpm(array('order' => $order, 'object' => $object, 'map' => $map, 'response' => $response));
-
-        //~ $uc_order_products_fieldmap_id = _uc_sf_order_get_fieldmap('uc_order_products', $create_or_update);
-        $uc_order_products_fieldmap_id = variable_get('uc_sf_order_order_product_export_fieldmap', -1);
-
-        //~ dpm($uc_order_products_fieldmap_id, 'uc_order_products_fieldmap_id');
-        // Load the fieldmap so we can get the object name.
-        $uc_order_products_fieldmap = salesforce_api_fieldmap_load($uc_order_products_fieldmap_id);
+function uc_sf_order_export($order, $name, $sfid = NULL) {
+  if (!variable_get('uc_sf_order_auto_sync_order', FALSE)) {
+    return;
+  }
 
-        if ($response->success && $order->products && ($uc_order_products_fieldmap_id >= 0)) {
-    $order_sfid = $response->id;
+  // if no valid fieldmap, abort
+  if (empty($name)) {
+    drupal_set_message(t('uc_sf_order_export: invalid fieldmap.  Remember to set the Ubercart fieldmaps to use in the Salesforce settings.', array('!fieldmap' => $name)), 'error');
+    return FALSE;
+  }
 
-    salesforce_api_id_save('uc_order', $order->order_id, $order_sfid, $fieldmap);
+  // Attempt to connect to Salesforce.
+  $sf = salesforce_api_connect();
 
-    //~ dpm($order_sfid, 'order_sfid');
+  // Load the ubercart order if we didn't get a full object.
+  if (is_numeric($order)) {
+    $order = uc_order_load($order);
+  }
 
-    // handle individual products
-    if (variable_get('uc_sf_order_auto_sync_product', 0)) {
-      foreach ($order->products as $product) {
-        // modify the product
-        $user_salesforce = salesforce_api_id_load('user', $order->uid);
-        $product->sfautogen_order_sfid = $order_sfid;
-        $product->sfautogen_user_sfid = $user_salesforce['sfid'];
+  // Create an object for export based on the specified fieldmap.
+  $object = salesforce_api_fieldmap_export_create($name, $order);
 
-        $product->salesforce = salesforce_api_id_load('node', $product->nid);
-        $product->sfautogen_product_sfid = $product->salesforce ? $product->salesforce['sfid'] : '';
+  // Load the fieldmap so we can get the object name.
+  $map = salesforce_api_fieldmap_load($name);
 
-        //~ dpm($product->salesforce, 'product->salesforce');
-        //~ dpm($product, 'product');
+  if (empty($sfid)) {
+    // Export the object to Salesforce.
+    try {
+      $response = $sf->client->create(array($object), $map->salesforce);
+    }
+    catch (Exception $e) {
+      drupal_set_message(t('Error exporting order to SalesForce.'), 'error');
+      return FALSE;
+    }
+    if (!$response->success) {
+      drupal_set_message(t('Error exporting order to SalesForce.'), 'error');
+      return FALSE;
+    }
+    else {
+      $order_sfid = $response->id;
+      salesforce_api_id_save('uc_order', $order->order_id, $order_sfid, $name);
+    }
+    $uc_order_products_fieldmap_id = variable_get('uc_sf_order_order_product_export_fieldmap', FALSE);
 
-        // Create an object for export based on the specified fieldmap.
-        $product_sf_object = salesforce_api_fieldmap_export_create($uc_order_products_fieldmap_id, $product);
-        //~ dpm($product_sf_object, 'product_sf_object');
+    // Load the fieldmap so we can get the object name.
+    $uc_order_products_fieldmap = salesforce_api_fieldmap_load($uc_order_products_fieldmap_id);
 
-        $product_response = $sf->client->create(array($product_sf_object), $uc_order_products_fieldmap['salesforce']);
+    if ($order_sfid && $order->products && $uc_order_products_fieldmap) {
+      // handle individual products
+      if (variable_get('uc_sf_order_auto_sync_product', 0)) {
+        $product_objects = array();
+        foreach ($order->products as $product) {
+          // modify the product
+          $user_salesforce = salesforce_api_id_load('user', $order->uid);
+          $product->sfautogen_order_sfid = $order_sfid;
+          $product->sfautogen_user_sfid = $user_salesforce->sfid;
 
-        //~ dpm($product_response, 'product_response');
+          $product->salesforce = salesforce_api_id_load('node', $product->nid);
+          $product->sfautogen_product_sfid = $product->salesforce ? $product->salesforce->sfid : '';
 
-        if ($product_response->success) {
-          if (!$product->salesforce) {
-            $product->salesforce = array();
+          // Create an object for export based on the specified fieldmap.
+          $product_objects[] = salesforce_api_fieldmap_export_create($uc_order_products_fieldmap_id, $product);
+        }
+        try {
+          $product_responses = $sf->client->create($product_objects, $uc_order_products_fieldmap->salesforce);
+        }
+        catch (Exception $e) {
+          watchdog('uc_sf_order', 'Failed to export Order Product to SalesForce. <pre>' . print_r($e, 1) . '</pre><pre>' . print_r($product, 1) . '</pre><pre>' . print_r($product_objects[$i], 1) . '</pre>');
+        }
+        foreach ($order->products as $i => $product) {
+          if ($product_response->success) {
+            $order->products[$i]->salesforce = (object)array(
+              'sfid' => $product_responses[$i]->id,
+              'name' => $uc_order_products_fieldmap_id,
+            );
+          }
+          else {
+            watchdog('uc_sf_order', 'Failed to export Order Product to SalesForce. <pre>' . print_r($product_responses[$i], 1) . '</pre><pre>' . print_r($product, 1) . '</pre><pre>' . print_r($product_objects[$i], 1) . '</pre>');
           }
-
-          $product->salesforce['sfid'] = $product_response->id;
         }
       }
     }
-
-    // handle OpportunityContactRole(s)
-    if (variable_get('uc_sf_order_auto_sync_ocr', 0)) {
-      $uc_order_ocr_fieldmap_id = variable_get('uc_sf_order_order_ocr_export_fieldmap', -1);
-      if ($uc_order_ocr_fieldmap_id >= 0) {
-        $ocr_node = NULL;
-        if (empty($ocr_node)) {
-          // Create a new node without setting the nid and call node_save
-          // Copy relevant donation fields
-          $ocr_node = new stdClass();
-          $ocr_node->type = 'opportunity_contact_role';
-          $ocr_node->status = 1;
-          $ocr_node->uid = $order->uid;
-          $ocr_node->title = 'opportunity_contact_role:uid='. $order->uid .';order_id='. $order->order_id;
-          $ocr_node->body = '';
-          $ocr_node->field_order_id = array(array('value' => $order->order_id));
-
-          node_save($ocr_node);
-
-          // modify the node
-          $ocr->sfautogen_order_sfid = $order_sfid;
-
-          //~ dpm($ocr_node);
+    // handle OpportunityContactRole
+    $ocr_fieldmap_id = 
+      variable_get('uc_sf_order_order_ocr_export_fieldmap', FALSE);
+    if ($ocr_fieldmap_id
+    && variable_get('uc_sf_order_auto_sync_ocr', FALSE)
+    && array_filter(content_types('opportunity_contact_role'))) {
+      $ocr_node = (object)array(
+        'type' => 'opportunity_contact_role',
+        'status' => 0,
+        'uid' => $order->uid,
+        'field_order_id' =>
+          array(array('value' => $order->order_id)),
+      );
+      node_save($ocr_node);
+      $account = user_load($order->uid);
+      if (empty($account->salesforce->sfid)) {
+        $user_map_id =
+         variable_get('uc_sf_order_user_export_fieldmap', 
+          'salesforce_api_default_user_contact_field_map');
+        $user_map = salesforce_api_fieldmap_load($user_map_id);
+        if ($user_map->automatic) {
+          user_save($account);
         }
+        else {
+          $user_object_export = 
+            salesforce_api_fieldmap_export_create($user_map_id, $account);
+          $user_response = $sf->client->create(
+            array($user_object_export), $user_map->salesforce);
+          $account_sfid = $user_response->id;
+        }
+      }
 
-        $uc_order_ocr_fieldmap = salesforce_api_fieldmap_load($uc_order_ocr_fieldmap_id);
-
-        // Create an object for export based on the specified fieldmap.
-        $ocr_sf_object = salesforce_api_fieldmap_export_create($uc_order_ocr_fieldmap_id, $ocr_node);
-        //~ dpm($ocr_sf_object, 'ocr_sf_object');
-
-        $ocr_response = $sf->client->create(array($ocr_sf_object), $uc_order_ocr_fieldmap['salesforce']);
-
-        //~ dpm($ocr_response, 'ocr_response');
-
-        if ($ocr_response->success) {
-          if (!$ocr_node->salesforce) {
-            $ocr_node->salesforce = array();
+      // The expected setup is that UC Order is mapped to Opportunity. If
+      // instead Products are mapped to Opportunity, then we need to upsert
+      // a OCR for each Product.
+      if ($uc_order_products_fieldmap->salesforce == 'Opportunity') {
+        $ocr_objects = array();
+        foreach ($order->products as $product) {
+          $ocr_node->sfautogen_order_sfid = $product->salesforce->sfid;
+          $ocr_object = 
+            salesforce_api_fieldmap_export_create($ocr_fieldmap_id, $ocr_node);
+          // If the account sfid was not set, but we have it locally, set it.
+          if ($ocr_object) {
+            if (empty($ocr_object->ContactId) && $account_sfid) {
+              $ocr_object->ContactId = $account_sfid;
+            }
+            if (empty($ocr_object->OpportunityId) && $order_sfid) {
+              $ocr_object->OpportunityId = $order_sfid;
+            }
+            $ocr_objects[] = $ocr_object;
           }
-
-          $ocr_node->salesforce['sfid'] = $ocr_response->id;
-          //~ node_save($ocr_node);
-          salesforce_api_id_save('node', $ocr_node->nid, $ocr_node->salesforce['sfid'], $uc_order_ocr_fieldmap_id);
         }
       }
-    }
-
+      elseif ($map->salesforce == 'Opportunity') {
+        $ocr_object = 
+          salesforce_api_fieldmap_export_create($ocr_fieldmap_id, $ocr_node);
+        // If the account sfid was not set, but we have it locally, set it.
+        if ($ocr_object) {
+          if (empty($ocr_object->ContactId) && $account_sfid) {
+            $ocr_object->ContactId = $account_sfid;
+          }
+          if (empty($ocr_object->OpportunityId) && $order_sfid) {
+            $ocr_object->OpportunityId = $order_sfid;
+          }
+          $ocr_objects = array($ocr_object);
+        }
+        else {
+          watchdog('uc_sf_order', 'Failed to create OCR for export from node. <pre>' . print_r($ocr_node, 1) . '</pre>');
         }
-      } catch (Exception $e) {
-    //dpm('Caught exception: ' .$e->getMessage());
-    //dpm($e, 'error');
-    sf_devel_backtrace();
-    drupal_set_message(t('Error exporting ubercart order to salesforce.'), 'error');
-    return FALSE;
       }
-    }
-    else {
-      try {
-        $object->Id = $sfid;
-
-        $response = $sf->client->update(array($object), $map['salesforce']);
-      } catch (Exception $e) {
-    //~ echo 'Caught exception: ',  $e->getMessage(), "\n";
-    //~ dpm($e);
-    //~ sf_devel_backtrace();
-    drupal_print_message(t('Error updating salesforce object from ubercart.'), 'error');
-    return FALSE;
+      if (!empty($ocr_objects)) {
+        try {
+          $ocr_responses = $sf->client->create(
+            $ocr_objects, 'OpportunityContactRole');
+        }
+        catch (Exception $e) {
+          watchdog('uc_sf_order', 'Failed to export Opportunity Contact Role to SalesForce. <pre>' . print_r($e, 1) . '</pre><pre>' . print_r($ocr_node, 1) . '</pre><pre>' . print_r($ocr_object, 1) . '</pre>');
+        }
+        if (!is_array($ocr_responses)) {
+          $ocr_responses = array($ocr_responses);
+        }
+        foreach ($ocr_responses as $ocr_response) {
+          if (!$ocr_response->success) {
+            watchdog('uc_sf_order', 'Failed to export Opportunity Contact Role to SalesForce. <pre>' . print_r($ocr_response, 1) . '</pre><pre>' . print_r($ocr_node, 1) . '</pre><pre>' . print_r($ocr_objects, 1) . '</pre>');
+          }
+        }
+      }
+      else {
+        watchdog('uc_sf_order', 'Ubercart SalesForce Order could not export Opportunity Contact Roles because it could not find an appropriate Opportunity to export. Please make sure you are using a fieldmap for SalesForce Opportunity.');
       }
     }
-
-    //~ dpm('salesforce response:');
-    //~ dpm($response, 'salesforce response');
-
-    // If the export was successful...
-    if ($response->success) {
-      if (empty($sfid)) {
-        // Store the Salesforce ID for the node and return TRUE.
-        //~ dpm("storing to salesforce object map: order_id={$order->order_id}, response_id={$response->id}, fieldmap=$fieldmap");
-        salesforce_api_id_save('uc_order', $order->order_id, $response->id, $fieldmap);
-
-        foreach ($order->products as $product) {
-    if ($product->salesforce['sfid']) {
-      salesforce_api_id_save('uc_order_products', $product->order_product_id, $product->salesforce['sfid'], $fieldmap);
+  }
+  else {
+    try {
+      $object->Id = $sfid;
+      $response = $sf->client->update(array($object), $map->salesforce);
+    } catch (Exception $e) {
+      drupal_print_message(t('Error updating salesforce object from ubercart.'), 'error');
+      return FALSE;
     }
+  }
+
+  // If the export was successful...
+  if ($response->success) {
+    if (empty($sfid)) {
+      // Store the Salesforce ID for the node and return TRUE.
+      salesforce_api_id_save('uc_order', $order->order_id, $response->id, $name);
+      foreach ($order->products as $product) {
+        if ($product->salesforce->sfid) {
+          salesforce_api_id_save('uc_order_products', $product->order_product_id, $product->salesforce->sfid, $name);
         }
       }
-
-      return TRUE;
     }
-    else {
-      // Otherwise log the error and return FALSE.
-      drupal_set_message('<pre>'. print_r($response, TRUE) .'</pre>', 'error');
+    return TRUE;
+  }
+  else {
+    // Otherwise log the error and return FALSE.
+    drupal_set_message('<pre>'. print_r($response, TRUE) .'</pre>', 'error');
 
-      return FALSE;
-    }
+    return FALSE;
   }
 }
 
@@ -894,17 +861,17 @@ function uc_sf_order_export($order, $fie
  *
  * @param $sfid
  *   The Salesforce ID of the object from which you want to import.
- * @param $fieldmap
- *   The index of the fieldmap to use to create the export object.
+ * @param $name
+ *   The name of the fieldmap to use to create the export object.
  * @param $uid
  *   The uid of the user to update.  If left NULL, a new user will be created.
  * @return
  *   The uid of the imported user or FALSE on failure.
  */
-function uc_sf_order_import($sfid, $fieldmap, $order_id = NULL) {
+function uc_sf_order_import($sfid, $name, $order_id = NULL) {
   // Retrieve the object from Salesforce.
   $sf = salesforce_api_connect();
-  $data = $sf->retrieve(array($sfid), $fieldmap);
+  $data = $sf->retrieve(array($sfid), $name);
 
   // Return FALSE if the object data was not found at Salesforce.
   if (empty($data)) {
@@ -913,11 +880,11 @@ function uc_sf_order_import($sfid, $fiel
   }
 
   // Load the fieldmap data.
-  $map = salesforce_api_fieldmap_load($fieldmap);
+  $map = salesforce_api_fieldmap_load($name);
 
   // Load the object definitions.
-  $drupal_object = salesforce_api_fieldmap_objects_load('drupal', $map['drupal']);
-  $salesforce_object = salesforce_api_fieldmap_objects_load('salesforce', $map['salesforce']);
+  $drupal_object = salesforce_api_fieldmap_objects_load('drupal', $map->drupal);
+  $salesforce_object = salesforce_api_fieldmap_objects_load('salesforce', $map->salesforce);
 
   // If a node was specified, attempt to load it.
   $order = uc_order_load($order_id);
@@ -925,7 +892,7 @@ function uc_sf_order_import($sfid, $fiel
   // If the node exists, simply update the existing node.
   if ($order->order_id) {
     // Loop through the fields on the fieldmap.
-    foreach ($map['fields'] as $value => $key) {
+    foreach ($map->fields as $value => $key) {
       // If a handler is specified for importing a value from Salesforce.
       if (isset($drupal_object['fields'][$key]['import'])) {
         // Get the value for the field from the handler function.
@@ -942,24 +909,53 @@ function uc_sf_order_import($sfid, $fiel
       }
     }
 
-    //~ drupal_set_message('<pre>Changes: '. print_r($changes, TRUE) .'</pre>');
+     drupal_set_message('<pre>Changes: '. print_r($changes, TRUE) .'</pre>');
 
     foreach ($changes as $key => $value) {
         $order->$key = $value;
     }
-    //~ drupal_set_message('<pre>Order: '. print_r($order, TRUE) .'</pre>');
-
+     drupal_set_message('<pre>Order: '. print_r($order, TRUE) .'</pre>');
     uc_order_save($order);
+    if ($map->automatic && !empty($order->order_id)) {
+      // Store the Salesforce ID for the node and return TRUE.
+      salesforce_api_id_save('uc_order', $order->order_id, $sfid, $name);
+    }
   }
 
   return $order->order_id;
 }
 
+function uc_sf_order_default_salesforce_field_maps() {
+  return array('uc_sf_order_default_uc_order_opportunity_field_map' => 
+    (object)array(
+      'disabled' => FALSE,
+      'name' => 'uc_sf_order_default_uc_order_opportunity_field_map',
+      'automatic' => FALSE,
+      'drupal' => 'uc_order',
+      'salesforce' => 'Opportunity',
+      'fields' => array(
+        'Name' => 'order_id',
+        'StageName' => 'order_status',
+        'CloseDate' => 'sfautogen_created_date'),
+      'description' => 'Default mapping for Ubercart Order to Opportuinty',
+    ),
+    'uc_sf_order_default_opportunity_contact_role_field_map' => (object)array(
+      'disabled' => FALSE,
+      'name' => 'uc_sf_order_default_opportunity_contact_role_field_map',
+      'automatic' => FALSE,
+      'drupal' => 'uc_order_contact_role',
+      'salesforce' => 'OpportunityContactRole',
+      'fields' => array(
+        'OpportunityId' => 'uc_sf_order_order_sfid',
+        'ContactId' => 'uc_sf_order_user_sfid'),
+      'description' => 'Default mapping for Opportuinty Contact Role',      
+    ),
+  );
+}
+
 function sf_devel_backtrace() {
-  $trace = debug_backtrace();
-  array_shift($trace);
-  foreach ($trace as $key => $value) {
-    $rich_trace[$value['function']] = $value;
+  $trace = array();
+  foreach(debug_backtrace() as $t) {
+    $trace[] = $t['function'] . ' : ' . $t['line'] . ' : ' . $t['file'];
   }
-  //dpm($rich_trace);
-}
+}
\ No newline at end of file
