Fix the form for the Product. It was returning variants with no quantity.

This commit is contained in:
Colin Kuskie 2009-07-03 16:19:26 +00:00
parent 1bcae0d3bc
commit df51a0d99f
3 changed files with 28 additions and 11 deletions

View file

@ -1,4 +1,5 @@
7.7.14 7.7.14
- fixed #10606: shelf selector
7.7.13 7.7.13
- fixed #10574: Creating Calendar Entry - fixed #10574: Creating Calendar Entry

View file

@ -255,7 +255,8 @@ sub getAddToCartForm {
my $i18n = WebGUI::International->new($session, 'Asset_Product'); my $i18n = WebGUI::International->new($session, 'Asset_Product');
my %variants = (); my %variants = ();
tie %variants, 'Tie::IxHash'; tie %variants, 'Tie::IxHash';
foreach my $collateral ( @{ $self->getAllCollateral('variantsJSON')} ) { COLLATERAL: foreach my $collateral ( @{ $self->getAllCollateral('variantsJSON')} ) {
next COLLATERAL unless $collateral->{quantity} > 0;
$variants{$collateral->{variantId}} = join ", ", $collateral->{shortdesc}, sprintf('%.2f',$collateral->{price}); $variants{$collateral->{variantId}} = join ", ", $collateral->{shortdesc}, sprintf('%.2f',$collateral->{price});
} }
return return

View file

@ -19,6 +19,8 @@ use lib "$FindBin::Bin/../../lib";
use Test::More; use Test::More;
use Test::Deep; use Test::Deep;
use Data::Dumper;
use HTML::Form;
use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session; use WebGUI::Session;
@ -34,7 +36,7 @@ my $session = WebGUI::Test->session;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Tests # Tests
plan tests => 8; # Increment this number for each test you create plan tests => 10; # Increment this number for each test you create
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# put your tests here # put your tests here
@ -51,6 +53,8 @@ my $image = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($image); WebGUI::Test->storagesToDelete($image);
$image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); $image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg'));
WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session));
my $imagedProduct = $node->addChild({ my $imagedProduct = $node->addChild({
className => "WebGUI::Asset::Sku::Product", className => "WebGUI::Asset::Sku::Product",
title => "Bible", title => "Bible",
@ -81,16 +85,27 @@ my $englishVarId = $imagedProduct->setCollateral('variantsJSON', 'variantId', 'n
} }
); );
use Data::Dumper; my $otherVarId = $imagedProduct->setCollateral('variantsJSON', 'variantId', 'new',
{
shortdesc => 'Elbonian',
varSku => 'Elbonian-bible',
price => 11,
weight => 7,
quantity => 0,
}
);
$imagedProduct->applyOptions($imagedProduct->getCollateral('variantsJSON', 'variantId', $englishVarId)); $imagedProduct->applyOptions($imagedProduct->getCollateral('variantsJSON', 'variantId', $englishVarId));
is($imagedProduct->getConfiguredTitle, 'Bible - English', 'getConfiguredTitle is overridden and concatenates the Product Title and the variant shortdesc'); is($imagedProduct->getConfiguredTitle, 'Bible - English', 'getConfiguredTitle is overridden and concatenates the Product Title and the variant shortdesc');
#---------------------------------------------------------------------------- my $addToCartForm = $imagedProduct->getAddToCartForm();
# Cleanup diag $addToCartForm;
END { my @forms = HTML::Form->parse($addToCartForm, 'http://www.webgui.org');
$product->purge; is(scalar @forms, 1, 'getAddToCartForm: returns only 1 form');
$imagedProduct->purge; my $form_variants = $forms[0]->find_input('vid');
} cmp_deeply(
[ $englishVarId ],
1; [ $form_variants->possible_values ],
'... form only has 1 variant, since the other one has 0 quantity'
);