From 10ea82d6ece300dd0a2c971ca073bdfeb7e0824f Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Wed, 22 Dec 2010 13:31:16 +0000 Subject: [PATCH] Don't let the cart crash on invalid addressIds --- docs/changelog/7.x.x.txt | 2 ++ lib/WebGUI/Shop/Cart.pm | 10 ++++++++-- t/Shop/Cart.t | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index cc7b6dec2..d42c5e4d5 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 3d963771a..99d7e35fd 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -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); diff --git a/t/Shop/Cart.t b/t/Shop/Cart.t index 9cfd466d6..32bfaef29 100644 --- a/t/Shop/Cart.t +++ b/t/Shop/Cart.t @@ -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;