function uc_attribute_uc_form_alter in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_attribute/uc_attribute.module \uc_attribute_uc_form_alter()
- 7.3 uc_attribute/uc_attribute.module \uc_attribute_uc_form_alter()
Implements hook_uc_form_alter().
Attaches option selectors to the form with the "Add to Cart" button.
This function also handles selecting attributes for products added to orders manually.
File
- uc_attribute/
uc_attribute.module, line 339
Code
function uc_attribute_uc_form_alter(&$form, &$form_state, $form_id) {
if (strpos($form_id, 'add_to_cart_form') || strpos($form_id, 'add_product_form')) {
$node =& $form['node']['#value'];
// If the node has a product list, add attributes to them
if (isset($form['products']) && count(element_children($form['products']))) {
foreach (element_children($form['products']) as $key) {
$form['products'][$key]['attributes'] = _uc_attribute_alter_form(node_load($key));
if (is_array($form['products'][$key]['attributes'])) {
$form['products'][$key]['attributes']['#tree'] = TRUE;
$form['products'][$key]['#type'] = 'fieldset';
}
}
}
else {
$form['attributes'] = _uc_attribute_alter_form($node);
if (is_array($form['attributes'])) {
$form['attributes']['#tree'] = TRUE;
$form['attributes']['#weight'] = -1;
}
}
}
}