You are here

function uc_product_form in Ubercart 5

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

Implementation of 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 421
The product module for Ubercart.

Code

function uc_product_form(&$node) {
  $type = node_get_types('type', $node);
  $location = array();
  $location[] = menu_get_item(null, 'admin');
  $location[] = menu_get_item(null, 'admin/store');
  $location[] = menu_get_item(null, 'admin/store/products');
  $location[] = menu_get_item(null, 'admin/store/settings/products');
  $breadcrumb = array();
  foreach ($location as $item) {
    $breadcrumb[] = l($item['title'], $item['path']);
  }
  drupal_set_breadcrumb($breadcrumb);
  $sign_flag = variable_get('uc_sign_after_amount', FALSE);
  $currency_sign = variable_get('uc_currency_sign', '$');
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => $type->title_label,
    '#required' => TRUE,
    '#weight' => -5,
    '#default_value' => $node->title,
    '#description' => t('Name of the product.'),
  );
  if ($type->has_body) {
    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => $type->body_label,
      '#required' => FALSE,
      '#default_value' => $node->body,
      '#rows' => 20,
      '#description' => t('Enter the product description used for product teasers and pages.'),
    );
    $form['body_filter']['format'] = filter_form($node->format);
    $form['body_filter']['#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' => $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' => $node->list_price,
    '#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' => $node->cost,
    '#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' => $node->sell_price,
    '#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 : TRUE,
    '#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' => $node->weight,
    '#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' => $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' => $node->length_units ? $node->length_units : variable_get('uc_length_unit', 'in'),
  );
  $form['base']['dimensions']['length'] = array(
    '#type' => 'textfield',
    '#title' => t('Length'),
    '#default_value' => $node->length,
    '#size' => 10,
  );
  $form['base']['dimensions']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $node->width,
    '#size' => 10,
  );
  $form['base']['dimensions']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $node->height,
    '#size' => 10,
  );
  $form['base']['pkg_qty'] = array(
    '#type' => 'textfield',
    '#title' => t('Package quantity'),
    '#default_value' => $node->pkg_qty ? $node->pkg_qty : 1,
    '#description' => t('For a package containing only this product, how many are in it?'),
    '#weight' => 25,
  );
  $form['base']['default_qty'] = array(
    '#type' => 'textfield',
    '#title' => t('Default quantity to add to cart'),
    '#default_value' => !is_null($node->default_qty) ? $node->default_qty : 1,
    '#description' => t('Leave blank or zero to disable the quantity field in the add to cart form.'),
    '#weight' => 27,
    '#size' => 5,
    '#maxlength' => 6,
  );
  $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' => $node->ordering,
    '#weight' => 30,
  );
  return $form;
}