From 82056c66aa728179a8ab2766b9e72372a1c7f0e0 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 29 Apr 2008 01:26:45 +0000 Subject: [PATCH] Added an asset called Shelf, which allows you to create categories of Skus. --- docs/changelog/7.x.x.txt | 2 + .../root_import_shelf-default.wgpkg | Bin 0 -> 1188 bytes docs/upgrades/upgrade_7.5.10-7.5.11.pl | 19 +++ etc/WebGUI.conf.original | 7 +- lib/WebGUI/Asset.pm | 4 +- lib/WebGUI/Asset/Sku.pm | 13 ++ lib/WebGUI/Asset/Sku/Product.pm | 17 +-- lib/WebGUI/Asset/Wobject/Shelf.pm | 129 ++++++++++++++++++ lib/WebGUI/Keyword.pm | 73 ++++++++-- lib/WebGUI/i18n/English/Asset_Shelf.pm | 31 +++++ 10 files changed, 266 insertions(+), 29 deletions(-) create mode 100644 docs/upgrades/packages-7.5.11/root_import_shelf-default.wgpkg create mode 100644 lib/WebGUI/Asset/Wobject/Shelf.pm create mode 100644 lib/WebGUI/i18n/English/Asset_Shelf.pm diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5940f2f0d..6e8e99765 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -25,7 +25,9 @@ amounts of money using the new commerce system. - Merged all the old shipping plugins into one "Flat Rate" shipping plugin. See gotchas. + - rfe: Colorize Buttons on EMS - fix: Fwd: lazy guys bug report about the product system + - Added an asset called Shelf, which allows you to create categories of Skus. - fix: Processing a Cash/Check Order - Rewrote Event Manager fromthe ground up. - Added WebGUI.str javascript class with sprintf and trim methods. diff --git a/docs/upgrades/packages-7.5.11/root_import_shelf-default.wgpkg b/docs/upgrades/packages-7.5.11/root_import_shelf-default.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..8d6519fbd893466da0d2ce5c45022c72830a369b GIT binary patch literal 1188 zcmV;V1Y7$biwFP!000001MOB@PvbZg?(_T#D-SD>X4fO!cUz>}?QRcS1h&5XlWRj2xc1HH1vkl~24UN5_NWwtgZS$26I=gJ zBJkPwf&1d!^>^Cev=qZ(QDF6Mz_Rsn6gHJ62Y`*;SQu%Mcyz9?l;l~?j zLQfm1=$v^ZAbqEEPRD;A3&WJ4)(%ZKbUuxMrMXm4 zrf>IbYOl_0f;M-9urnQ#LJ{LlrOZeZnvjVBR21eS1#-#N)r>1`uCB(vOrd&rLl?1= zy1<+gC5d9QUngEoJXFhg;yu6~E&X?3){koC=@g;M(1>v!8AnGL^CgL(*EHBJBw!Td zw3Se1)+G62Dkx7ctXCi*Bz)B83b4|$aqz{QXcgUwvD$#J9-*nZD|eOTkq(rfi@TtZ z&(ICX;eYi5L$Z}!RwD&$$n8c=eWrNC#+%_(f#JJcSjBRRI1f5NVezY~i(1L@tIaxP z5Lc8kssb{VCfT)&RGQXA-K;p;-X~PdADoL^uwt}&_LRMQ*w!eR)UR~m=ENnNe!Msi z0<7sEI4|cxHBXTYoEup1WaGe%q|F+!7%;zc=H}|K7IAII4xOgXT4P}8Yo2|ThR-;3 z7IYb!XiTjI6FJU{r)^tKa-6;%&7e+~&2f)2_>6xqjBj-t_!(6&)e-y=4uat5{LAP2 zj3hAf_fr{NqjHEzBzEvZCJh`4ok;7VRoYb@6I`9Hc3EwgIY0RRwW?a#u{*-0B{u$nj3l7Lds^&03i#i=3Kl(n-;Wk zrVv0i8o2=I(i-{{b}-&?GsT~Qi?Sl`pT$MNB3Yx+a5NeWdyPCOw&eD(IVew|ZqFa} zw|b*d7=O4-F-}@7&{| z*W2kf+6ju5iSkx)x{vjZydb->write(q{ + create table Shelf ( + assetId varchar(22) binary not null, + revisionDate bigint, + templateId varchar(22) binary not null default 'nFen0xjkZn8WkpM93C9ceQ', + primary key (assetId,revisionDate) + ) + }); + $session->config->addToArray("assetContainers","WebGUI::Asset::Wobject::Shelf"); + print "DONE!\n" unless $quiet; +} #---------------------------------------------------------------------------- # Add the useCaptcha field to DataForm assets sub addCaptchaToDataForm { diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 8655333b2..205bdf2c1 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -217,13 +217,12 @@ "WebGUI::Asset::Wobject::Collaboration", "WebGUI::Asset::Wobject::DataForm", "WebGUI::Asset::Wobject::Calendar", - "WebGUI::Asset::Wobject::EventManagementSystem", - "WebGUI::Asset::Wobject::Gallery", + "WebGUI::Asset::Wobject::EventManagementSystem", + "WebGUI::Asset::Wobject::Gallery", "WebGUI::Asset::Wobject::HttpProxy", "WebGUI::Asset::Wobject::Navigation", "WebGUI::Asset::Wobject::Matrix", "WebGUI::Asset::Wobject::Poll", - "WebGUI::Asset::Wobject::Product", "WebGUI::Asset::Wobject::ProjectManager", "WebGUI::Asset::Wobject::SQLReport", "WebGUI::Asset::Wobject::Search", @@ -236,6 +235,7 @@ "WebGUI::Asset::Wobject::InOutBoard", "WebGUI::Asset::File::ZipArchive", "WebGUI::Asset::Wobject::WSClient", + "WebGUI::Asset::Wobject::Shelf", "WebGUI::Asset::Wobject::SQLForm", "WebGUI::Asset::Wobject::Thingy" ], @@ -254,6 +254,7 @@ "assetContainers" : [ "WebGUI::Asset::Wobject::Layout", "WebGUI::Asset::Wobject::Folder", "WebGUI::Asset::Wobject::Dashboard", "WebGUI::Asset::Wobject::MessageBoard", + "WebGUI::Asset::Sku::Product", "WebGUI::Asset::Wobject::WikiMaster" ], diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 7629c8ef3..bb6d153e0 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -947,9 +947,9 @@ sub getEditForm { # display keywords field $tabform->getTab('meta')->text( name => 'keywords', - value => $self->get('keywords'), label => $i18n->get('keywords'), hoverHelp => $i18n->get('keywords help'), + value => $self->get('keywords'), ); # metadata / content profiling @@ -1954,7 +1954,7 @@ sub prepareView { my $self = shift; $self->{_toolbar} = $self->getToolbar; my $style = $self->session->style; - my @keywords = $self->get('keywords'); + my @keywords = @{WebGUI::Keyword->new($self->session)->getKeywordsForAsset({asset=>$self, asArrayRef=>1})}; if (scalar @keywords) { $style->setMeta( { name => 'keywords', diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 6eaa92d7c..12777a640 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -279,6 +279,19 @@ sub getTaxRate { #------------------------------------------------------------------- +=head2 getThumbnailUrl ( ) + +Returns undef. Should be overridden by any skus that have images. + +=cut + +sub getThumbnailUrl { + my $self = shift; + return undef; +} + +#------------------------------------------------------------------- + =head2 getWeight ( ) Returns 0. Needs to be overriden by subclasses. diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index ffaf358e3..9ab21381b 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -277,24 +277,11 @@ sub getPrice { return $self->get('price'); } -#------------------------------------------------------------------- -sub getThumbnailFilename { - my $self = shift; - my $filestore = $_[0]; - my $files = $filestore->getFiles(); - foreach my $file (@{$files}){ - if($file =~ m/^thumb-/){ - return $file; - } - } - return ""; -} - #------------------------------------------------------------------- sub getThumbnailUrl { my $self = shift; - my $store = $_[0]; - return $store->getUrl($self->getThumbnailFilename($store)); + my $store = shift || WebGUI::Storage::Image->get($self->session, $self->get('image1')); + return $store->getThumbnailUrl($store->getFiles->[0]); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm new file mode 100644 index 000000000..07aa41378 --- /dev/null +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -0,0 +1,129 @@ +package WebGUI::Asset::Wobject::Shelf; + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2008 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use Tie::IxHash; +use WebGUI::International; +use base 'WebGUI::Asset::Wobject'; + +#------------------------------------------------------------------- + +=head2 definition ( ) + +Add our custom properties of templateId to this asset. + +=cut + +sub definition { + my ($class, $session, $definition) = @_; + my $i18n = WebGUI::International->new($session, 'Asset_Shelf'); + my %properties; + tie %properties, 'Tie::IxHash'; + %properties = ( + templateId =>{ + fieldType => "template", + defaultValue => 'nFen0xjkZn8WkpM93C9ceQ', + tab => "display", + namespace => "Shelf", + hoverHelp => $i18n->get('view template help'), + label => $i18n->get('view template'), + } + ); + push(@{$definition}, { + assetName => $i18n->get('assetName'), + icon => 'Shelf.gif', + autoGenerateForms => 1, + tableName => 'Shelf', + className => 'WebGUI::Asset::Wobject::Shelf', + properties => \%properties + }); + return $class->SUPER::definition($session, $definition); +} + + + +#------------------------------------------------------------------- + +=head2 prepareView ( ) + +See WebGUI::Asset::prepareView() for details. + +=cut + +sub prepareView { + my $self = shift; + $self->SUPER::prepareView(); + my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); + $template->prepare; + $self->{_viewTemplate} = $template; +} + + +#------------------------------------------------------------------- + +=head2 view ( ) + +method called by the www_view method. Returns a processed template +to be displayed within the page style. + +=cut + +sub view { + my $self = shift; + my $session = $self->session; + + # get other shelves + my @children = (); + foreach my $child (@{$self->getLineage(['children'],{returnObjects=>1,includeOnlyClasses=>['WebGUI::Asset::Wobject::Shelf']})}) { + my $properties = $child->get; + $child->{url} = $self->getUrl; + push @children, $child; + } + + # find products based upon keywords + my @keywords = $self->get('keywords'); + my $p = WebGUI::Keyword->new($session)->getMatchingAssets({ + matchAssetKeywords => $self, + isa => 'WebGUI::Asset::Sku', + usePaginator => 1, + }); + $p->setBaseUrl($self->getUrl('func=view')); + + # generate template variables + my @skus = (); + foreach my $row (@{$p->getPageData}) { + my $id = $row->{assetId}; + 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); + push @skus, $sku; + } + else { + $session->errorHandler->error(q|Couldn't instanciate SKU with assetId |.$id.q| on shelf with assetId |.$self->getId); + } + } + my %var = ( + shelves => \@children, + products => \@skus, + ); + $p->appendTemplateVars(\%var); + + # render page + return $self->processTemplate(\%var, undef, $self->{_viewTemplate}); +} + + + +1; diff --git a/lib/WebGUI/Keyword.pm b/lib/WebGUI/Keyword.pm index d5e0ba112..75bb6ce20 100644 --- a/lib/WebGUI/Keyword.pm +++ b/lib/WebGUI/Keyword.pm @@ -157,7 +157,7 @@ sub getKeywordsForAsset { return \@keywords; } else { - return wantarray ? @keywords : join(" ", map({ m/\s/ ? '"' . $_ . '"' : $_ } @keywords)); + return join(" ", map({ m/\s/ ? '"' . $_ . '"' : $_ } @keywords)); } } @@ -166,34 +166,89 @@ sub getKeywordsForAsset { =head2 getMatchingAssets ( { startAsset => $asset, keyword => $keyword } ) -Returns an array reference of asset ids matching the start point + keyword. +Returns an array reference of asset ids matching the params. =head3 startAsset -An asset object where you'd like to start searching for matching keywords. +An asset object where you'd like to start searching for matching keywords. Doesn't search any particular branch if one isn't specified. =head3 keyword The keyword to match. +=head3 keywords + +An array reference of keywords to match. + +=head3 matchAssetKeywords + +A reference to an asset that has a list of keywords to match. This can help locate assets that are similar to another asset. + +=head3 isa + +A classname pattern to match. For example, if you provide 'WebGUI::Asset::Sku' then everything that has a class name that starts with that including 'WebGUI::Asset::Sku::Product' will be included. + =head3 usePaginator -Instead of returning an array reference of assetId's, return a paginator object. +Instead of returning an array reference of assetId's, return a paginator object. =cut sub getMatchingAssets { my ($self, $options) = @_; - my $query = "select assetKeyword.assetId from assetKeyword left join asset using (assetId) - where lineage like ? and keyword=? order by creationDate desc"; - my $params = [$options->{startAsset}->get("lineage").'%', $options->{keyword}]; + + # base query + my @clauses = (); + my @params = (); + + # what lineage are we looking for + if (exists $options->{startAsset}) { + push @clauses, 'lineage like ?'; + push @params, $options->{startAsset}->get("lineage").'%'; + } + + # matching keywords against another asset + if (exists $options->{matchAssetKeywords}) { + $options->{keywords} = $self->getKeywordsForAsset({ + asset => $options->{matchAssetKeywords}, + asArrayRef => 1, + }); + } + + # looking for a class name match + if (exists $options->{isa}) { + push @clauses, 'className like ?'; + push @params, $options->{isa}.'%'; + } + + # looking for a single keyword + if (exists $options->{keyword}) { + push @clauses, 'keyword=?'; + push @params, $options->{keyword}; + } + + # looking for a list of keywords + if (exists $options->{keywords}) { + my @placeholders = (); + foreach my $word (@{$options->{keywords}}){ + push @placeholders, '?'; + push @params, $word; + } + push @clauses, 'keyword in ('.join(',', @placeholders).')'; + } + + # write the query + my $query = 'select distinct assetKeyword.assetId from assetKeyword left join asset using (assetId) + where '.join(' and ', @clauses).' order by creationDate desc'; + + # perform the search if ($options->{usePaginator}) { my $p = WebGUI::Paginator->new($self->session); - $p->setDataByQuery($query, undef, undef, $params); + $p->setDataByQuery($query, undef, undef, \@params); return $p; } else { - return $self->session->db->buildArrayRef($query, $params); + return $self->session->db->buildArrayRef($query, \@params); } } diff --git a/lib/WebGUI/i18n/English/Asset_Shelf.pm b/lib/WebGUI/i18n/English/Asset_Shelf.pm new file mode 100644 index 000000000..262569cfa --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_Shelf.pm @@ -0,0 +1,31 @@ +package WebGUI::i18n::English::Asset_Shelf; + +use strict; + +our $I18N = { + 'subcategories' => { + message => q|Subcategories|, + lastUpdated => 0, + context => q|a template label|, + }, + + 'view template' => { + message => q|View Template|, + lastUpdated => 0, + context => q|a property|, + }, + + 'view template help' => { + message => q|Choose the template that will display the list of products associated with this shelf.|, + lastUpdated => 0, + context => q|help for a property|, + }, + + 'assetName' => { + message => q|Shelf|, + lastUpdated => 0, + context => q|the name of the asset|, + }, +}; + +1;