diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index be3d06f5a..16ef4633b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -9,6 +9,7 @@ - fixed: can now turn off inheritUrlFromParent and the code is now more robust, moved from Asset->update to Asset->fixUrl. - fixed: Time tracker can't post time once it's been posted. + - fixed: Shop: Product asset- image not showing 7.5.13 - fixed: storage locations for some assets in packages not imported correctly diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 77512d6f3..782db2bdf 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -442,12 +442,32 @@ sub getQuantityAvailable { } #------------------------------------------------------------------- + +=head2 getThumbnailUrl ( [$store] ) + +Return a URL to the thumbnail for an image stored in this Product by creating +a WebGUI::Storage::Image object and calling its getThumbnailUrl method. + +=head3 $store + +This should be a WebGUI::Storage::Image object. If it is not defined, +then by default getThumbnailUrl will attempt to look up the URL for +the 'image1' property. + +If image1 is not defined for this Product and a separate storage object is not +sent in, it will return the empty string. + +=cut + sub getThumbnailUrl { my $self = shift; my $store = shift; - if (! defined $store and $self->get('image1')) { + if (defined $store) { + return $store->getThumbnailUrl($store->getFiles->[0]); + } + elsif ($self->get('image1')) { $store = WebGUI::Storage::Image->get($self->session, $self->get('image1')); - return $store->getThumbnailUrl($store->getFiles->[0]); + return $store->getThumbnailUrl($store->getFiles->[0]); } else { return ''; diff --git a/t/Asset/Sku/Product.t b/t/Asset/Sku/Product.t index 095b320b7..fce39fbbc 100644 --- a/t/Asset/Sku/Product.t +++ b/t/Asset/Sku/Product.t @@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Sku::Product; +use WebGUI::Storage::Image; #---------------------------------------------------------------------------- # Init @@ -33,7 +34,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 2; # Increment this number for each test you create +plan tests => 7; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -41,10 +42,38 @@ my $node = WebGUI::Asset::Sku::Product->getProductImportNode($session); isa_ok($node, 'WebGUI::Asset::Wobject::Folder', 'getProductImportNode returns a Folder'); is($node->getId, 'PBproductimportnode001', 'Product Import Node has the correct GUID'); +my $product = $node->addChild({ + className => "WebGUI::Asset::Sku::Product", + title => "Rock Hammer", +}); + +is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string'); + +my $image = WebGUI::Storage::Image->create($session); +$image->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); + +my $imagedProduct = $node->addChild({ + className => "WebGUI::Asset::Sku::Product", + title => "Bible", + image1 => $image->getId, +}); + +ok($imagedProduct->getThumbnailUrl(), 'getThumbnailUrl is not empty'); +is($imagedProduct->getThumbnailUrl(), $image->getThumbnailUrl('lamp.jpg'), 'getThumbnailUrl returns the right path to the URL'); + +my $otherImage = WebGUI::Storage::Image->create($session); +$otherImage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jpg')); + +ok($imagedProduct->getThumbnailUrl($otherImage), 'getThumbnailUrl with an explicit storageId returns something'); +is($imagedProduct->getThumbnailUrl($otherImage), $otherImage->getThumbnailUrl('gooey.jpg'), 'getThumbnailUrl with an explicit storageId returns the right path to the URL'); + #---------------------------------------------------------------------------- # Cleanup END { - + $product->purge; + $imagedProduct->purge; + $image->delete; + $otherImage->delete; } 1; diff --git a/t/Asset/Sku/ProductCollateral.t b/t/Asset/Sku/ProductCollateral.t index 2789709aa..46f9508e1 100644 --- a/t/Asset/Sku/ProductCollateral.t +++ b/t/Asset/Sku/ProductCollateral.t @@ -41,9 +41,9 @@ plan tests => 33; # Increment this number for each test you create # put your tests here my $root = WebGUI::Asset->getRoot($session); my $product = $root->addChild({ - className => "WebGUI::Asset::Sku::Product", - title => "Rock Hammer", - }); + className => "WebGUI::Asset::Sku::Product", + title => "Rock Hammer", +}); isa_ok($product, "WebGUI::Asset::Sku::Product"); ok(! exists $product->{_collateral}, 'object cache does not exist yet'); diff --git a/t/supporting_collateral/gooey.jpg b/t/supporting_collateral/gooey.jpg new file mode 100644 index 000000000..0a364a6af Binary files /dev/null and b/t/supporting_collateral/gooey.jpg differ