Add an option to the Sku to require individual shipping of this sku, separate

from other items in the cart.  Update the FlatRate driver to support calculating that.
This commit is contained in:
Colin Kuskie 2009-04-29 16:52:16 +00:00
parent e98fc02e9b
commit db290f91f9
8 changed files with 141 additions and 14 deletions

View file

@ -30,7 +30,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 17; # Increment this number for each test you create
plan tests => 19; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -63,6 +63,10 @@ is($sku->onRemoveFromCart, undef, "onRemoveFromCart should exist and return unde
is($sku->isRecurring, 0, "skus are not recurring by default");
is($sku->isShippingRequired, 0, "skus are not shippable by default");
is($sku->getConfiguredTitle, $sku->getTitle, "configured title and title should be the same by default");
is($sku->shipsSeparately, 0, 'shipsSeparately return 0 by default');
$sku->update({shipsSeparately => 1,});
is($sku->shipsSeparately, 1, '... tracks shipsSepartely sku property');
isa_ok($sku->getCart, "WebGUI::Shop::Cart", "can get a cart object");
my $item = $sku->addToCart;
@ -72,12 +76,12 @@ $item->cart->delete;
my $loadSku = WebGUI::Asset::Sku->newBySku($session, $sku->get("sku"));
is($loadSku->getId, $sku->getId, "newBySku() works.");
$sku->purge;
#----------------------------------------------------------------------------
# Cleanup
END {
$sku->purge;
}
1;

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 14;
my $tests = 19;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -40,7 +40,7 @@ plan tests => 1 + $tests;
my $loaded = use_ok('WebGUI::Shop::ShipDriver::FlatRate');
my $storage;
my ($driver, $cart, $car);
my ($driver, $cart, $car, $key);
my $versionTag;
SKIP: {
@ -127,8 +127,6 @@ cmp_deeply(
#
#######################################################################
$driver;
my $options = {
label => 'flat rate, ship weight, items in the cart',
enabled => 1,
@ -319,6 +317,60 @@ $options = {
$driver->update($options);
is($driver->calculate($cart), 30_200, 'calculate by percentage of price');
$cart->empty();
$driver->update({
label => 'flat fee for shipsSeparately test',
enabled => 1,
flatFee => 1,
percentageOfPrice => 0,
pricePerWeight => 0,
pricePerItem => 0,
});
$key = WebGUI::Asset->getImportNode($session)->addChild({
className => 'WebGUI::Asset::Sku::Product',
title => 'Key',
isShippingRequired => 1,
shipsSeparately => 1,
});
my $metalKey = $key->setCollateral('variantsJSON', 'variantId', 'new',
{
shortdesc => 'metal key',
varSku => 'metal-key',
price => 1.00,
weight => 1.00,
quantity => 1e9,
}
);
my $bioKey = $key->setCollateral('variantsJSON', 'variantId', 'new',
{
shortdesc => 'biometric key',
varSku => 'bio-key',
price => 5.00,
weight => 1.00,
quantity => 1e9,
}
);
my $boughtCar = $car->addToCart($car->getCollateral('variantsJSON', 'variantId', $reallyNiceCar));
my $firstKey = $key->addToCart($key->getCollateral('variantsJSON', 'variantId', $metalKey));
is($driver->calculate($cart), 2, 'shipsSeparately: returns two, one for ships separately, one for ships bundled');
$boughtCar->adjustQuantity();
is($driver->calculate($cart), 2, '... returns two, one for ships separately, one for ships bundled, even for two items');
$firstKey->adjustQuantity();
is($driver->calculate($cart), 3, '... returns three, two for ships separately, one for ships bundled, even for two items');
$key->update({shipsSeparately => 0});
is($driver->calculate($cart), 1, '... returns one, since all can be bundled together now');
$car->update({shipsSeparately => 1});
$key->update({shipsSeparately => 1});
is($driver->calculate($cart), 4, '... returns four, since all must be shipped separately now');
}
#----------------------------------------------------------------------------
@ -333,6 +385,9 @@ END {
if (defined $car && (ref($car) eq 'WebGUI::Asset::Sku::Product')) {
$car->purge;
}
if (defined $key && (ref($key) eq 'WebGUI::Asset::Sku::Product')) {
$key->purge;
}
if (defined $versionTag) {
$versionTag->rollback;
}