Finish out the FlatRate driver, with tests and i18n.
Fix bugs found in ShipDriver by building a driver.
This commit is contained in:
parent
6d856d1b58
commit
640554ea14
4 changed files with 160 additions and 54 deletions
|
|
@ -131,23 +131,24 @@ sub definition {
|
||||||
unless ref $session eq 'WebGUI::Session';
|
unless ref $session eq 'WebGUI::Session';
|
||||||
my $definition = shift || [];
|
my $definition = shift || [];
|
||||||
my $i18n = WebGUI::International->new($session, 'ShipDriver');
|
my $i18n = WebGUI::International->new($session, 'ShipDriver');
|
||||||
tie my %properties, 'Tie::IxHash';
|
tie my %fields, 'Tie::IxHash';
|
||||||
%properties = (
|
%fields = (
|
||||||
name => 'Shipper Driver',
|
label => {
|
||||||
fields => {
|
fieldType => 'text',
|
||||||
label => {
|
label => $i18n->get('label'),
|
||||||
fieldType => 'text',
|
hoverHelp => $i18n->get('label help'),
|
||||||
label => $i18n->get('label'),
|
defaultValue => undef,
|
||||||
hoverHelp => $i18n->get('label help'),
|
|
||||||
defaultValue => undef,
|
|
||||||
},
|
|
||||||
enabled => {
|
|
||||||
fieldType => 'yesNo',
|
|
||||||
label => $i18n->get('enabled'),
|
|
||||||
hoverHelp => $i18n->get('enabled help'),
|
|
||||||
defaultValue => 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
enabled => {
|
||||||
|
fieldType => 'yesNo',
|
||||||
|
label => $i18n->get('enabled'),
|
||||||
|
hoverHelp => $i18n->get('enabled help'),
|
||||||
|
defaultValue => 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
my %properties = (
|
||||||
|
name => 'Shipper Driver',
|
||||||
|
fields => \%fields,
|
||||||
);
|
);
|
||||||
push @{ $definition }, \%properties;
|
push @{ $definition }, \%properties;
|
||||||
return $definition;
|
return $definition;
|
||||||
|
|
@ -245,7 +246,7 @@ subclass, instead specified in definition with the name "name".
|
||||||
|
|
||||||
sub getName {
|
sub getName {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $definition = WebGUI::Shop::ShipDriver->definition($self->session);
|
my $definition = $self->definition($self->session);
|
||||||
return $definition->[0]->{name};
|
return $definition->[0]->{name};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,7 +303,8 @@ Setter for user configurable options in the ship objects.
|
||||||
|
|
||||||
=head4 $options
|
=head4 $options
|
||||||
|
|
||||||
A list of properties to assign to this ShipperDriver. See C<definition> for details.
|
A list of properties to assign to this ShipperDriver. See C<definition> for details. The options are
|
||||||
|
flattened into JSON and stored in the database as text. There is no content checking performed.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package WebGUI::Shop::ShipDriver::FlatRate;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use base qw/WebGUI::Shop::ShipDriver/;
|
use base qw/WebGUI::Shop::ShipDriver/;
|
||||||
|
use Carp qw/croak/;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -60,36 +61,37 @@ sub definition {
|
||||||
croak "Definition requires a session object"
|
croak "Definition requires a session object"
|
||||||
unless ref $session eq 'WebGUI::Session';
|
unless ref $session eq 'WebGUI::Session';
|
||||||
my $definition = shift || [];
|
my $definition = shift || [];
|
||||||
my $i18n = WebGUI::International->new($session, 'ShipDriver');
|
my $i18n = WebGUI::International->new($session, 'ShipDriver_FlatRate');
|
||||||
tie my %properties, 'Tie::IxHash';
|
tie my %fields, 'Tie::IxHash';
|
||||||
%properties = (
|
%fields = (
|
||||||
name => 'Flat Rate',
|
flatFee => {
|
||||||
fields => {
|
fieldType => 'float',
|
||||||
flatFee => {
|
label => $i18n->get('flatFee'),
|
||||||
fieldType => 'float',
|
hoverHelp => $i18n->get('flatFee help'),
|
||||||
label => $i18n->get('flatFee'),
|
defaultValue => 0,
|
||||||
hoverHelp => $i18n->get('flatFee help'),
|
|
||||||
defaultValue => 0,
|
|
||||||
},
|
|
||||||
percentageOfPrice => {
|
|
||||||
fieldType => 'float',
|
|
||||||
label => $i18n->get('percentageOfPrice'),
|
|
||||||
hoverHelp => $i18n->get('percentageOfPrice help'),
|
|
||||||
defaultValue => 0,
|
|
||||||
},
|
|
||||||
pricePerWeight => {
|
|
||||||
fieldType => 'float',
|
|
||||||
label => $i18n->get('pricePerWeight'),
|
|
||||||
hoverHelp => $i18n->get('pricePerWeight help'),
|
|
||||||
defaultValue => 0,
|
|
||||||
},
|
|
||||||
pricePerItem => {
|
|
||||||
fieldType => 'float',
|
|
||||||
label => $i18n->get('pricePerItem'),
|
|
||||||
hoverHelp => $i18n->get('pricePerItem help'),
|
|
||||||
defaultValue => 0,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
percentageOfPrice => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => $i18n->get('percentageOfPrice'),
|
||||||
|
hoverHelp => $i18n->get('percentageOfPrice help'),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
pricePerWeight => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => $i18n->get('pricePerWeight'),
|
||||||
|
hoverHelp => $i18n->get('pricePerWeight help'),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
pricePerItem => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => $i18n->get('pricePerItem'),
|
||||||
|
hoverHelp => $i18n->get('pricePerItem help'),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
my %properties = (
|
||||||
|
name => 'Flat Rate',
|
||||||
|
fields => \%fields,
|
||||||
);
|
);
|
||||||
push @{ $definition }, \%properties;
|
push @{ $definition }, \%properties;
|
||||||
return $class->SUPER::definition($session, $definition);
|
return $class->SUPER::definition($session, $definition);
|
||||||
|
|
|
||||||
53
lib/WebGUI/i18n/English/ShipDriver_FlatRate.pm
Normal file
53
lib/WebGUI/i18n/English/ShipDriver_FlatRate.pm
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package WebGUI::i18n::English::ShipDriver_FlatRate;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
our $I18N = {
|
||||||
|
|
||||||
|
'flatFee' => {
|
||||||
|
message => q|Flat Fee|,
|
||||||
|
lastUpdated => 1203569535,
|
||||||
|
context => q|A fixed amount of money added to a purchase for shipping.|,
|
||||||
|
},
|
||||||
|
|
||||||
|
'flatFee help' => {
|
||||||
|
message => q|A fixed amount of money added to a purchase for shipping.|,
|
||||||
|
lastUpdated => 1203569511,
|
||||||
|
},
|
||||||
|
|
||||||
|
'percentageOfPrice' => {
|
||||||
|
message => q|Percentage of Price|,
|
||||||
|
lastUpdated => 1203569584,
|
||||||
|
context => q|A shipping cost added to a cart as a percentage of the total.|,
|
||||||
|
},
|
||||||
|
|
||||||
|
'percenageOfPrice help' => {
|
||||||
|
message => q|A shipping cost added to a cart as a percentage of the total cost of the cart.|,
|
||||||
|
lastUpdated => 1203569582,
|
||||||
|
},
|
||||||
|
|
||||||
|
'percentageOfWeight' => {
|
||||||
|
message => q|Percentage of Weight|,
|
||||||
|
lastUpdated => 1203569584,
|
||||||
|
context => q|A shipping cost added to a cart as a percentage of the weight.|,
|
||||||
|
},
|
||||||
|
|
||||||
|
'percentageOfWeight help' => {
|
||||||
|
message => q|A shipping cost added to a cart as a percentage of the total weight of all items in the cart.|,
|
||||||
|
lastUpdated => 1203569582,
|
||||||
|
},
|
||||||
|
|
||||||
|
'pricePerItem' => {
|
||||||
|
message => q|Price Per Item|,
|
||||||
|
lastUpdated => 1203569584,
|
||||||
|
context => q|A shipping cost added to a cart based on the number of items in the cart.|,
|
||||||
|
},
|
||||||
|
|
||||||
|
'pricePerItem help' => {
|
||||||
|
message => q|A shipping cost added to a cart based on the number of items in the cart.|,
|
||||||
|
lastUpdated => 1203569582,
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 28;
|
my $tests = 11;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -56,11 +56,40 @@ my $definition;
|
||||||
eval { $definition = WebGUI::Shop::ShipDriver::FlatRate->definition(); };
|
eval { $definition = WebGUI::Shop::ShipDriver::FlatRate->definition(); };
|
||||||
like ($@, qr/^Definition requires a session object/, 'definition croaks without a session object');
|
like ($@, qr/^Definition requires a session object/, 'definition croaks without a session object');
|
||||||
|
|
||||||
$definition = WebGUI::Shop::ShipDriver->definition($session);
|
$definition = WebGUI::Shop::ShipDriver::FlatRate->definition($session);
|
||||||
|
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$definition,
|
$definition,
|
||||||
[ {
|
[ {
|
||||||
|
name => 'Flat Rate',
|
||||||
|
fields => {
|
||||||
|
flatFee => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => ignore(),
|
||||||
|
hoverHelp => ignore(),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
percentageOfPrice => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => ignore(),
|
||||||
|
hoverHelp => ignore(),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
pricePerWeight => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => ignore(),
|
||||||
|
hoverHelp => ignore(),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
pricePerItem => {
|
||||||
|
fieldType => 'float',
|
||||||
|
label => ignore(),
|
||||||
|
hoverHelp => ignore(),
|
||||||
|
defaultValue => 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
name => 'Shipper Driver',
|
name => 'Shipper Driver',
|
||||||
fields => {
|
fields => {
|
||||||
label => {
|
label => {
|
||||||
|
|
@ -74,10 +103,9 @@ cmp_deeply(
|
||||||
label => ignore(),
|
label => ignore(),
|
||||||
hoverHelp => ignore(),
|
hoverHelp => ignore(),
|
||||||
defaultValue => 1,
|
defaultValue => 1,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
} ],
|
} ],
|
||||||
,
|
|
||||||
'Definition returns an array of hashrefs',
|
'Definition returns an array of hashrefs',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -90,16 +118,21 @@ cmp_deeply(
|
||||||
my $driver;
|
my $driver;
|
||||||
|
|
||||||
my $options = {
|
my $options = {
|
||||||
label => 'Slow and dangerous',
|
label => 'flat rate, ship weight, items in the cart',
|
||||||
enabled => 1,
|
enabled => 1,
|
||||||
|
flatFee => 1.00,
|
||||||
|
percentageOfPrice => 5,
|
||||||
|
pricePerWeight => 0.5,
|
||||||
|
pricePerItem => 0.1,
|
||||||
};
|
};
|
||||||
|
|
||||||
$driver = WebGUI::Shop::ShipDriver->create( $session, $options);
|
$driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
|
||||||
|
|
||||||
isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate');
|
isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate');
|
||||||
|
|
||||||
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
||||||
|
|
||||||
|
cmp_deeply($driver->options, $options, 'options accessor works');
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
|
|
@ -126,7 +159,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||||
|
|
||||||
my @inputs = $forms[0]->inputs;
|
my @inputs = $forms[0]->inputs;
|
||||||
is (scalar @inputs, 5, 'getEditForm: the form has 5 controls');
|
is (scalar @inputs, 9, 'getEditForm: the form has 9 controls');
|
||||||
|
|
||||||
my @interestingFeatures;
|
my @interestingFeatures;
|
||||||
foreach my $input (@inputs) {
|
foreach my $input (@inputs) {
|
||||||
|
|
@ -158,6 +191,22 @@ cmp_deeply(
|
||||||
name => 'enabled',
|
name => 'enabled',
|
||||||
type => 'radio',
|
type => 'radio',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name => 'flatFee',
|
||||||
|
type => 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'percentageOfPrice',
|
||||||
|
type => 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'pricePerWeight',
|
||||||
|
type => 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'pricePerItem',
|
||||||
|
type => 'text',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
'getEditForm made the correct form with all the elements'
|
'getEditForm made the correct form with all the elements'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue