diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 51fc47332..134a281d7 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.7.14 + - fixed #10606: shelf selector 7.7.13 - fixed #10574: Creating Calendar Entry diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index caaad5b6c..03e0a6ef2 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -255,7 +255,8 @@ sub getAddToCartForm { my $i18n = WebGUI::International->new($session, 'Asset_Product'); my %variants = (); 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}); } return diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index 3052b733c..a4b80f446 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -19,6 +19,8 @@ use lib "$FindBin::Bin/../../lib"; use Test::More; use Test::Deep; +use Data::Dumper; +use HTML::Form; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; @@ -34,7 +36,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # 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 @@ -51,6 +53,8 @@ my $image = WebGUI::Storage->create($session); WebGUI::Test->storagesToDelete($image); $image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); +WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session)); + my $imagedProduct = $node->addChild({ className => "WebGUI::Asset::Sku::Product", 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)); is($imagedProduct->getConfiguredTitle, 'Bible - English', 'getConfiguredTitle is overridden and concatenates the Product Title and the variant shortdesc'); -#---------------------------------------------------------------------------- -# Cleanup -END { - $product->purge; - $imagedProduct->purge; -} - -1; +my $addToCartForm = $imagedProduct->getAddToCartForm(); +diag $addToCartForm; +my @forms = HTML::Form->parse($addToCartForm, 'http://www.webgui.org'); +is(scalar @forms, 1, 'getAddToCartForm: returns only 1 form'); +my $form_variants = $forms[0]->find_input('vid'); +cmp_deeply( + [ $englishVarId ], + [ $form_variants->possible_values ], + '... form only has 1 variant, since the other one has 0 quantity' +);