--- uc_minpercentrate.module	2009-07-05 00:58:08.000000000 -0400
+++ uc_minpercentrate-new.module	2009-11-03 13:08:17.000000000 -0500
@@ -71,7 +71,7 @@ function uc_minpercentrate_form_alter(&$
         '#type' => 'textfield',
         '#title' => $method->title,
         '#default_value' => $form['#node']->minpercentrate[$method->mid],
-        '#description' => t('Default rate: %rate', array('%rate' => uc_currency_format($method->minpercent_rate))),
+        '#description' => t('Default rate: %rate', array('%rate' => $method->percent_rate)),
         '#size' => 16,
         '#field_suffix' => '%',
         '#weight' => $weight['minpercentrate_'. $method->mid],
@@ -93,6 +93,10 @@ function uc_minpercentrate_nodeapi(&$nod
             db_query("DELETE FROM {uc_minpercentrate_products} WHERE vid = %d", $node->vid);
           }
           foreach ($node->minpercentrate as $mid => $rate) {
+            if ($rate == -1) {
+              $method = db_fetch_object(db_query('SELECT percent_rate FROM {uc_minpercentrate_methods} WHERE mid=%d', $mid));
+              $rate = $method->percent_rate;
+            }
             if ($rate !== '') {
               db_query("INSERT INTO {uc_minpercentrate_products} (vid, nid, mid, rate) VALUES (%d, %d, %d, %f)",
                 $node->vid, $node->nid, $mid, $rate);
@@ -202,33 +206,40 @@ function uc_minpercentrate_shipping_meth
 function uc_minpercentrate_quote($products, $details, $method) {
   $method = explode('_', $method['id']);
   $mid = $method[1];
-  if ($method = db_fetch_object(db_query("SELECT * FROM {uc_minpercentrate_methods} WHERE mid = %d", $mid))) {
 
+  if($method = db_fetch_object(db_query("SELECT * FROM {uc_minpercentrate_methods} WHERE mid = %d", $mid))) {
     foreach ($products as $product) {
-		
-    $sub_total += $product->sell_price * $product->qty;	
-
-        $rate1 = $method->percent_rate * $sub_total / 100 ;
-		
-		if ($rate1 <= $method->base_rate ) {
-		$rate = $method->base_rate; } 
-		
-	  if($rate1 >= $method->base_rate ) {  
-		$rate = $rate1; }
-
-	  if($method->free_rate <= $sub_total) {  
-		$rate =  0 ;}
-			
+    
+      if($product->minpercentrate[$mid]) {
+        $percent_rate = $product->minpercentrate[$mid];
+      }
+      else {
+        $percent_rate = $method->percent_rate;
+      }
 	
-	}
+      $sub_total += $product->sell_price * $product->qty;	
 
+      $rate1 = $percent_rate * $sub_total / 100 ;
+	
+  		if ($rate1 < $method->base_rate ) {
+  		  $rate = $method->base_rate; 
+  		} 
 	
-    if ($rate == 0) {
-    $quotes[] = array('rate' => $rate, 'format' => 'FREE', 'option_label' => check_plain($method->label)); }
+      if($rate1 > $method->base_rate ) {  
+  	    $rate = $rate1; 
+  	  }
+
+      if($method->free_rate <= $sub_total) {  
+  	    $rate =  0 ;
+  	  }
+    }
+  }
 
-    if ($rate != 0) {
-    $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => check_plain($method->label)); }
- 
+  if ($rate != 0) {
+    $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' =>  check_plain($method->label)); 
+  }
+  else {
+    $quotes[] = array('rate' => $rate, 'format' => 'FREE', 'option_label' => check_plain($method->label)); 
   }
 
   return $quotes;
