Fix a bug with shipping costs as a percentage of weight. Build

a test to test the fix.
This commit is contained in:
Colin Kuskie 2008-10-07 22:43:22 +00:00
parent 334ce4791f
commit c0b9bdcc43
3 changed files with 65 additions and 2 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}
}