From 90c82daaeb46400cf08b63e18d36d208deb371e1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 20 Aug 2008 18:03:46 +0000 Subject: [PATCH] fix a bug where getOptions returns all shipping drivers, regardless of their enabled status --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/Ship.pm | 1 + t/Shop/Ship.t | 31 ++++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 81fab042c..0e236b486 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -27,6 +27,7 @@ - fixed: edit operation sql error, Thingy (Yung Han Khoe) - fixed: Thingy: default thing property hidden (Yung Han Khoe) - fixed: Ad Space Description Text Keeps Repopulating + - fixed: Disabled Shipping methods still available 7.5.20 - fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields diff --git a/lib/WebGUI/Shop/Ship.pm b/lib/WebGUI/Shop/Ship.pm index 1a04a3ac0..bc7e82fe9 100644 --- a/lib/WebGUI/Shop/Ship.pm +++ b/lib/WebGUI/Shop/Ship.pm @@ -98,6 +98,7 @@ sub getOptions { my $session = $cart->session; my %options = (); foreach my $shipper (@{$self->getShippers()}) { + next unless $shipper->get('enabled'); $options{$shipper->getId} = { label => $shipper->get("label"), price => $shipper->calculate($cart), diff --git a/t/Shop/Ship.t b/t/Shop/Ship.t index a869f7147..2784e4d89 100644 --- a/t/Shop/Ship.t +++ b/t/Shop/Ship.t @@ -23,6 +23,7 @@ use HTML::Form; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; +use WebGUI::Shop::Cart; #---------------------------------------------------------------------------- # Init @@ -31,7 +32,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 20; +my $tests = 22; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -155,10 +156,10 @@ isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate', 'added a new, configured F ####################################################################### my $shippers; -$driver2 = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>1, label=>q{Tommy's cut-rate shipping}}); +$driver2 = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>0, label=>q{Tommy's cut-rate shipping}}); $shippers = $ship->getShippers(); -is(scalar @{$shippers}, 3, 'getShippers: got both shippers'); +is(scalar @{$shippers}, 3, 'getShippers: got both shippers, even though one is not enabled'); my @shipperNames = map { $_->get("label") } @{ $shippers }; cmp_bag( @@ -173,6 +174,8 @@ cmp_bag( # ####################################################################### +my $defaultDriver = WebGUI::Shop::ShipDriver->new($session, 'defaultfreeshipping000'); + eval { $shippers = $ship->getOptions(); }; $e = Exception::Class->caught(); isa_ok($e, 'WebGUI::Error::InvalidParam', 'getOptions takes exception to not giving it a cart'); @@ -184,6 +187,28 @@ cmp_deeply( 'getOptions takes exception to not giving it a cart', ); +my $cart = WebGUI::Shop::Cart->create($session); +eval { $shippers = $ship->getOptions($cart) }; +$e = Exception::Class->caught(); +ok(!$e, 'No exception thrown for getOptions with a cart argument'); + +cmp_deeply( + $shippers, + { + $defaultDriver->getId => { + label => $defaultDriver->get('label'), + price => ignore(), + }, + $driver->getId => { + label => $driver->get('label'), + price => ignore(), + }, + }, + 'getOptions returns the two enabled shipping drivers' +); + +$cart->delete; + } #----------------------------------------------------------------------------