From e6d42bd21991df4999d2d6d234c8ff788e9613dc Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 13 Mar 2008 13:57:44 +0000 Subject: [PATCH] added shipping calculation for flat rate --- lib/WebGUI/Asset/Sku.pm | 13 +++++++++++++ lib/WebGUI/Shop/ShipDriver/FlatRate.pm | 18 ++++++++++++++++-- t/Asset/Sku.t | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 5fc2a78db..bdb9bffa8 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -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. diff --git a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm index 030850632..5e69a56d3 100644 --- a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm +++ b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm @@ -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; } #------------------------------------------------------------------- diff --git a/t/Asset/Sku.t b/t/Asset/Sku.t index 62640eccb..dc97f5641 100644 --- a/t/Asset/Sku.t +++ b/t/Asset/Sku.t @@ -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.");