| 1 |
// $Id$
|
| 2 |
|
| 3 |
var uc_free_order_next_method = '';
|
| 4 |
var using_free_order = -1;
|
| 5 |
|
| 6 |
// Adds a click function to the total so we can check its updated values.
|
| 7 |
$(document).ready(
|
| 8 |
function() {
|
| 9 |
$('#edit-panes-payment-current-total').click(function() { free_order_check_total(this.value); });
|
| 10 |
}
|
| 11 |
);
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Checks the current total and updates the available/selected payment methods
|
| 15 |
* accordingly.
|
| 16 |
*/
|
| 17 |
function free_order_check_total(total) {
|
| 18 |
total = parseFloat(total);
|
| 19 |
|
| 20 |
if (total >= .01) {
|
| 21 |
// Disable the free order option and select the first available method.
|
| 22 |
if (using_free_order != 0) {
|
| 23 |
// Show the other payment method radios.
|
| 24 |
$("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
|
| 25 |
|
| 26 |
// Hide the free order radio.
|
| 27 |
$("input:radio[@value=free_order]").attr('disabled', 'disabled').parent().hide(0);
|
| 28 |
|
| 29 |
// Select the first payment method.
|
| 30 |
$("input:radio[@value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
|
| 31 |
|
| 32 |
// Refresh the payment details section.
|
| 33 |
get_payment_details('cart/checkout/payment_details/' + uc_free_order_next_method);
|
| 34 |
|
| 35 |
using_free_order = 0;
|
| 36 |
}
|
| 37 |
}
|
| 38 |
else {
|
| 39 |
// Disable the CC option and select the gift card option.
|
| 40 |
if (using_free_order != 1) {
|
| 41 |
// Hide the fallback payment method radio.
|
| 42 |
$("#payment-pane .form-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
|
| 43 |
|
| 44 |
// Show and select the gift card.
|
| 45 |
$("input:radio[@value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
|
| 46 |
|
| 47 |
// Refresh the payment details section.
|
| 48 |
get_payment_details('cart/checkout/payment_details/free_order');
|
| 49 |
|
| 50 |
using_free_order = 1;
|
| 51 |
}
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|