Force the user to pick a shipping method before checking out. Implements RFE #10940
If there is only 1 shipping method, automatically choose it. Displays an message to the user if they have an address, but no shipping method.
This commit is contained in:
parent
cad1d99844
commit
e5ead13da3
4 changed files with 48 additions and 16 deletions
|
|
@ -14,6 +14,7 @@ use WebGUI::Shop::Credit;
|
|||
use WebGUI::Shop::Ship;
|
||||
use WebGUI::Shop::Tax;
|
||||
use WebGUI::User;
|
||||
use Tie::IxHash;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -520,6 +521,9 @@ sub readyForCheckout {
|
|||
return 0 if $total < $requiredAmount;
|
||||
}
|
||||
|
||||
##Must have a configured shipping id.
|
||||
return 0 if ! $self->get('shipperId');
|
||||
|
||||
##Check for any other logged errors
|
||||
return 0 if $error{ id $self };
|
||||
|
||||
|
|
@ -843,22 +847,35 @@ sub www_view {
|
|||
$var{shippingAddress} = $address->getHtmlFormatted;
|
||||
my $ship = WebGUI::Shop::Ship->new($self->session);
|
||||
my $options = $ship->getOptions($self);
|
||||
my %formOptions = ();
|
||||
my $defaultOption = "";
|
||||
foreach my $option (keys %{$options}) {
|
||||
$defaultOption = $option;
|
||||
$formOptions{$option} = $options->{$option}{label}." (".$self->formatCurrency($options->{$option}{price}).")";
|
||||
}
|
||||
if ($defaultOption) {
|
||||
$var{shippingOptions} = WebGUI::Form::selectBox($session, {name=>"shipperId", options=>\%formOptions, defaultValue=>$defaultOption, value=>$self->get("shipperId")});
|
||||
$var{shippingPrice} = ($self->get("shipperId") ne "") ? $options->{$self->get("shipperId")}{price} : $options->{$defaultOption}{price};
|
||||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||
}
|
||||
else {
|
||||
my $numberOfOptions = scalar keys %{ $options };
|
||||
if ($numberOfOptions < 1) {
|
||||
$var{shippingOptions} = '';
|
||||
$var{shippingPrice} = 0;
|
||||
$error{id $self} = $i18n->get("No shipping plugins configured");
|
||||
}
|
||||
elsif ($numberOfOptions == 1) {
|
||||
my ($option) = keys %{ $options };
|
||||
$self->update({ shipperId => $option });
|
||||
$var{shippingPrice} = $options->{$self->get("shipperId")}->{price};
|
||||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||
}
|
||||
else {
|
||||
tie my %formOptions, 'Tie::IxHash';
|
||||
$formOptions{''} = $i18n->get('Choose a shipping method');
|
||||
foreach my $option (keys %{$options}) {
|
||||
$formOptions{$option} = $options->{$option}{label}." (".$self->formatCurrency($options->{$option}{price}).")";
|
||||
}
|
||||
my $defaultOption = $self->get('shipperId') ? $self->get('shipperId') : '';
|
||||
$var{shippingOptions} = WebGUI::Form::selectBox($session, {name=>"shipperId", options=>\%formOptions, value=>$self->get("shipperId")});
|
||||
if (my $shipperId = $self->get('shipperId')) {
|
||||
$var{shippingPrice} = $options->{$shipperId}->{price};
|
||||
}
|
||||
else {
|
||||
$var{shippingPrice} = 0;
|
||||
$error{id $self} = ($i18n->get('Choose a shipping method and update the cart to checkout'));
|
||||
}
|
||||
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||
}
|
||||
}
|
||||
|
||||
# Tax variables
|
||||
|
|
|
|||
|
|
@ -1659,6 +1659,18 @@ our $I18N = {
|
|||
context => q|Error message in the manage ship driver screen.|,
|
||||
},
|
||||
|
||||
'Choose a shipping method' => {
|
||||
message => q|Choose a shipping method|,
|
||||
lastUpdated => 0,
|
||||
context => q|Label to make the user choose a shipping method|,
|
||||
},
|
||||
|
||||
'Choose a shipping method and update the cart to checkout' => {
|
||||
message => q|Choose a shipping method and update the cart to checkout|,
|
||||
lastUpdated => 0,
|
||||
context => q|Label to make the user choose a shipping method|,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue