uc_free_order.module in UC Free Order Payment Method 5
File
uc_free_order.module
View source
<?php
function uc_free_order_perm() {
return array(
'test free order',
);
}
function uc_free_order_form_alter($form_id, &$form) {
global $user;
if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['payment'])) {
if (user_access('test free order')) {
drupal_set_message('Test free order: <span style="cursor: pointer;" onclick="alert(\'Discount added.\'); set_line_item(\'fo_discount\', \'Test Discount\', -2000, 0);">Add discount</span> | <span style="cursor: pointer;" onclick="alert(\'Discount removed.\'); remove_line_item(\'fo_discount\');">Remove discount</span>');
}
drupal_add_js(drupal_get_path('module', 'uc_free_order') . '/uc_free_order.js');
$set = FALSE;
foreach (array_keys($form['panes']['payment']['payment_method']['#options']) as $key) {
if ($key !== 'free_order' && !$set) {
drupal_add_js("uc_free_order_next_method = '" . $key . "';", 'inline');
$set = TRUE;
}
}
}
elseif ($form_id == 'uc_cart_checkout_review_form') {
$order = uc_order_load($_SESSION['cart_order']);
if ($order->payment_method == 'free_order') {
if ($order->order_total >= 0.01) {
drupal_set_message(t('We cannot process your order without payment.'), 'error');
drupal_goto('cart/checkout');
}
}
}
}
function uc_free_order_payment_method() {
$methods[] = array(
'id' => 'free_order',
'name' => t('Free order'),
'title' => t('Free order - payment not necessary.'),
'desc' => t('Allow customers with $0 order totals to checkout without paying.'),
'callback' => 'uc_payment_method_free_order',
'checkout' => TRUE,
'no_gateway' => TRUE,
'weight' => 10,
);
return $methods;
}
function uc_payment_method_free_order($op, &$arg1) {
switch ($op) {
case 'cart-details':
return t('Continue with checkout to complete your free order.');
}
}