--- C:/Users/mxmorin.DOMAINE/Downloads/commerce_extra_price_formatters-7.x-1.x-dev/commerce_extra_price_formatters/commerce_extra_price_formatters.module	Fri Jan 04 15:48:28 2013
+++ C:/applications/web/wamp/www/commerce/sites/all/modules/commerce_extra_price_formatters/commerce_extra_price_formatters.module	Mon Jan 07 11:13:51 2013
@@ -5,6 +5,9 @@
  * Defines the additional price formatters for Drupal Commerce
  */
 
+define('COMMERCE_COMPONENT_PRICE_ORDER','commerce_component_price_order');
+define('COMMERCE_COMPONENT_PRICE_SETTINGS','commerce_component_price_settings');
+define('COMMERCE_COMPONENT_HIDDEN_SETTINGS','commerce_component_hidden_settings');
 
 /**
  * Implements hook_field_formatter_info().
@@ -389,6 +392,10 @@
     'commerce_price_rrp_your_price' => array(
       'variables' => array('components' => array(), 'price' => array(), 'options' => array()),
     ),
+    'reorder_price_components_table' => array(
+      'render element' => 'element'
+    ),
+    
   );
 }
 
@@ -497,3 +504,135 @@
 
   return  theme('table', array('rows' => $rows, 'attributes' => array('class' => array('commerce-price-rrp-your-price'))));
 }
+
+/**
+ * Alter Commerce_price component before printing
+ * This will change weight and titles or components
+ **/
+function commerce_extra_price_formatters_commerce_price_formatted_components_alter(&$components, $item, $entity) {
+
+  // Load the saved order set for the components in the checkout.
+  $types = variable_get(COMMERCE_COMPONENT_PRICE_ORDER,array());
+  $hidden_components = variable_get(COMMERCE_COMPONENT_HIDDEN_SETTINGS, array());
+
+  // Assign a weight to each component if there is one stored.
+  foreach ($components as $name => $component) {
+    if (array_key_exists($name,$types)) {
+      $components[$name]['weight'] = $types[$name]['weight'];
+    }
+    // Hide the component if required.
+    if (array_key_exists($name, $hidden_components) && $hidden_components[$name]['hide'] == 1){
+      unset($components[$name]);
+    }
+  }
+
+  // Reset the weight of the total so it's always at the bottom.
+  $components['commerce_price_formatted_amount']['weight'] = 1000;
+
+
+}
+
+/**
+ * Implements hook_form_<FORM>_alter
+ *
+ * Add draggable table to cart pane to reorder component_price components.
+ **/
+
+function commerce_extra_price_formatters_form_commerce_checkout_pane_settings_form_alter(&$form, &$form_state) {
+  if ($form['checkout_pane']['#value']['base'] == 'commerce_cart_contents_pane') {
+    $form['settings']['reorder_price_components'] = array(
+      '#type' => 'item',
+      '#title' => 'Order price components',
+      '#tree' => TRUE,
+      '#weight' => 5,
+      '#theme' => 'reorder_price_components_table'
+    );
+
+    $form['settings']['hide_price_components'] = array(
+      '#type' => 'item',
+      '#title' => t('Hide price components in the cart total.'),
+      '#tree' => TRUE,
+      '#weight' => 10,
+    );
+
+    $types = commerce_price_component_types();
+    $orders = variable_get(COMMERCE_COMPONENT_PRICE_ORDER,array());
+    $hidden_components = variable_get(COMMERCE_COMPONENT_HIDDEN_SETTINGS, array());
+    foreach ($orders as $name => $order) {
+      $types[$name]['weight'] = $order['weight'];
+    }
+    uasort($types,"drupal_sort_weight");
+
+
+
+    foreach($types as $key => $component) {
+
+      if (!isset($component['hide'])) $component['hide'] = FALSE;
+      $form['settings']['reorder_price_components'][$key]['name'] = array(
+        '#markup' => $component['title'],
+      );
+      $form['settings']['reorder_price_components'][$key]['weight'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $component['weight'],
+        '#size' => 3,
+        '#attributes' => array('class' => array('rank-weight')), // needed for table dragging
+      );
+
+      $hidden = FALSE;
+      if (array_key_exists($key, $hidden_components) && $hidden_components[$key]['hide'] == 1) $hidden = TRUE;
+      $form['settings']['hide_price_components'][$key]['hide'] = array(
+        '#type' => 'checkbox',
+        '#default_value' => $hidden,
+        '#title' => $component['title'],
+      );
+
+    }
+
+    $form['submit']['#submit'][] = "commerce_extra_price_formatters_form_commerce_cart_contents_pane_submit";
+  }
+}
+
+  /**
+   * Submit callback for  commerce_checkout_pane_settings_form
+   * Store new order in variables
+   **/
+  function commerce_extra_price_formatters_form_commerce_cart_contents_pane_submit(&$form, &$form_state) {
+    $types = $form_state['values']['reorder_price_components'];
+    uasort($types,"drupal_sort_weight");
+    variable_set(COMMERCE_COMPONENT_PRICE_ORDER,$types);
+
+    $hidden_components = $form_state['values']['hide_price_components'];
+    variable_set(COMMERCE_COMPONENT_HIDDEN_SETTINGS,$hidden_components);
+
+  }
+
+  /**
+   * Theme for rendering component prices ordering
+   **/
+  function theme_reorder_price_components_table($vars) {
+    $element = $vars['element'];
+    drupal_add_tabledrag('reorder_price_form', 'order', 'sibling', 'rank-weight'); // needed for table dragging
+
+    $header = array(
+      'name' => t('Name'),
+      'weight' => t('Rank'),
+    );
+
+    $rows = array();
+    foreach (element_children($element) as $key) {
+      $row = array();
+
+      $row['data'] = array();
+      foreach ($header as $fieldname => $title) {
+        $row['data'][] = drupal_render($element[$key][$fieldname]);
+        $row['class'] = array('draggable'); // needed for table dragging
+      }
+      $rows[] = $row;
+    }
+
+    return theme('table', array(
+      'header' => $header,
+      'rows' => $rows,
+      'attributes' => array('id' => 'reorder_price_form'), // needed for table dragging
+    ));
+  }
