function uc_product_kit_form in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_product_kit/uc_product_kit.module \uc_product_kit_form()
- 7.3 uc_product_kit/uc_product_kit.module \uc_product_kit_form()
Implementation of hook_form().
File
- uc_product_kit/
uc_product_kit.module, line 300 - The product kit module for Übercart.
Code
function uc_product_kit_form(&$node) {
$form = array();
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#required' => TRUE,
'#weight' => -5,
'#default_value' => $node->title,
'#description' => t('Name of the product kit'),
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#required' => FALSE,
'#default_value' => $node->body,
'#rows' => 20,
'#description' => t('Explain these whatchamacallits.'),
);
$form['body_filter']['format'] = filter_form($node->format);
$form['body_filter']['#weight'] = -4;
$product_types = module_invoke_all('product_types');
$products = array();
unset($product_types[array_search('product_kit', $product_types)]);
$result = db_query("SELECT nid, title FROM {node} WHERE type IN ('" . implode("','", $product_types) . "') ORDER BY title, nid");
while ($product = db_fetch_object($result)) {
$products[$product->nid] = $product->title;
}
$form['base'] = array(
'#type' => 'fieldset',
'#title' => t('Product Information'),
'#collapsible' => true,
'#collapsed' => false,
'#weight' => -1,
'#attributes' => array(
'class' => 'product-field',
),
);
$form['base']['mutable'] = array(
'#type' => 'radios',
'#title' => t('How is this product kit handled by the cart?'),
'#options' => array(
UC_PRODUCT_KIT_UNMUTABLE_NO_LIST => t('As a unit. Customers may only change how many kits they are buying. Do not list component products.'),
UC_PRODUCT_KIT_UNMUTABLE_WITH_LIST => t('As a unit. Customers may only change how many kits they are buying. List component products.'),
UC_PRODUCT_KIT_MUTABLE => t('As individual products. Customers may add or remove kit components at will.'),
),
'#default_value' => isset($node->mutable) ? $node->mutable : variable_get('uc_product_kit_mutable', UC_PRODUCT_KIT_UNMUTABLE_WITH_LIST),
);
$form['base']['products'] = array(
'#type' => 'select',
'#multiple' => true,
'#required' => true,
'#title' => t('Products'),
'#options' => $products,
'#default_value' => isset($node->products) ? array_keys($node->products) : array(),
);
$form['base']['items'] = array(
'#tree' => true,
);
if (isset($node->products)) {
foreach ($node->products as $i => $product) {
$form['base']['items'][$i] = array(
'#type' => 'fieldset',
);
$form['base']['items'][$i]['link'] = array(
'#type' => 'item',
'#value' => l($product->title, 'node/' . $i),
);
$form['base']['items'][$i]['qty'] = array(
'#type' => 'textfield',
'#title' => t('Quantity'),
'#default_value' => $product->qty,
'#size' => 5,
);
$form['base']['items'][$i]['ordering'] = array(
'#type' => 'weight',
'#title' => t('Ordering'),
'#default_value' => isset($product->ordering) ? $product->ordering : 0,
);
$item = node_load($i);
$form['base']['items'][$i]['discount'] = array(
'#type' => 'textfield',
'#title' => t('Discount'),
'#description' => t('Enter a negative value to lower the item price by that amount. Enter a postive value to set the item price to that amount. This discount is applied to each %product in the kit.', array(
'%product' => $product->title,
)),
'#default_value' => is_null($product->discount) || $product->discount === '' ? $item->sell_price : $product->discount,
'#size' => 5,
);
}
}
$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 order'),
'#delta' => 25,
'#default_value' => $node->ordering,
'#weight' => 30,
);
return $form;
}