added shipping calculation for flat rate
This commit is contained in:
parent
819552ce06
commit
e6d42bd219
3 changed files with 30 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue