You are here

function uc_product_form in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_product/uc_product.module \uc_product_form()
  2. 7.3 uc_product/uc_product.module \uc_product_form()

Implements hook_form().

See also

theme_uc_product_form_prices()

theme_uc_product_form_weight()

theme_uc_product_dimensions()

uc_product_form_validate()

File

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

Code

function uc_product_form(&$node) {
  $type = node_get_types('type', $node);
  $sign_flag = variable_get('uc_sign_after_amount', FALSE);
  $currency_sign = variable_get('uc_currency_sign', '$');
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#maxlength' => 255,
    '#weight' => -5,
  );
  if ($type->has_body) {
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
    $form['body_field']['body']['#description'] = t('Enter the product description used for product teasers and pages.');
    $form['body_field']['#weight'] = -4;
  }
  $form['base'] = array(
    '#type' => 'fieldset',
    '#title' => t('Product information'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => -1,
    '#attributes' => array(
      'class' => 'product-field',
    ),
  );
  $form['base']['model'] = array(
    '#type' => 'textfield',
    '#title' => t('SKU'),
    '#required' => TRUE,
    '#default_value' => isset($node->model) ? $node->model : '',
    '#description' => t('Product SKU/model.'),
    '#weight' => 0,
    '#size' => 32,
  );
  $form['base']['prices'] = array(
    '#weight' => 5,
    '#theme' => 'uc_product_form_prices',
  );
  $form['base']['prices']['list_price'] = array(
    '#type' => 'textfield',
    '#title' => t('List price'),
    '#required' => FALSE,
    '#default_value' => isset($node->list_price) ? uc_store_format_price_field_value($node->list_price) : 0,
    '#description' => t('The listed MSRP.'),
    '#weight' => 0,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['base']['prices']['cost'] = array(
    '#type' => 'textfield',
    '#title' => t('Cost'),
    '#required' => FALSE,
    '#default_value' => isset($node->cost) ? uc_store_format_price_field_value($node->cost) : 0,
    '#description' => t("Your store's cost."),
    '#weight' => 1,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['base']['prices']['sell_price'] = array(
    '#type' => 'textfield',
    '#title' => t('Sell price'),
    '#required' => TRUE,
    '#default_value' => isset($node->sell_price) ? uc_store_format_price_field_value($node->sell_price) : 0,
    '#description' => t('Customer purchase price.'),
    '#weight' => 2,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['base']['shippable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Product and its derivatives are shippable.'),
    '#default_value' => isset($node->shippable) ? $node->shippable : variable_get('uc_product_shippable_' . $node->type, 1),
    '#weight' => 10,
  );
  $form['base']['weight'] = array(
    '#weight' => 15,
    '#theme' => 'uc_product_form_weight',
  );
  $form['base']['weight']['weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#default_value' => isset($node->weight) ? $node->weight : 0,
    '#size' => 10,
    '#maxlength' => 15,
  );
  $units = array(
    'lb' => t('Pounds'),
    'kg' => t('Kilograms'),
    'oz' => t('Ounces'),
    'g' => t('Grams'),
  );
  $form['base']['weight']['weight_units'] = array(
    '#type' => 'select',
    '#title' => t('Unit of measurement'),
    '#default_value' => isset($node->weight_units) ? $node->weight_units : variable_get('uc_weight_unit', 'lb'),
    '#options' => $units,
  );
  $form['base']['dimensions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Dimensions'),
    '#description' => t('Physical dimensions of the packaged product.'),
    '#weight' => 20,
    '#theme' => 'uc_product_dimensions_form',
  );
  $form['base']['dimensions']['length_units'] = array(
    '#type' => 'select',
    '#title' => t('Units of measurement'),
    '#options' => array(
      'in' => t('Inches'),
      'ft' => t('Feet'),
      'cm' => t('Centimeters'),
      'mm' => t('Millimeters'),
    ),
    '#default_value' => isset($node->length_units) ? $node->length_units : variable_get('uc_length_unit', 'in'),
  );
  $form['base']['dimensions']['dim_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Length'),
    '#default_value' => isset($node->length) ? $node->length : '',
    '#size' => 10,
  );
  $form['base']['dimensions']['dim_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => isset($node->width) ? $node->width : '',
    '#size' => 10,
  );
  $form['base']['dimensions']['dim_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => isset($node->height) ? $node->height : '',
    '#size' => 10,
  );
  $form['base']['pkg_qty'] = array(
    '#type' => 'uc_quantity',
    '#title' => t('Package quantity'),
    '#default_value' => isset($node->pkg_qty) ? $node->pkg_qty : 1,
    '#description' => t('At most, how many of these items can fit in your largest box? Orders that exceed this value will be split into multiple packages when retrieving shipping quotes.'),
    '#weight' => 25,
  );
  $form['base']['default_qty'] = array(
    '#type' => 'uc_quantity',
    '#title' => t('Default quantity to add to cart'),
    '#default_value' => isset($node->default_qty) ? $node->default_qty : 1,
    '#description' => t('Use 0 to disable the quantity field next to the add to cart button.'),
    '#weight' => 27,
    '#allow_zero' => TRUE,
  );
  $form['base']['ordering'] = array(
    '#type' => 'weight',
    '#title' => t('List position'),
    '#description' => t("Specify a value to set this product's position in product lists.<br />Products in the same position will be sorted alphabetically."),
    '#delta' => 25,
    '#default_value' => isset($node->ordering) ? $node->ordering : 0,
    '#weight' => 30,
  );
  return $form;
}