Project:
UbercartCategory:
taskVersion:
Ubercart 1.0Priority:
normalAssigned:
UnassignedStatus:
activeHi
I've found a tricky validation issue on uc_cart, when you select "My billing information is the same as my delivery information" and there is a required field missing, an error is issued for both the field of shipping information and billing information.
I think that this error should not be issued for billing info if the "My billing information is the same as my delivery information" is checked because it forces the user to uncheck and recheck for refreshing the info.
I suggest to modify the uc_checkout_pane_billing function of uc_cart_checkout_pane with these changes:
/**
* Get the billing information.
*/
function uc_checkout_pane_billing($op, &$arg1, $arg2) {
global $user;
switch ($op) {
case 'view':
$copy_address = (boolean)$_POST['panes']['billing']['copy_address'];
$description = t('Enter your billing address and information here.');
if ((uc_cart_is_shippable() || !variable_get('uc_cart_delivery_not_shippable', TRUE)) &&
_checkout_pane_data('delivery', 'weight') < _checkout_pane_data('billing', 'weight') &&
_checkout_pane_data('delivery', 'enabled')) {
$contents['copy_address'] = array(
'#type' => 'checkbox',
'#title' => t('My billing information is the same as my delivery information.'),
'#attributes' => array('onclick' => "uc_cart_copy_address(this.checked, 'delivery', 'billing');"),
);
}
if ($user->uid) {
$addresses = uc_select_address($user->uid, 'billing', 'apply_address(\'billing\', this.value);', t('Saved addresses'), TRUE);
if (!empty($addresses)) {
$contents['billing_address_select'] = $addresses;
}
}
if (uc_address_field_enabled('first_name')) {
$contents['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->billing_first_name, (!$copy_address AND uc_address_field_required('first_name')));
}
if (uc_address_field_enabled('last_name')) {
$contents['billing_last_name'] = uc_textfield(uc_get_field_name('last_name'), $arg1->billing_last_name, (!$copy_address AND uc_address_field_required('last_name')));
}
if (uc_address_field_enabled('company')) {
$contents['billing_company'] = uc_textfield(uc_get_field_name('company'), $arg1->billing_company, (!$copy_address AND uc_address_field_required('company')), NULL, 64);
}
if (uc_address_field_enabled('street1')) {
$contents['billing_street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->billing_street1, (!$copy_address AND uc_address_field_required('street1')), NULL, 64);
}
if (uc_address_field_enabled('street2')) {
$contents['billing_street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->billing_street2, (!$copy_address AND uc_address_field_required('street2')), NULL, 64);
}
if (uc_address_field_enabled('city')) {
$contents['billing_city'] = uc_textfield(uc_get_field_name('city'), $arg1->billing_city, (!$copy_address AND uc_address_field_required('city')));
}
if (uc_address_field_enabled('country')) {
$contents['billing_country'] = uc_country_select(uc_get_field_name('country'), $arg1->billing_country, NULL, 'name', (!$copy_address AND uc_address_field_required('country')));
}
if (uc_address_field_enabled('zone')) {
if (isset($_POST['panes']['billing']['billing_country'])) {
$country_id = intval($_POST['panes']['billing']['billing_country']);
}
else {
$country_id = $arg1->billing_country;
}
$contents['billing_zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->billing_zone, NULL, $country_id, 'name', (!$copy_address AND uc_address_field_required('zone')));
if (isset($_POST['panes']) && count($contents['billing_zone']['#options']) == 1) {
$contents['billing_zone']['#required'] = FALSE;
}
}
if (uc_address_field_enabled('postal_code')) {
$contents['billing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $arg1->billing_postal_code, (!$copy_address AND uc_address_field_required('postal_code')), NULL, 10, 10);
}
if (uc_address_field_enabled('phone')) {
$contents['billing_phone'] = uc_textfield(uc_get_field_name('phone'), $arg1->billing_phone, (!$copy_address AND uc_address_field_required('phone')), NULL, 32, 16);
}
return array('description' => $description, 'contents' => $contents, 'theme' => 'address_pane');
case 'process':
$copy_address = $arg2['copy_address'];
if ($copy_address) {
$arg1->billing_first_name = $arg1->delivery_first_name;
$arg1->billing_last_name = $arg1->delivery_last_name;
$arg1->billing_company = $arg1->delivery_company;
$arg1->billing_street1 = $arg1->delivery_street1;
$arg1->billing_street2 = $arg1->delivery_street2;
$arg1->billing_city = $arg1->delivery_city;
$arg1->billing_zone = $arg1->delivery_zone;
$arg1->billing_postal_code = $arg1->delivery_postal_code;
$arg1->billing_country = $arg1->delivery_country;
$arg1->billing_phone = $arg1->delivery_phone;
}
else {
$arg1->billing_first_name = $arg2['billing_first_name'];
$arg1->billing_last_name = $arg2['billing_last_name'];
$arg1->billing_company = $arg2['billing_company'];
$arg1->billing_street1 = $arg2['billing_street1'];
$arg1->billing_street2 = $arg2['billing_street2'];
$arg1->billing_city = $arg2['billing_city'];
$arg1->billing_zone = $arg2['billing_zone'];
$arg1->billing_postal_code = $arg2['billing_postal_code'];
$arg1->billing_country = $arg2['billing_country'];
$arg1->billing_phone = $arg2['billing_phone'];
}
return TRUE;
case 'review':
$review[] = array('title' => t('Address'), 'data' => uc_order_address($arg1, 'billing', FALSE));
if (uc_address_field_enabled('phone') && !empty($arg1->billing_phone)) {
$review[] = array('title' => t('Phone'), 'data' => check_plain($arg1->billing_phone));
}
return $review;
}
}
Re: Issue on required billing information on uc_cart
I'll check into this, but the JS should work so that if you check that box, any changes you make to the delivery address should be duplicated on the billing address.
Re: Re: Issue on required billing information on uc_cart
yes, the js does his job, but when you don't fill a required delivery field, a double error issues, one for the delivery field and one for the billing field, even the check is enabled. It is confussing i think, when the check is enabled it should not validate the billing info, only delivery, and copy one into another.
Re: Re: Re: Issue on required billing information on uc_cart
I see what you mean. I'll log this as a feature request against a future version... for 5.x that checkbox has no way of differentiating in the form submit function whether it was for the billing or delivery address. It will let you copy whichever one is second. This means I have no way of telling in validation which address to bypass. That can certainly be cleaned up in the future.
Re: Re: Re: Re: Issue on required billing information on uc_cart
The code I've posted is working quite well for me, when the check is marked, it assumes that the billing & delivery information are the same, it does not validate the billing info and overwrites whatever the billing info contains with the delivery info.
Hope this helps
Thanks Ryan
Re: Re: Re: Re: Re: Issue on required billing information on uc_
I like the basic thought behind your code. What I was referring to, though, is when the order of the checkout panes is switched. You can test by moving your billing pane to be higher than your delivery pane.