diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index dbf04e12d..b5264648f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -28,6 +28,7 @@ - rfe: Updated Thingy's edit instructions and search description fields to HTMLAreas (SDH Consulting Group) - rfe: Thingy Private Rows (SDH Consulting Group) + - fixed: Shop: Percentage of Weight Shipping Method doesn't work 7.6.0 - added: users may now customize the post received page for the CS diff --git a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm index b641ea88d..6ebc4e992 100644 --- a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm +++ b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm @@ -49,7 +49,7 @@ sub calculate { 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") * $sku->getWeight * $self->get("pricePerWeight") / 100) # cost by weight + ($item->get("quantity") * $self->get("pricePerItem")); # cost by item $anyShippable = 1; } diff --git a/t/Shop/ShipDriver/FlatRate.t b/t/Shop/ShipDriver/FlatRate.t index 20d042f50..0ebfd9ac4 100644 --- a/t/Shop/ShipDriver/FlatRate.t +++ b/t/Shop/ShipDriver/FlatRate.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 11; +my $tests = 12; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -40,6 +40,7 @@ plan tests => 1 + $tests; my $loaded = use_ok('WebGUI::Shop::ShipDriver::FlatRate'); my $storage; +my ($driver, $cart, $car); SKIP: { @@ -248,9 +249,70 @@ undef $driver; # ####################################################################### +my $car = WebGUI::Asset->getImportNode($session)->addChild({ + className => 'WebGUI::Asset::Sku::Product', + title => 'Automobiles', + isShippingRequired => 1, +}); + +my $crappyCar = $car->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => '1987 Ford Escort', + varSku => 'crappy-car', + price => 600, + weight => 1500, + quantity => 5, + } +); + +my $goodCar = $car->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => '2004 Honda MPV minivan', + varSku => 'used van', + price => 15_000, + weight => 2000, + quantity => 15, + } +); + +my $reallyNiceCar = $car->setCollateral('variantsJSON', 'variantId', 'new', + { + shortdesc => 'Cadillac XLR-V', + varSku => 'nice-car', + price => 90_000, + weight => 3000, + quantity => 3, + } +); + +$options = { + label => 'flat rate, ship weight', + enabled => 1, + flatFee => 1.00, + percentageOfPrice => 0, + pricePerWeight => 100, + pricePerItem => 0, + }; + +$driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options); + +my $cart = WebGUI::Shop::Cart->newBySession($session); +$car->addToCart($car->getCollateral('variantsJSON', 'variantId', $crappyCar)); + +is($driver->calculate($cart), 1501, 'calculate by weight and flat fee work'); + } #---------------------------------------------------------------------------- # Cleanup END { + if (defined $driver and ref $driver eq 'WebGUI::Shop::ShipDriver::FlatRate') { + $driver->delete; + } + if (defined $cart and ref $cart eq 'WebGUI::Shop::Cart') { + $cart->delete; + } + if (defined $car and ref $car eq 'WebGUI::Asset:Sku::Product') { + $car->purge; + } }