From 01b8ccf412f142af5dd164b29ff8e488a2a05bf8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 28 Mar 2009 17:25:43 +0000 Subject: [PATCH] Add getAddToCartForm to skus, update Shelf code, help, i18n and template. --- docs/changelog/7.x.x.txt | 4 ++++ lib/WebGUI/Asset/Sku.pm | 21 +++++++++++++++++ lib/WebGUI/Asset/Sku/Ad.pm | 12 ++++++++++ lib/WebGUI/Asset/Sku/Donation.pm | 22 ++++++++++++++++++ lib/WebGUI/Asset/Sku/EMSBadge.pm | 20 +++++++++++++++++ lib/WebGUI/Asset/Sku/EMSRibbon.pm | 20 +++++++++++++++++ lib/WebGUI/Asset/Sku/EMSTicket.pm | 19 ++++++++++++++++ lib/WebGUI/Asset/Sku/EMSToken.pm | 20 +++++++++++++++++ lib/WebGUI/Asset/Sku/Product.pm | 31 ++++++++++++++++++++++++++ lib/WebGUI/Asset/Sku/Subscription.pm | 21 +++++++++++++++++ lib/WebGUI/Asset/Wobject/Shelf.pm | 9 ++++---- lib/WebGUI/Help/Asset_Shelf.pm | 3 +++ lib/WebGUI/i18n/English/Asset_Shelf.pm | 12 ++++++++++ lib/WebGUI/i18n/English/Asset_Sku.pm | 12 ++++++++++ 14 files changed, 222 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0a6f9f6d1..7b1a326eb 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,10 @@ - fixed #9955: Matrix alpha sort is backwards - fixed #9934: Matrix 2.0 - Products should be listed alphabetically - fixed #9865: Matrix: Later added attributes are not detected in older listings + - added: Sku's now have a getAddToCartForm method, which is used by the Shelf + to place a small form next to each Sku that displays. Sku's with complex + forms (like the EMS sku's), simply display a button to take the user to the + sku's view screen for the whole form. [TEMPLATE] 7.7.1 - the AdSku project: create a Sku that allows buyers to purchase advertising in select AdSpaces at selected priorities diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 944027c21..573034010 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -159,6 +159,27 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm ( ) + +Returns a form to add this Sku to the cart. Used when this Sku is part of +a shelf. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Sku'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'addToCart'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('add to cart')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getCart ( ) diff --git a/lib/WebGUI/Asset/Sku/Ad.pm b/lib/WebGUI/Asset/Sku/Ad.pm index 49fce1263..16af9a5cc 100644 --- a/lib/WebGUI/Asset/Sku/Ad.pm +++ b/lib/WebGUI/Asset/Sku/Ad.pm @@ -138,6 +138,18 @@ sub definition { #------------------------------------------------------------------- +=head2 getAddToCartForm + +Returns an empty string, since the add to cart form is complex. + +=cut + +sub getAddToCartForm { + return ''; +} + +#------------------------------------------------------------------- + =head2 getClickDiscountText returns the text to display the number of clicks purchasaed where discounts apply diff --git a/lib/WebGUI/Asset/Sku/Donation.pm b/lib/WebGUI/Asset/Sku/Donation.pm index f6d3f4e8b..7a9efe2ee 100644 --- a/lib/WebGUI/Asset/Sku/Donation.pm +++ b/lib/WebGUI/Asset/Sku/Donation.pm @@ -92,6 +92,28 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm ( ) + +Returns a form to add this Sku to the cart. Used when this Sku is part of +a shelf. Overrode master class to add price form. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Donation'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'donate'}) + . WebGUI::Form::float( $session, {name => 'price', defaultValue => $self->getPrice }) + . WebGUI::Form::submit( $session, {value => $i18n->get('donate button')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getConfiguredTitle diff --git a/lib/WebGUI/Asset/Sku/EMSBadge.pm b/lib/WebGUI/Asset/Sku/EMSBadge.pm index fd45a68ca..bb196c730 100644 --- a/lib/WebGUI/Asset/Sku/EMSBadge.pm +++ b/lib/WebGUI/Asset/Sku/EMSBadge.pm @@ -165,6 +165,26 @@ sub drawRelatedBadgeGroupsField { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm + +Returns a button to take the user to the view screen. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Sku'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'view'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('see more')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getConfiguredTitle diff --git a/lib/WebGUI/Asset/Sku/EMSRibbon.pm b/lib/WebGUI/Asset/Sku/EMSRibbon.pm index 81b3fc524..ccabe2406 100644 --- a/lib/WebGUI/Asset/Sku/EMSRibbon.pm +++ b/lib/WebGUI/Asset/Sku/EMSRibbon.pm @@ -83,6 +83,26 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm + +Returns a button to take the user to the view screen. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Sku'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'view'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('see more')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getConfiguredTitle diff --git a/lib/WebGUI/Asset/Sku/EMSTicket.pm b/lib/WebGUI/Asset/Sku/EMSTicket.pm index 96fe5178b..34101f0f2 100644 --- a/lib/WebGUI/Asset/Sku/EMSTicket.pm +++ b/lib/WebGUI/Asset/Sku/EMSTicket.pm @@ -229,6 +229,25 @@ sub drawRelatedRibbonsField { #------------------------------------------------------------------- +=head2 getAddToCartForm + +Returns a button to take the user to the view screen. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Sku'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'view'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('see more')}) + . WebGUI::Form::formFooter($session) + ;} + +#------------------------------------------------------------------- + =head2 getConfiguredTitle Returns title + badgeholder name. diff --git a/lib/WebGUI/Asset/Sku/EMSToken.pm b/lib/WebGUI/Asset/Sku/EMSToken.pm index 41f9e7bcc..28bec87b4 100644 --- a/lib/WebGUI/Asset/Sku/EMSToken.pm +++ b/lib/WebGUI/Asset/Sku/EMSToken.pm @@ -76,6 +76,26 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm + +Returns a button to take the user to the view screen. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Sku'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'view'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('see more')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getConfiguredTitle diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 788003407..7f0577e88 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -240,6 +240,37 @@ sub duplicate { } +#------------------------------------------------------------------- + +=head2 getAddToCartForm ( ) + +Returns a form to add this Sku to the cart. Used when this Sku is part of +a shelf. Overrode master class to add variant dropdown. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Product'); + my %variants = (); + tie %variants, 'Tie::IxHash'; + foreach my $collateral ( @{ $self->getAllCollateral('variantsJSON')} ) { + $variants{$collateral->{variantId}} = join ", ", $collateral->{shortdesc}, sprintf('%.2f',$collateral->{price}); + } + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'buy'}) + . WebGUI::Form::selectBox( $session, { + name => 'vid', + options => \%variants, + value => [0], + }) + . WebGUI::Form::submit( $session, {value => $i18n->get('add to cart')}) + . WebGUI::Form::formFooter($session) + ; +} + #------------------------------------------------------------------- =head2 getAllCollateral ( tableName ) diff --git a/lib/WebGUI/Asset/Sku/Subscription.pm b/lib/WebGUI/Asset/Sku/Subscription.pm index 53407f836..e221561ca 100644 --- a/lib/WebGUI/Asset/Sku/Subscription.pm +++ b/lib/WebGUI/Asset/Sku/Subscription.pm @@ -269,6 +269,27 @@ sub generateSubscriptionCodeBatch { #------------------------------------------------------------------- +=head2 getAddToCartForm ( ) + +Returns a form to add this Sku to the cart. Used when this Sku is part of +a shelf. Override master class to add different form. + +=cut + +sub getAddToCartForm { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, 'Asset_Subscription'); + return + WebGUI::Form::formHeader($session, {action => $self->getUrl}) + . WebGUI::Form::hidden( $session, {name => 'func', value => 'purchaseSubscription'}) + . WebGUI::Form::submit( $session, {value => $i18n->get('purchase button')}) + . WebGUI::Form::formFooter($session) + ; +} + +#------------------------------------------------------------------- + =head2 getAdminConsoleWithSubmenu ( ) Returns an admin console with management links added to the submenu. diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index d3368e970..81cb41a82 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -308,10 +308,11 @@ sub view { 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); + 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 { diff --git a/lib/WebGUI/Help/Asset_Shelf.pm b/lib/WebGUI/Help/Asset_Shelf.pm index 09b73ba08..9e67a20db 100644 --- a/lib/WebGUI/Help/Asset_Shelf.pm +++ b/lib/WebGUI/Help/Asset_Shelf.pm @@ -21,8 +21,11 @@ our $HELP = { variables => [ { name => "shelves" , required=>1}, { name => "products" , required=>1, variables => [ + { name => "url", + description => 'product_url', }, { name => "thumbnailUrl" }, { name => "price" }, + { name => "addToCartForm" }, ], }, { name => "templateId", description=>"shelf template help" }, diff --git a/lib/WebGUI/i18n/English/Asset_Shelf.pm b/lib/WebGUI/i18n/English/Asset_Shelf.pm index 1348b0d6d..52aad39ba 100644 --- a/lib/WebGUI/i18n/English/Asset_Shelf.pm +++ b/lib/WebGUI/i18n/English/Asset_Shelf.pm @@ -33,6 +33,18 @@ our $I18N = { context => q|a template variable|, }, + 'product_url' => { + message => q|The URL to this sku.|, + lastUpdated => 0, + context => q|a template variable|, + }, + + 'addToCartForm' => { + message => q|If this product supports it, the form to add this product to the cart. It will contain a submit button and all required form elements needed to add the product to the cart.|, + lastUpdated => 0, + context => q|a template variable|, + }, + '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.|, lastUpdated => 0, diff --git a/lib/WebGUI/i18n/English/Asset_Sku.pm b/lib/WebGUI/i18n/English/Asset_Sku.pm index 342caa0ea..fdcdffead 100644 --- a/lib/WebGUI/i18n/English/Asset_Sku.pm +++ b/lib/WebGUI/i18n/English/Asset_Sku.pm @@ -93,6 +93,18 @@ our $I18N = { context => q|help for tax rate override field| }, + 'add to cart' => { + message => q|Add To Cart|, + lastUpdated => 0, + context => q|i18n label for the add to cart button|, + }, + + 'see more' => { + message => q|See more|, + lastUpdated => 0, + context => q|alternate i18n label for the add to cart button|, + }, + 'Add a Variant' => { message => q|Add a Variant|, lastUpdated => 0,