Don't let the cart crash on invalid addressIds

This commit is contained in:
Martin Kamerbeek 2010-12-22 13:31:16 +00:00
parent f748aa1b83
commit 10ea82d6ec
3 changed files with 27 additions and 3 deletions

View file

@ -4,6 +4,8 @@
- fixed #11984: No JS allows invalid dates in Event asset
- fixed bug in shopping cart where in some cases the shipper selectbox would
be empty ( Martin Kamerbeek / Oqapi )
- fixed bug where an invalid address ids would prevent a customer from ever
checking out again ( Martin Kamerbeek / Oqapi )
7.10.6
- fixed #11974: Toolbar icons unclickable in Webkit using HTML5

View file

@ -1174,7 +1174,10 @@ sub www_view {
my $billingAddressId = $self->get('billingAddressId');
if ($billingAddressId) {
$billingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getBillingAddress->get('label');
my $billingAddress = eval { $self->getBillingAddress };
if ( defined $billingAddress ) {
$billingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $billingAddress->get('label');
}
}
%billingAddressOptions = (%billingAddressOptions, %addressOptions);
@ -1190,7 +1193,10 @@ sub www_view {
my $shippingAddressId = $self->get('shippingAddressId');
if ($shippingAddressId) {
$shippingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $self->getShippingAddress->get('label');
my $shippingAddress = eval { $self->getShippingAddress };
if ( defined $shippingAddress ) {
$shippingAddressOptions{'update_address'} = sprintf $i18n->get('Update %s'), $shippingAddress->get('label');
}
}
%shippingAddressOptions = (%shippingAddressOptions, %addressOptions);

View file

@ -35,7 +35,7 @@ my $i18n = WebGUI::International->new($session, "Shop");
#----------------------------------------------------------------------------
# Tests
plan tests => 34; # Increment this number for each test you create
plan tests => 36; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -207,5 +207,21 @@ is($cart->delete, undef, "Can destroy cart.");
$cart->update( { shippingAddressId => $shipper->getId } );
}
# Test (part of) www_view
{
my $shippingAddressId = $cart->get( 'shippingAddressId' );
my $billingAddressId = $cart->get( 'billingAddressId' );
$cart->update( { shippingAddressId => 'NoWayDude' } );
eval { $cart->www_view };
is( $@, '', 'Invalid shippingAddressId doesn\'t make www_view crash' );
$cart->update( { billingAddressId => 'WRONG!!!!', shippingAddressId => $shippingAddressId } );
eval { $cart->www_view };
is( $@, '', 'Invalid billingAddressId doesn\'t make www_view crash' );
$cart->update( { billingAddressId => $billingAddressId } );
}
$product->purge;