function uc_atctweaks_form_alter in UC Add to Cart Tweaks 6
Same name and namespace in other branches
- 7 uc_atctweaks.module \uc_atctweaks_form_alter()
Implementation of hook_form_alter().
Summary of alterations: 1) Alters the product feature add form to restrict multiple Add to Cart Tweak features from being added to a single product. 2) Alters the add to cart form for variable priced products. 3) Alter the product class form to set default add to cart tweaks.
File
- ./
uc_atctweaks.module, line 18 - Defines a product feature to tweak the add to cart form behavior.
Code
function uc_atctweaks_form_alter(&$form, &$form_state, $form_id) {
// 1) Alter the product feature add form.
if ($form_id == 'uc_product_feature_add_form') {
// If an add to cart tweak has already been added to this product...
if (db_result(db_query("SELECT COUNT(*) FROM {uc_product_features} WHERE nid = %d AND fid = '%s'", arg(1), 'atctweaks'))) {
// Remove Add to Cart Tweak from the available list of features to add.
unset($form['feature']['#options']['atctweaks']);
}
}
// 2) Alters the add to cart form for variable priced products.
if (strpos($form_id, 'uc_product_add_to_cart_form_') === 0) {
$data = uc_atctweaks_product_load($form['nid']['#value']);
if ($data) {
$form['atctweaks_data'] = array(
'#type' => 'value',
'#value' => $data,
);
$form['#submit'] = array_merge(array(
'uc_atctweaks_add_to_cart_pre_submit',
), $form['#submit']);
$form['#submit'][] = 'uc_atctweaks_add_to_cart_post_submit';
}
}
// 3) Alter the product class form to set default add to cart tweaks.
if ($form_id == 'uc_product_class_form') {
$data = variable_get('ucatc_class_def_' . $form['pcid']['#value'], array());
if (!empty($data)) {
$data = (object) unserialize($data);
}
else {
$data = FALSE;
}
$form['atctweaks'] = array(
'#type' => 'fieldset',
'#title' => t('Default Add to Cart Tweaks'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 5,
);
$form['atctweaks']['default_atctweaks'] = array(
'#type' => 'checkbox',
'#title' => t('Check this box to add default Add to Cart Tweaks to every product of this class using these settings.'),
'#default_value' => $data === FALSE ? FALSE : TRUE,
);
$form['atctweaks'] += _uc_atctweaks_feature_form($data);
$form['#submit'][] = 'uc_atctweaks_product_class_submit';
$form['submit']['#weight'] = 10;
}
}