function uc_product_form in Ubercart 7.3
Same name and namespace in other branches
- 5 uc_product/uc_product.module \uc_product_form()
- 6.2 uc_product/uc_product.module \uc_product_form()
Implements hook_form().
File
- uc_product/
uc_product.module, line 316 - The product module for Ubercart.
Code
function uc_product_form($node, $form_state) {
$type = node_type_get_type($node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#maxlength' => 255,
'#weight' => -5,
);
$form['base'] = array(
'#type' => 'fieldset',
'#title' => t('Product information'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -10,
'#attributes' => array(
'class' => array(
'product-field',
),
),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'uc_product') . '/uc_product.js',
),
),
);
$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(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'uc-inline-form',
'clearfix',
),
),
'#weight' => 5,
);
$form['base']['prices']['list_price'] = array(
'#type' => 'uc_price',
'#title' => t('List price'),
'#default_value' => $node->list_price,
'#description' => t('The listed MSRP.'),
'#weight' => 0,
);
$form['base']['prices']['cost'] = array(
'#type' => 'uc_price',
'#title' => t('Cost'),
'#default_value' => $node->cost,
'#description' => t("Your store's cost."),
'#weight' => 1,
);
$form['base']['prices']['sell_price'] = array(
'#type' => 'uc_price',
'#title' => t('Sell price'),
'#required' => TRUE,
'#default_value' => $node->sell_price,
'#description' => t('Customer purchase price.'),
'#weight' => 2,
);
$form['base']['shippable'] = array(
'#type' => 'checkbox',
'#title' => t('Product is shippable.'),
'#default_value' => $node->shippable,
'#weight' => 10,
);
$form['base']['weight'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'uc-inline-form',
'clearfix',
),
),
'#states' => array(
'invisible' => array(
'input[name="shippable"]' => array(
'checked' => FALSE,
),
),
),
'#weight' => 15,
);
$form['base']['weight']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => $node->weight,
'#size' => 10,
'#element_validate' => array(
'uc_store_validate_number',
),
);
$units = array(
'lb' => t('Pounds'),
'kg' => t('Kilograms'),
'oz' => t('Ounces'),
'g' => t('Grams'),
);
$form['base']['weight']['weight_units'] = array(
'#type' => 'select',
'#title' => t('Units'),
'#default_value' => $node->weight_units,
'#options' => $units,
);
$form['base']['dimensions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'uc-inline-form',
'clearfix',
),
),
'#states' => array(
'invisible' => array(
'input[name="shippable"]' => array(
'checked' => FALSE,
),
),
),
'#weight' => 20,
);
$form['base']['dimensions']['dim_length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => $node->length,
'#size' => 10,
'#element_validate' => array(
'uc_store_validate_number',
),
);
$form['base']['dimensions']['dim_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $node->width,
'#size' => 10,
'#element_validate' => array(
'uc_store_validate_number',
),
);
$form['base']['dimensions']['dim_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $node->height,
'#size' => 10,
'#element_validate' => array(
'uc_store_validate_number',
),
);
$form['base']['dimensions']['length_units'] = array(
'#type' => 'select',
'#title' => t('Units'),
'#options' => array(
'in' => t('Inches'),
'ft' => t('Feet'),
'cm' => t('Centimeters'),
'mm' => t('Millimeters'),
),
'#default_value' => $node->length_units,
);
$form['base']['pkg_qty'] = array(
'#type' => 'uc_quantity',
'#title' => t('Maximum package quantity'),
'#default_value' => $node->pkg_qty,
'#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,
'#states' => array(
'invisible' => array(
'input[name="shippable"]' => array(
'checked' => FALSE,
),
),
),
);
if (variable_get('uc_product_add_to_cart_qty', FALSE)) {
$form['base']['default_qty'] = array(
'#type' => 'uc_quantity',
'#title' => t('Default quantity to add to cart'),
'#default_value' => $node->default_qty,
'#description' => t('Use 0 to disable the quantity field next to the add to cart button.'),
'#weight' => 27,
'#allow_zero' => TRUE,
);
}
else {
$form['base']['default_qty'] = array(
'#type' => 'value',
'#value' => $node->default_qty,
);
}
$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;
}