--- uc_product_minmax.module	2010-01-26 17:44:28.000000000 -0600
+++ uc_product_minmaxNEW.module	2010-02-09 16:33:08.000000000 -0600
@@ -403,6 +403,43 @@ function uc_product_minmax_form_alter(&$
       $form['qty']['#description'] = $output;
     }
   }
+  
+  if($form_id == 'uc_cart_view_form') {
+    $form['#validate'][] = 'uc_product_minmax_qty_validate';
+  }
+}
+
+function uc_product_minmax_qty_validate($form, &$form_state) {
+  foreach($form_state['values']['items'] as &$item) {
+    $nid = $item['nid'];
+    $qty = $item['qty'];
+    
+    $minmaxresult = db_fetch_object(db_query("SELECT * FROM {uc_product_minmax} WHERE nid = %s", $nid));
+    $fail = 0;
+    if ($qty < $minmaxresult->product_min) {
+      $fail = 1;
+      $message[] = t('The minimum order quantity for this item is @qty.', array('@qty' => $minmaxresult->product_min));
+    }
+    if ($minmaxresult->pmin_multiple && $qty % $minmaxresult->pmin_multiple != 0) {
+      $fail = 1;
+      $message[] = t('This item must be ordered in multiples of @qty.', array('@qty' => $minmaxresult->pmin_multiple));
+    }
+    if ($minmaxresult->product_max && $qty > $minmaxresult->product_max && $minmaxresult->product_max != 0) {
+      $fail = 1;
+      $message[] = t('The maximum order quantity for this item is @qty.', array('@qty' => $minmaxresult->product_max));
+    }
+    if ($fail) {
+      $message[] = t('Please check your quantity and try again.');
+      $result[] = array(
+        'success' => FALSE,
+        'message' => theme('item_list', $message),
+      );
+    }
+
+    if($fail == 1) {
+      form_set_error('items', $message[0]);
+    }
+  }
 }
 
 /*******************************************************************************
