The shelf now checks for viewing permissions of the products and shelves that it displays.

Template with i18n feedback for users.
This commit is contained in:
Colin Kuskie 2009-07-17 21:01:55 +00:00
parent 9a6d5d6eb0
commit f2bd5d8e48
5 changed files with 123 additions and 38 deletions

View file

@ -288,8 +288,9 @@ sub view {
# get other shelves
my @childShelves = ();
foreach my $child (@{$self->getLineage(['children'],{returnObjects=>1,includeOnlyClasses=>['WebGUI::Asset::Wobject::Shelf']})}) {
my $properties = $child->get;
SHELF: foreach my $child (@{$self->getLineage(['children'],{returnObjects=>1,includeOnlyClasses=>['WebGUI::Asset::Wobject::Shelf']})}) {
next SHELF unless $child->canView;
my $properties = $child->get;
$child->{url} = $child->getUrl;
$child->{title} = $child->getTitle;
push @childShelves, $child;
@ -305,30 +306,38 @@ sub view {
isa => 'WebGUI::Asset::Sku',
});
##Prescreen to only paginate viewable products
my @productIds = List::MoreUtils::uniq(@childSkus, @{$keywordBasedAssetIds});
my @products = ();
PRODUCT: foreach my $id (@productIds) {
my $asset = WebGUI::Asset->newByDynamicClass($session, $id);
if (defined $asset && $asset->canView) {
push @products, $asset;
}
else {
$session->errorHandler->error(q|Couldn't instanciate SKU with assetId |.$id.q| on shelf with assetId |.$self->getId);
}
}
# create paginator
my @products = List::MoreUtils::uniq(@childSkus, @{$keywordBasedAssetIds});
my $p = WebGUI::Paginator->new($session, $self->getUrl('func=view'));
$p->setDataByArrayRef(\@products);
# generate template variables
my @skus = ();
foreach my $id (@{$p->getPageData}) {
my $asset = WebGUI::Asset->newByDynamicClass($session, $id);
if (defined $asset) {
my $sku = $asset->get;
$sku->{url} = $asset->getUrl;
$sku->{thumbnailUrl} = $asset->getThumbnailUrl;
$sku->{price} = sprintf("%.2f", $asset->getPrice);
$sku->{addToCartForm} = $asset->getAddToCartForm;
push @skus, $sku;
}
else {
$session->errorHandler->error(q|Couldn't instanciate SKU with assetId |.$id.q| on shelf with assetId |.$self->getId);
}
}
my @skus = ();
foreach my $asset (@{$p->getPageData}) {
my $sku = $asset->get;
$sku->{url} = $asset->getUrl;
$sku->{thumbnailUrl} = $asset->getThumbnailUrl;
$sku->{price} = sprintf("%.2f", $asset->getPrice);
$sku->{addToCartForm} = $asset->getAddToCartForm;
push @skus, $sku;
}
my %var = (
shelves => \@childShelves,
products => \@skus,
shelves => \@childShelves,
products => \@skus,
noViewableSkus => scalar(@skus) ? 0 : 1,
emptyShelf => scalar(@productIds) ? 0 : 1,
);
$p->appendTemplateVars(\%var);

View file

@ -29,6 +29,8 @@ our $HELP = {
],
},
{ name => "templateId", description=>"shelf template help" },
{ name => "noViewableSkus", },
{ name => "emptyShelf", },
],
related => [
],

View file

@ -46,14 +46,14 @@ our $I18N = {
},
'shelves' => {
message => q|A loop containing the list of shelves that are children of this one in the asset tree. Each record in the loop contains all the properties of a shelf.|,
message => q|A loop containing the list of shelves that are children of this one in the asset tree. Each record in the loop contains all the properties of a shelf. Only shelves that the user can see will be in the loop.|,
lastUpdated => 0,
context => q|a template variable|,
},
'products' => {
message => q|A loop containing the list of products that match the keywords specified in this shelf. Each record in the loop contains all the properties of the matching sku, plus the following variables.|,
lastUpdated => 0,
message => q|A loop containing the list of products that match the keywords specified in this shelf, or that are children of this shelf. Only products that the user can see will be in the loop. Each record in the loop contains all the properties of the matching sku, plus the following variables.|,
lastUpdated => 1247603018,
context => q|a template variable|,
},
@ -75,6 +75,30 @@ our $I18N = {
context => q|help for a property|,
},
'noViewableSkus' => {
message => q|A boolean which is true if there are no products on this shelf which the current user can view.|,
lastUpdated => 0,
context => q|Template variable help|,
},
'emptyShelf' => {
message => q|A boolean which is true if this shelf has any Products at all.|,
lastUpdated => 0,
context => q|Template variable help|,
},
'this shelf is empty' => {
message => q|This shelf is empty.|,
lastUpdated => 0,
context => q|template label|,
},
'You do not have permission to view the products on this shelf' => {
message => q|You do not have permission to view the products on this shelf.|,
lastUpdated => 0,
context => q|template label|,
},
'assetName' => {
message => q|Shelf|,
lastUpdated => 0,