added shipping calculation for flat rate

This commit is contained in:
JT Smith 2008-03-13 13:57:44 +00:00
parent 819552ce06
commit e6d42bd219
3 changed files with 30 additions and 2 deletions

View file

@ -241,6 +241,19 @@ sub getTaxRate {
#-------------------------------------------------------------------
=head2 getWeight ( )
Returns 0. Needs to be overriden by subclasses.
=cut
sub getWeight {
my $self = shift;
return 0;
}
#-------------------------------------------------------------------
=head2 indexContent ( )
Adding sku as a keyword. See WebGUI::Asset::indexContent() for additonal details.

View file

@ -42,8 +42,22 @@ costs are assessed.
=cut
sub calculate {
my $self = shift;
return;
my ($self, $cart) = @_;
my $cost = 0;
my $anyShippable = 0;
foreach my $item (@{$cart->getItems}) {
my $sku = $item->getSku;
if ($sku->isShippingRequired) {
$cost += ($item->get("quantity") * $sku->getPrice * $self->get("percentageOfPrice") / 100) # cost by price
+ ($item->get("quantity") * $sku->getWeight * $self->get("percentageOfWeight") / 100) # cost by weight
+ ($item->get("quantity") * $self->get("pricePerItem")); # cost by item
$anyShippable = 1;
}
}
if ($anyShippable) {
$cost += $flatFee;
}
return $cost;
}
#-------------------------------------------------------------------

View file

@ -53,6 +53,7 @@ is($options{test1}, "YY", "Can set and get an option.");
is($sku->getMaxAllowedInCart, 99999999, "Got a valid default max in cart.");
is($sku->getPrice, 0.00, "Got a valid default price.");
is($sku->getWeight, 0, "Got a valid default weight.");
is($sku->getTaxRate, undef, "Tax rate is not overridden.");
$sku->update({overrideTaxRate=>1, taxRateOverride=>5});
is($sku->getTaxRate, 5, "Tax rate is overridden.");