function uc_pma_form_alter in Ubercart Payment Method Adjustments 7
Same name and namespace in other branches
- 6 uc_pma.module \uc_pma_form_alter()
Implements hook_form_alter().
File
- ./
uc_pma.module, line 27 - This module hooks into a few different parts of Ubercart to allow store administrators to associate a fee or discount with payment methods.
Code
function uc_pma_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'uc_payment_methods_form') {
$methods_info = '<div>' . t('The adjustment field can be used to associate a fee or discount with a payment method. Specify a value that is a flat amount or a percentage of the subtotal to be added or subtracted when a payment method is chosen at checkout. Examples: 3%, 1.00, -5.5%, -2') . '</div><br />';
if (isset($form['methods_info'])) {
$form['methods_info']['#value'] .= $methods_info;
}
else {
$form['methods_info']['#value'] = $methods_info;
}
$form['pmtable']['#theme'] = 'uc_pma_payment_method_table';
foreach (element_children($form['pmtable']) as $method_id) {
$form['pmtable'][$method_id]['uc_payment_method_' . $method_id . '_adjustment'] = array(
'#type' => 'textfield',
'#summary callback' => 'summarize_null',
'#default_value' => variable_get('uc_payment_method_' . $method_id . '_adjustment', ''),
'#size' => '9',
);
}
$form['uc_pma'] = array(
'#type' => 'fieldset',
'#title' => t('Payment Method Adjustments'),
);
$form['uc_pma']['uc_pma_adjustments_apply_to'] = array(
'#type' => 'checkboxes',
'#title' => t('Apply UC_PMA adjustments to:'),
'#default_value' => variable_get('uc_pma_adjustments_apply_to', array(
'products',
)),
'#description' => t('UC_PMA adjustments always apply to products, but not by default to line items like shipping.'),
'#options' => array(
'shipping' => t('Shipping'),
),
);
}
elseif ($form_id == 'uc_cart_checkout_form') {
foreach ($form['panes']['payment']['payment_method']['#options'] as $key => $value) {
$adjustment = variable_get('uc_payment_method_' . $key . '_adjustment', '');
if (!empty($adjustment)) {
$form['panes']['payment']['payment_method']['#options'][$key] .= '<div class="description" style="padding-left: 2.5em;">' . payment_method_adjustment_description($key) . '</div>';
}
}
//replace default payment pane ajax behaviour with own
$form['panes']['payment']['payment_method']['#ajax'] = array(
'callback' => 'uc_pma_payment_method_ajax',
'progress' => array(
'type' => 'throbber',
),
);
}
}