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 @@
|
||||||
- fixed #11032: The Thingy form field "otherThingy" not checking for privilege
|
- fixed #11032: The Thingy form field "otherThingy" not checking for privilege
|
||||||
- fixed #11037: Maintenance page is being cached
|
- fixed #11037: Maintenance page is being cached
|
||||||
- fixed #11056: No history in wiki
|
- fixed #11056: No history in wiki
|
||||||
|
- added RFE #10940: Force the user to pick a shipping method before checking out.
|
||||||
|
|
||||||
7.8.0
|
7.8.0
|
||||||
- upgraded YUI to 2.8.0r4
|
- upgraded YUI to 2.8.0r4
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use WebGUI::Shop::Credit;
|
||||||
use WebGUI::Shop::Ship;
|
use WebGUI::Shop::Ship;
|
||||||
use WebGUI::Shop::Tax;
|
use WebGUI::Shop::Tax;
|
||||||
use WebGUI::User;
|
use WebGUI::User;
|
||||||
|
use Tie::IxHash;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -520,6 +521,9 @@ sub readyForCheckout {
|
||||||
return 0 if $total < $requiredAmount;
|
return 0 if $total < $requiredAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##Must have a configured shipping id.
|
||||||
|
return 0 if ! $self->get('shipperId');
|
||||||
|
|
||||||
##Check for any other logged errors
|
##Check for any other logged errors
|
||||||
return 0 if $error{ id $self };
|
return 0 if $error{ id $self };
|
||||||
|
|
||||||
|
|
@ -843,22 +847,35 @@ sub www_view {
|
||||||
$var{shippingAddress} = $address->getHtmlFormatted;
|
$var{shippingAddress} = $address->getHtmlFormatted;
|
||||||
my $ship = WebGUI::Shop::Ship->new($self->session);
|
my $ship = WebGUI::Shop::Ship->new($self->session);
|
||||||
my $options = $ship->getOptions($self);
|
my $options = $ship->getOptions($self);
|
||||||
my %formOptions = ();
|
my $numberOfOptions = scalar keys %{ $options };
|
||||||
my $defaultOption = "";
|
if ($numberOfOptions < 1) {
|
||||||
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 {
|
|
||||||
$var{shippingOptions} = '';
|
$var{shippingOptions} = '';
|
||||||
$var{shippingPrice} = 0;
|
$var{shippingPrice} = 0;
|
||||||
$error{id $self} = $i18n->get("No shipping plugins configured");
|
$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
|
# Tax variables
|
||||||
|
|
|
||||||
|
|
@ -1659,6 +1659,18 @@ our $I18N = {
|
||||||
context => q|Error message in the manage ship driver screen.|,
|
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;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ my $i18n = WebGUI::International->new($session, "Shop");
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 29; # Increment this number for each test you create
|
plan tests => 30; # Increment this number for each test you create
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
@ -105,13 +105,15 @@ my $ship = WebGUI::Shop::Ship->new( $session );
|
||||||
my $shipper = $ship->addShipper( 'WebGUI::Shop::ShipDriver::FlatRate', {flatFee => 1 } );
|
my $shipper = $ship->addShipper( 'WebGUI::Shop::ShipDriver::FlatRate', {flatFee => 1 } );
|
||||||
$cart->update( {
|
$cart->update( {
|
||||||
shippingAddressId => $address->getId,
|
shippingAddressId => $address->getId,
|
||||||
shipperId => $shipper->getId,
|
|
||||||
} );
|
} );
|
||||||
is($cart->readyForCheckout, 1, 'Cart is ready for checkout');
|
ok(! $cart->readyForCheckout, 'readyForCheckout: returns false due to no shipperId');
|
||||||
|
|
||||||
|
$cart->update( { shipperId => $shipper->getId, } );
|
||||||
|
ok($cart->readyForCheckout, '... returns true when it has shipperId, and shipping address');
|
||||||
|
|
||||||
# Check shipping address constraint
|
# Check shipping address constraint
|
||||||
$cart->update( {shippingAddressId => 'Does Not Exist'} );
|
$cart->update( {shippingAddressId => 'Does Not Exist'} );
|
||||||
is( $cart->readyForCheckout, 0, 'Cannot checkout cart without shipping address' );
|
ok( ! $cart->readyForCheckout, '... Cannot checkout cart without shipping address' );
|
||||||
|
|
||||||
# Check minimum transaction amount
|
# Check minimum transaction amount
|
||||||
$session->setting->set( 'shopCartCheckoutMinimum', 1000 );
|
$session->setting->set( 'shopCartCheckoutMinimum', 1000 );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue