--- C:/Documents and Settings/drupal 7 modules/commerce_shipping-7.x-1.0/commerce_shipping/commerce_shipping.module	Sun Jan 01 03:37:04 2012
+++ C:/Documents and Settings/drupal7/sites/all/modules/commerce_shipping/commerce_shipping.module	Sat Apr 14 15:09:16 2012
@@ -90,7 +90,20 @@
 
   return $line_item_types;
 }
-
+/**
+ * Implements hook_commerce_cart_line_item_refresh().
+ */
+function commerce_shipping_commerce_cart_line_item_refresh($cloned_line_item, $order_wrapper) {
+    
+    if ($cloned_line_item->type == "shipping") {
+	  // Only process a line item once
+	  static $processed = array();
+	  if (!isset($processed[$cloned_line_item->line_item_id])) $processed[$cloned_line_item->line_item_id] = 1;
+	  else $processed[$cloned_line_item->line_item_id]++;
+	  if ($processed[$cloned_line_item->line_item_id] > 1) return;
+	  commerce_shipping_repopulate_shipping($cloned_line_item);
+	}
+}
 /**
  * Ensures the shipping line item type contains a field for shipping method.
  *
@@ -496,4 +509,102 @@
   foreach ($line_items_to_delete as $line_item_id) {
     commerce_line_item_delete($line_item_id);
   }
+}
+
+function commerce_shipping_repopulate_shipping($line_item) {
+
+	$order = commerce_order_load($line_item->order_id);
+	if ($line_item->type != "shipping") return;
+	
+    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+	$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+	$shipping_line_item_id = $line_item_wrapper->commerce_shipping_method->value();
+	if (!isset($shipping_line_item_id)) return; // nothing to do
+	
+    $plugin = commerce_shipping_method_instance_load($order->data['shipping_method']);
+    $class = new $plugin['handler']['class']($plugin['settings'], $order);
+	
+    $default_currency_code = commerce_default_currency();
+    if ($balance = commerce_payment_order_balance($order)) {
+      $default_currency_code = $balance['currency_code'];
+    }
+	// We have to recreate the variables that go into the form submission which shipping plugins are set up for
+	if ($order->commerce_customer_shipping[LANGUAGE_NONE][0]['profile_id'] > 0) {
+	  $form_state['input']['customer_profile_shipping'] =  (array) commerce_customer_profile_load($order->commerce_customer_shipping[LANGUAGE_NONE][0]['profile_id']);
+	}
+	if ($order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'] > 0) {
+	  $form_state['input']['customer_profile_billing'] =  (array) commerce_customer_profile_load($order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id']);
+	}
+    $form_values = array();
+	$form = array();
+    // Let the shipping method calculate the shipping price.
+    $plugin = commerce_shipping_plugin_get_plugin('quotes', $shipping_line_item_id);
+	
+    $shipping_line_items = $class->calculate_quote($default_currency_code, $form_values, $order, $form, $form_state);
+    
+    // Loop through the result and create line items if possible.
+    if (is_array($shipping_line_items)) {
+      foreach ($shipping_line_items as $shipping_line_item) {
+	    if ($shipping_line_item['label'] == $line_item->line_item_label) {
+		
+        if (is_numeric($shipping_line_item)) {
+          $price = array(
+            'amount' => $shipping_line_item,
+          );
+        }
+        elseif (isset($shipping_line_item['amount'])) {
+          $price = array(
+            'amount' => $shipping_line_item['amount'],
+            'currency_code' => !empty($shipping_line_item['currency_code']) ? $shipping_line_item['currency_code'] : $default_currency_code,
+          );
+        }
+        elseif (isset($shipping_line_item['price'])) {
+            $price = $shipping_line_item['price'];
+        }
+        if (isset($shipping_line_item['label'])) {
+          $line_item_wrapper->line_item_label = $shipping_line_item['label'];
+        }
+        if (isset($shipping_line_item['quantity'])) {
+          $line_item_wrapper->quantity = $shipping_line_item['quantity'];
+        }
+
+        // Require that the price is set.
+        if (isset($price)) {
+          // Add component if needed
+          if (empty($price['data']['components'])) {
+            $price_component = 'quote';
+            if (!empty($plugin['price_component'])) {
+              $price_component = 'quote_' . $plugin['name'];
+            }
+            $price['data'] = commerce_price_component_add(
+              $price,
+              $price_component,
+              $price,
+              TRUE,
+              FALSE
+            );
+          }
+          // Make sure the currency code is set.
+          if (empty($price['currency_code'])) {
+            $price['currency_code'] = $default_currency_code;
+          }
+		  
+          $line_item_wrapper->commerce_unit_price = $price;
+		  
+          rules_invoke_all('commerce_shipping_calculate', $line_item);
+          $line_item_wrapper->save();
+		  //  Remove any entries for the current line item id
+		  foreach ($order_wrapper->commerce_line_items as $delta => $wrapper) {
+			if ($wrapper->value()->line_item_id == $line_item->line_item_id) {
+		      $order_wrapper->commerce_line_items->offsetUnset($delta);
+			}
+		  }
+          $order_wrapper->commerce_line_items[] = $line_item_wrapper->value();
+		  }
+        }
+      }
+    }
+    else return;
+    // Lastly we save the order.
+    commerce_order_save($order_wrapper->value());
 }
