Remove billing field requirements if the order value if 0
budda - November 15, 2008 - 23:39
| Project: | UC Free Order Payment Method |
| Version: | 5.x-1.0 |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | rszrama |
| Status: | active |
Jump to:
Description
If the total cart value is 0 then the billing fields should be un-required.
Should the billing pane just be hidden or are there reasons it may be required by some users? Maybe the option to hide should be configurable?

#1
If the billing pane is hidden, I'm curious how the checkout is handled on this.... otherwise items would stay in the cart, no?
#2
I think it can be hidden as long as we make sure the module alters the #required field for the form elements. I've done this in a custom job for a site in the past, so I'm sure I can manage. Good feature request. I am going to move it to the current branch, though.
#3
can this be added to the drupal 5 branch also?
#4
The uc_free_order.js needs a function amending:
<?php
/**
* Checks the current total and updates the available/selected payment methods
* accordingly.
*/
function free_order_check_total(total) {
total = parseFloat(total);
if (total >= .01) {
// Disable the free order option and select the first available method.
if (using_free_order == 0) {
// Show the other payment method radios.
$("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
// Hide the free order radio.
$("input:radio[@value=free_order]").attr('disabled', 'disabled').parent().hide(0);
// Find first available payment option
var firstmethod = $(':radio[name="panes[payment][payment_method]"]:first');
uc_free_order_next_method = firstmethod.val();
// Select the first payment method.
$("input:radio[@value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
// Refresh the payment details section.
get_payment_details('cart/checkout/payment_details/' + uc_free_order_next_method);
} else {
using_free_order = 0;
}
}
else {
// Disable the CC option and select the gift card option.
if (using_free_order != 1) {
// Hide the fallback payment method radio.
$("#payment-pane .form-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
// Show and select the gift card.
$("input:radio[@value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
// Refresh the payment details section.
get_payment_details('cart/checkout/payment_details/free_order');
using_free_order = 1;
}
}
}
?>
Then in the module, replace the hook_form_alter() function with:
<?php
/**
* Implementation of hook_form_alter().
*/
function uc_free_order_ixis_form_alter($form_id, &$form) {
global $user;
// Alter the checkout form to prepare it for our special JS.
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_ixis_next_method = '". $key ."';", 'inline');
$set = TRUE;
}
}
$cart_value = uc_free_order_calc_cart_total();
if ($cart_value == 0) {
unset($form['panes']['billing']);
}
}
elseif ($form_id == 'uc_cart_checkout_review_form') {
$order = uc_order_load($_SESSION['cart_order']);
if ($order->payment_method == 'free_order') {
if ($cart_value >= .01) {
drupal_set_message(t('We cannot process your order without payment.'), 'error');
drupal_goto('cart/checkout');
}
}
}
}
?>
I've only tested this against 5.x UC 1.x
#5
subscribing.