Ubercart 3 check the stock before adding to the cart When a user enters in a quantity to add to their cart, I am trying to check that quantity against the stock level of that product, and when the stock is less than their quantity, it returns and error.  This is as far as I have gotten, and I am stuck.  Got any ideas?

function uc_check_stock_form_alter(&amp;$form,&amp;$form_state,$form_id) {
  if ($form_id == 'uc_product_add_to_cart_form_') {
    $form['#validate'][] = 'uc_check_stock_form_validate';
  }
  return $form;
}


function uc_check_stock_form_validate($form, &amp;$form_state) {

  $stock = db_result(db_query("SELECT `stock` FROM `uc_product_stock` WHERE `nid` = '%d'", $form_state['values']['node']-&gt;nid));
  if (is_numeric($stock) &amp;&amp; $stock &lt; $form_state['values']['qty']) {
  form_set_error('qty', t('Quantity is greater than our available stock. Please adjust your quantity for the this item.'));
  }
}
Someone created a module for that already, needs some fixing IMHO, maybe you can play with that and make something better, I'll definitely be very thankful...