Add the tax table.

Add the getItems method, for accessing the entire tax table.
This commit is contained in:
Colin Kuskie 2008-02-15 22:15:58 +00:00
parent f08f3a0ffe
commit 70b8331794
3 changed files with 46 additions and 2 deletions

View file

@ -24,6 +24,8 @@ my $session = start(); # this line required
# upgrade functions go here
insertCommerceTaxTable($session);
finish($session); # this line required
@ -34,6 +36,25 @@ finish($session); # this line required
# # and here's our code
#}
#-------------------------------------------------
sub insertCommerceTaxTable {
my $session = shift;
print "\tInstall the Commerce Tax Table.\n" unless ($quiet);
# and here's our code
$session->db->write(<<EOSQL);
CREATE TABLE tax (
taxId VARCHAR(22) NOT NULL,
field VARCHAR(100) NOT NULL,
value VARCHAR(100) DEFAULT 0.0,
taxRate FLOAT NOT NULL,
PRIMARY KEY (taxId),
UNIQUE KEY (field, value)
)
EOSQL
}
# --------------- DO NOT EDIT BELOW THIS LINE --------------------------------

View file

@ -10,7 +10,9 @@ Package WebGUI::Shop::Tax
=head1 DESCRIPTION
This package manages tax information, and calculates taxes on a shopping cart.
This package manages tax information, and calculates taxes on a shopping cart. It isn't a classic object
in that the only data it contains is a WebGUI::Session object, but it does provide several methods for
handling the information in the tax tables.
=head1 SYNOPSIS
@ -28,6 +30,21 @@ readonly session => my %session;
#-------------------------------------------------------------------
=head2 getItems ( )
Returns a WebGUI::SQL::Result object for accessing all of the data in the tax table. This
is a convenience method for listing and/or exporting tax data.
=cut
sub getItems {
my $self = shift;
my $result = $self->session->db->read('select * from tax');
return $result;
}
#-------------------------------------------------------------------
=head2 new ( $session )
Constructor for the WebGUI::Shop::Tax. Returns a WebGUI::Shop::Tax object.

View file

@ -27,7 +27,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 3;
my $tests = 5;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -47,6 +47,12 @@ isa_ok($taxer->session, 'WebGUI::Session', 'session method returns a session obj
is($session->getId, $taxer->session->getId, 'session method returns OUR session object');
my $taxIterator = $taxer->getItems;
isa_ok($taxIterator, 'WebGUI::SQL::ResultSet');
is($taxIterator->rows, 0, 'WebGUI ships with no predefined tax data');
}