From f65ae74e5479f643f644f479882001f6fdc3f9b1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 2 Sep 2010 12:51:54 -0700 Subject: [PATCH] Format the subtotal variable in the Payment driver to 2 decimal places. Fixes bug #11813 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Shop/PayDriver.pm | 2 +- t/Shop/PayDriver.t | 60 +++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 13bceee72..51bd01f0f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -5,6 +5,7 @@ - added: template variable downgrading so that using we can safely pass template variables TT would understand to HTML::Template templates -- see WebGUI::Asset::Template::Parser->downgrade for details. + - fixed #11813: Payment confirmation screen dollar amount 7.9.13 - fixed #11783: Instances deleted during realtime run diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index 3575eba7a..77b54ba99 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -94,7 +94,7 @@ sub appendCartVariables { $var ||= {}; my $cart = $self->getCart; $var->{shippableItemsInCart} = $cart->requiresShipping; - $var->{subtotal} = $cart->calculateSubtotal; + $var->{subtotal} = $cart->formatCurrency($cart->calculateSubtotal); $var->{shipping} = $cart->calculateShipping; $var->{taxes} = $cart->calculateTaxes; my $totalPrice = $var->{subtotal} + $var->{shipping} + $var->{taxes}; diff --git a/t/Shop/PayDriver.t b/t/Shop/PayDriver.t index 5d765af3c..a40b6aef5 100644 --- a/t/Shop/PayDriver.t +++ b/t/Shop/PayDriver.t @@ -18,6 +18,7 @@ use strict; use lib "$FindBin::Bin/../lib"; use Test::More; use Test::Deep; +use Data::Dumper; use JSON; use HTML::Form; @@ -32,7 +33,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 54; +plan tests => 55; #---------------------------------------------------------------------------- # figure out if the test can actually run @@ -452,6 +453,63 @@ TODO: { ok(0, 'Test other users and groups'); } +####################################################################### +# +# appendCartVariables +# +####################################################################### + +my $versionTag = WebGUI::VersionTag->getWorking($session); +my $node = WebGUI::Asset->getImportNode($session); +my $widget = $node->addChild({ + className => 'WebGUI::Asset::Sku::Product', + title => 'Test product for cart template variables in the Product', + isShippingRequired => 1, +}); +my $blue_widget = $widget->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => 'Blue widget', price => 5.00, + varSku => 'blue-widget', weight => 1.0, + quantity => 9999, + } +); + +$versionTag->commit; +my $cart = WebGUI::Shop::Cart->newBySession($session); +WebGUI::Test->addToCleanup($versionTag, $cart); +my $addressBook = $cart->getAddressBook; +my $workAddress = $addressBook->addAddress({ + label => 'work', + organization => 'Plain Black Corporation', + address1 => '1360 Regent St. #145', + city => 'Madison', state => 'WI', code => '53715', + country => 'United States', +}); +$cart->update({ + billingAddressId => $workAddress->getId, + shippingAddressId => $workAddress->getId, +}); +$widget->addToCart($widget->getCollateral('variantsJSON', 'variantId', $blue_widget)); + +my $cart_variables = {}; +$driver->appendCartVariables($cart_variables); +diag Dumper($cart_variables); + +cmp_deeply( + $cart_variables, + { + taxes => ignore(), + shippableItemsInCart => 1, + totalPrice => '5.00', + inShopCreditDeduction => ignore(), + inShopCreditAvailable => ignore(), + subtotal => '5.00', + shipping => ignore(), + + }, + 'appendCartVariables: checking shippableItemsInCart and totalPrice & subtotal formatting' +); + ####################################################################### # # delete