diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c056ae177..cc7b6dec2 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,8 @@ - added #11968: use the language override in the registration form (Jukka Raimovaara / Mentalhouse Oy) - Changed Carousel to use TinyMCE with WebGUI plugins - 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 ) 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 b32207f8f..3d963771a 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -875,8 +875,10 @@ sub www_ajaxPrices { } || 0, shipping => eval { - die unless $shipping; - $self->update({ shippingAddressId => $shipping }); + #die unless $shipping; + if ( $shipping ) { + $self->update({ shippingAddressId => $shipping }); + } my $ship = WebGUI::Shop::Ship->new($self->session); $ship->getOptions($self); } || [], diff --git a/t/Shop/Cart.t b/t/Shop/Cart.t index afaed76a5..9cfd466d6 100644 --- a/t/Shop/Cart.t +++ b/t/Shop/Cart.t @@ -17,12 +17,14 @@ use FindBin; use strict; use lib "$FindBin::Bin/../lib"; use Test::More; +use Test::Deep; use Scalar::Util qw/refaddr/; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; use WebGUI::Asset; use WebGUI::Shop::Cart; use WebGUI::TestException; +use JSON 'from_json'; #---------------------------------------------------------------------------- @@ -33,7 +35,7 @@ my $i18n = WebGUI::International->new($session, "Shop"); #---------------------------------------------------------------------------- # Tests -plan tests => 30; # Increment this number for each test you create +plan tests => 34; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -179,5 +181,31 @@ $cart->delete; is($cart->delete, undef, "Can destroy cart."); +# Test (shipping part of) www_ajaxPrices +{ + local *WebGUI::Shop::Ship::getOptions = sub { [ qw{ a b c } ] }; + + $cart->update( { shippingAddressId => $address->getId } ); + + my $response = from_json $cart->www_ajaxPrices; + cmp_deeply( + $response->{ shipping }, + [ qw{ a b c } ], + 'shipping contains available shipping option when no shipper is passed', + ); + is( $cart->get('shippingAddressId'), $address->getId, 'calling www_ajaxPrices w/o shipperId doesn\'t change the cart shipperId' ); + + local *WebGUI::Session::Form::get = sub { return 'OtherShippert' }; + $response = from_json $cart->www_ajaxPrices; + cmp_deeply( + $response->{ shipping }, + [ qw{ a b c } ], + 'shipping contains available shipping option when a shipper is passed', + ); + is( $cart->get('shippingAddressId'), 'OtherShippert', 'calling www_ajaxPrices w/ shipperId updates the cart shipperId' ); + + $cart->update( { shippingAddressId => $shipper->getId } ); +} + $product->purge;