From 82ed3f03b847fd66ed3e68df10d49dcf703732ea Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 4 Oct 2010 14:20:45 -0700 Subject: [PATCH] Fix shop credit display and calculations in the PayDriver. Fixes bug #11891 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/PayDriver.pm | 2 +- t/Shop/PayDriver.t | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index abf82fbee..003616c23 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -6,6 +6,7 @@ - fixed #11789: Date form reports 1 day earlier on Edit for the time zone corresponding to Europe/Berlin. - fixed #11894: Europe London timezone decrements birth date - fixed #11857: make page printable? + - fixed #11891: Shop credit not displayed in payment method screen 7.10.1 - fixed #11851: Story Topic: top story variables should be available all the time diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index 77b54ba99..15764b72d 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -101,7 +101,7 @@ sub appendCartVariables { my $session = $self->session; my $credit = WebGUI::Shop::Credit->new($session, $cart->getPosUser->userId); $var->{inShopCreditAvailable} = $credit->getSum; - $var->{inShopCreditDeduction} = $credit->calculateDeduction($var->{totalPrice}); + $var->{inShopCreditDeduction} = $credit->calculateDeduction($totalPrice); $var->{totalPrice } = $cart->formatCurrency($totalPrice + $var->{inShopCreditDeduction}); return $self; } diff --git a/t/Shop/PayDriver.t b/t/Shop/PayDriver.t index a40b6aef5..f4557954c 100644 --- a/t/Shop/PayDriver.t +++ b/t/Shop/PayDriver.t @@ -24,7 +24,10 @@ use HTML::Form; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; +use WebGUI::Shop::Cart; +use WebGUI::Shop::Credit; use WebGUI::Shop::PayDriver; +use WebGUI::User; #---------------------------------------------------------------------------- # Init @@ -33,7 +36,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 55; +plan tests => 56; #---------------------------------------------------------------------------- # figure out if the test can actually run @@ -475,8 +478,10 @@ my $blue_widget = $widget->setCollateral('variantsJSON', 'variantId', 'new', ); $versionTag->commit; +my $credited_user = WebGUI::User->create($session); +$session->user({user => $credited_user}); my $cart = WebGUI::Shop::Cart->newBySession($session); -WebGUI::Test->addToCleanup($versionTag, $cart); +WebGUI::Test->addToCleanup($versionTag, $cart, $credited_user); my $addressBook = $cart->getAddressBook; my $workAddress = $addressBook->addAddress({ label => 'work', @@ -493,7 +498,6 @@ $widget->addToCart($widget->getCollateral('variantsJSON', 'variantId', $blue_wid my $cart_variables = {}; $driver->appendCartVariables($cart_variables); -diag Dumper($cart_variables); cmp_deeply( $cart_variables, @@ -510,6 +514,26 @@ cmp_deeply( 'appendCartVariables: checking shippableItemsInCart and totalPrice & subtotal formatting' ); +my $credit = WebGUI::Shop::Credit->new($session, $credited_user->userId); +$credit->adjust('1', 'credit for testing'); +$cart_variables = {}; +$driver->appendCartVariables($cart_variables); +cmp_deeply( + $cart_variables, + { + taxes => ignore(), + shippableItemsInCart => 1, + subtotal => '5.00', + inShopCreditDeduction => '-1.00', + inShopCreditAvailable => '1.00', + totalPrice => '4.00', + shipping => ignore(), + + }, + '... checking credit display' +); + + ####################################################################### # # delete