You are here

function uc_product_validate in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_product/uc_product.module \uc_product_validate()

File

uc_product/uc_product.module, line 632
The product module for Ubercart.

Code

function uc_product_validate($node) {
  $pattern = '/^\\d*(\\.\\d*)?$/';
  $price_error = t('Price must be in a valid number format. No commas and only one decimal point.');
  if (!empty($node->list_price) && !is_numeric($node->list_price) && !preg_match($pattern, $node->list_price)) {
    form_set_error('list_price', $price_error);
  }
  if (!empty($node->cost) && !is_numeric($node->cost) && !preg_match($pattern, $node->cost)) {
    form_set_error('cost', $price_error);
  }
  if (!is_numeric($node->sell_price) && !preg_match($pattern, $node->sell_price)) {
    form_set_error('sell_price', $price_error);
  }
  if (!empty($node->weight) && !is_numeric($node->weight)) {
    form_set_error('weight', t('Weight must be in a valid number format. No commas and only one decimal point.'));
  }
  if ($node->default_qty) {
    if (!is_numeric($node->default_qty)) {
      form_set_error('default_qty', t('Quantities should be numeric.'));
    }
    else {
      if ($node->default_qty < 0) {
        form_set_error('default_qty', t("Adding negative items to the cart doesn't make sense, so don't make it easy."));
      }
    }
  }
}