--- uc_tablequote.module	2010-04-16 22:41:21.940125000 +0300
+++ uc_tablequote_new.module	2010-04-16 23:09:25.893250000 +0300
@@ -158,7 +158,7 @@ function uc_tablequote_admin_settings_va
   }
   
   // check that max is bigger than min
-  if ($form_state['values']['uc_tablequote_maximum'] < $form_state['values']['uc_tablequote_minimum']) {
+  if ($form_state['values']['uc_tablequote_maximum'] && $form_state['values']['uc_tablequote_maximum'] <= $form_state['values']['uc_tablequote_minimum']) {
     form_set_error('uc_tablequote_maximum', t('The maximum value must be greater than the minumum value.'));
   }
   
@@ -215,24 +215,27 @@ function uc_tablequote_theme($form){
 
 function theme_uc_tablequote_admin_settings($form){
   $header = array(t('Delete'), t('Minimum value'), t('Maximum value'), t('Shipping Rate'));
+
   $result = db_query("SELECT * FROM {uc_tablequote} ORDER BY min");
-  $num_rows = db_result(db_query('SELECT COUNT(*) FROM {uc_tablequote} ORDER BY min'));
-  if ($num_rows == 0) {
+
+  while ($r = db_fetch_object($result)) {
+    $row = array();
+    $qid = $r->qid;
+    $r->rate > 0 ? $rate = $r->rate : $rate = 'Free';
+    $row[] = drupal_render($form['rates'][$qid]['delete']);
+    $row[] = $r->min;
+    $row[] = $r->max;
+    $row[] = $rate;
+    $rows[] = $row;
+  }
+
+  if (count($rows) == 0) {
     $rows[] = array(array('data' => t('No rates found.'), 'colspan' => 4));
   }
   else {
-    while ($r = db_fetch_object($result)) {
-      $row = array();
-      $qid = $r->qid;
-      $r->rate > 0 ? $rate = $r->rate : $rate = 'Free';
-      $row[] = drupal_render($form['rates'][$qid]['delete']);
-      $row[] = $r->min;
-      $row[] = $r->max;
-      $row[] = $rate;
-      $rows[] = $row;
-    }
     $rows[] = array(array('data' => t('Shipping quotes based on: ').variable_get('uc_tablequote_type','weight'), 'colspan' => 4));
   }
+
   $output .= theme('table', $header, $rows);
   
   $output .= drupal_render($form);
@@ -243,27 +246,39 @@ function theme_uc_tablequote_admin_setti
  * Module Functions                                                           *
  ******************************************************************************/
 function uc_tablequote_quote($products, $details) {
+
   $total = 0;
+  $type = variable_get('uc_tablequote_type', 'weight');
+
   foreach ($products as $product) {
-    if (variable_get('uc_tablequote_type', 'weight') == 'weight') {
-      $total += $product->qty * $product->weight * uc_weight_conversion($product->weight_units, variable_get('uc_weight_unit', 'lb'));
-    }
-    elseif (variable_get('uc_tablequote_type', 'weight') == 'order') {
-      $total += $product->price * $product->qty;
+
+    if ($product->shippable) {
+      switch($type) {
+        case 'order':
+          $total += $product->price * $product->qty;
+          break;
+        case 'weight:
+        default:
+          $total += $product->qty * $product->weight * uc_weight_conversion($product->weight_units, variable_get('uc_weight_unit', 'lb'));
+          break;
+      }
     }
   }
 
   $rate = 0;
+  $found = FALSE;
+
   $result = db_query("SELECT * FROM {uc_tablequote}");
   while ($r = db_fetch_object($result)) {
     if (($total >= $r->min) && ($total < $r->max)) {
       $rate = $r->rate;
+      $found = TRUE;
     }
   }
 
   $method = uc_tablequote_shipping_method();
   $quotes = array();
-  if ($rate > 0) {
+  if ($found) {
     $quotes[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $method['tablequote']['quote']['accessorials'][0]);
   }
 
