| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Adds a payment method to handle free orders.
|
| 6 |
*
|
| 7 |
* The groundwork for this module in core and an initial implementation were
|
| 8 |
* made possible by Warner Bros. Records.
|
| 9 |
*/
|
| 10 |
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_perm().
|
| 14 |
*/
|
| 15 |
function uc_free_order_perm() {
|
| 16 |
return array('test free order');
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_form_alter().
|
| 21 |
*/
|
| 22 |
function uc_free_order_form_alter($form_id, &$form) {
|
| 23 |
global $user;
|
| 24 |
|
| 25 |
// Alter the checkout form to prepare it for our special JS.
|
| 26 |
if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['payment'])) {
|
| 27 |
if (user_access('test free order')) {
|
| 28 |
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>');
|
| 29 |
}
|
| 30 |
|
| 31 |
drupal_add_js(drupal_get_path('module', 'uc_free_order') .'/uc_free_order.js');
|
| 32 |
|
| 33 |
$set = FALSE;
|
| 34 |
foreach (array_keys($form['panes']['payment']['payment_method']['#options']) as $key) {
|
| 35 |
if ($key !== 'free_order' && !$set) {
|
| 36 |
drupal_add_js("uc_free_order_next_method = '". $key ."';", 'inline');
|
| 37 |
$set = TRUE;
|
| 38 |
}
|
| 39 |
}
|
| 40 |
}
|
| 41 |
elseif ($form_id == 'uc_cart_checkout_review_form') {
|
| 42 |
$order = uc_order_load($_SESSION['cart_order']);
|
| 43 |
|
| 44 |
if ($order->payment_method == 'free_order') {
|
| 45 |
if ($order->order_total >= .01) {
|
| 46 |
drupal_set_message(t('We cannot process your order without payment.'), 'error');
|
| 47 |
drupal_goto('cart/checkout');
|
| 48 |
}
|
| 49 |
}
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Implementation of hook_payment_method().
|
| 55 |
*/
|
| 56 |
function uc_free_order_payment_method() {
|
| 57 |
$methods[] = array(
|
| 58 |
'id' => 'free_order',
|
| 59 |
'name' => t('Free order'),
|
| 60 |
'title' => t('Free order - payment not necessary.'),
|
| 61 |
'desc' => t('Allow customers with $0 order totals to checkout without paying.'),
|
| 62 |
'callback' => 'uc_payment_method_free_order',
|
| 63 |
'checkout' => TRUE,
|
| 64 |
'no_gateway' => TRUE,
|
| 65 |
'weight' => 10,
|
| 66 |
);
|
| 67 |
|
| 68 |
return $methods;
|
| 69 |
}
|
| 70 |
|
| 71 |
// Handles the free order payment method.
|
| 72 |
function uc_payment_method_free_order($op, &$arg1) {
|
| 73 |
switch ($op) {
|
| 74 |
case 'cart-details':
|
| 75 |
return t('Continue with checkout to complete your free order.');
|
| 76 |
|
| 77 |
/**
|
| 78 |
* Commented out this section b/c it wasn't firing in order. I've moved
|
| 79 |
* this logic to hook_form_alter() on the review form instead. Keeping this
|
| 80 |
* here in case I need to revisit this code. -RS
|
| 81 |
*/
|
| 82 |
|
| 83 |
/* case 'cart-process':
|
| 84 |
if ($arg1->payment_method == 'free_order') {
|
| 85 |
// Load the customer's gift card balance.
|
| 86 |
if ($arg1->order_total >= .01) {
|
| 87 |
drupal_set_message(t('We cannot process your order without payment.'), 'error');
|
| 88 |
return FALSE;
|
| 89 |
}
|
| 90 |
}
|
| 91 |
return TRUE;*/
|
| 92 |
}
|
| 93 |
}
|
| 94 |
|