diff --git a/docs/upgrades/packages-7.5.11/root_import_flat-discount-default.wgpkg b/docs/upgrades/packages-7.5.11/root_import_flat-discount-default.wgpkg new file mode 100644 index 000000000..521ff7856 Binary files /dev/null and b/docs/upgrades/packages-7.5.11/root_import_flat-discount-default.wgpkg differ diff --git a/docs/upgrades/packages-7.5.11/shopping-cart-collateral-items-1.wgpkg b/docs/upgrades/packages-7.5.11/shopping-cart-collateral-items-1.wgpkg index d307e6ac4..25862fefa 100644 Binary files a/docs/upgrades/packages-7.5.11/shopping-cart-collateral-items-1.wgpkg and b/docs/upgrades/packages-7.5.11/shopping-cart-collateral-items-1.wgpkg differ diff --git a/docs/upgrades/upgrade_7.5.10-7.5.11.pl b/docs/upgrades/upgrade_7.5.10-7.5.11.pl index ef423d93e..88835341a 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -46,11 +46,32 @@ mergeProductsWithCommerce($session); addCaptchaToDataForm( $session ); addArchiveEnabledToCollaboration( $session ); addShelf( $session ); +addCoupon( $session ); addVendors($session); modifyThingyPossibleValues( $session ); finish($session); # this line required +#---------------------------------------------------------------------------- +sub addCoupon { + my $session = shift; + print "\tAdding Coupons" unless $quiet; + + $session->db->write(q{ + create table FlatDiscount ( + assetId varchar(22) binary not null, + revisionDate bigint, + templateId varchar(22) binary not null default '63ix2-hU0FchXGIWkG3tow', + mustSpend float not null default 0, + percentageDiscount int(3) not null default 0, + priceDiscount float not null default 0, + primary key (assetId,revisionDate) + ) + }); + $session->config->addToArray("assets","WebGUI::Asset::Sku::FlatDiscount"); + print "DONE!\n" unless $quiet; +} + #---------------------------------------------------------------------------- sub addVendors { my $session = shift; @@ -99,6 +120,7 @@ sub addShelf { $session->config->addToArray("assetContainers","WebGUI::Asset::Wobject::Shelf"); print "DONE!\n" unless $quiet; } + #---------------------------------------------------------------------------- # Add the useCaptcha field to DataForm assets sub addCaptchaToDataForm { @@ -544,7 +566,7 @@ EOSQL #------------------------------------------------- sub addPaymentDrivers { my $session = shift; - print "\tSet up the default payment dirvers.\n" unless ($quiet); + print "\tSet up the default payment drivers.\n" unless ($quiet); # and here's our code $session->config->delete('paymentPlugins'); $session->config->addToArray('paymentDrivers', 'WebGUI::Shop::PayDriver::Cash'); diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 205bdf2c1..7794579f4 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -210,6 +210,7 @@ "assets" : [ "WebGUI::Asset::Sku::Donation", + "WebGUI::Asset::Sku::FlatDiscount", "WebGUI::Asset::Snippet", "WebGUI::Asset::Redirect", "WebGUI::Asset::FilePile", diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index bb6d153e0..70fd53ecd 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2473,7 +2473,7 @@ sub www_edit { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->locked() unless $self->canEditIfLocked; - return $self->getAdminConsole->render($self->getEditForm->print); + return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 188bcd690..4932697a5 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -121,7 +121,7 @@ sub definition { fieldType => "yesNo", defaultValue => 1, label => $i18n->get("display title"), - hoverHelp => $i18n->get("display title") + hoverHelp => $i18n->get("display title help") }, overrideTaxRate => { tab => "shop", @@ -318,6 +318,18 @@ sub indexContent { return $indexer; } +#------------------------------------------------------------------- + +=head2 isCoupon + +Returns a boolean indicating whether this sku represents a coupon. Some coupons may not allow themselves to be used in conjunction with other coupons. Returns 0 by default. + +=cut + +sub isCoupon { + return 0; +} + #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Sku/EMSRibbon.pm b/lib/WebGUI/Asset/Sku/EMSRibbon.pm index f7d180db5..bb4d131a3 100644 --- a/lib/WebGUI/Asset/Sku/EMSRibbon.pm +++ b/lib/WebGUI/Asset/Sku/EMSRibbon.pm @@ -124,6 +124,18 @@ sub getPrice { #------------------------------------------------------------------- +=head2 isCoupon + +Returns 1. + +=cut + +sub isCoupon { + return 1; +} + +#------------------------------------------------------------------- + =head2 onCompletePurchase Does bookkeeping on EMSRegistrationRibbon table. diff --git a/lib/WebGUI/Asset/Sku/FlatDiscount.pm b/lib/WebGUI/Asset/Sku/FlatDiscount.pm new file mode 100644 index 000000000..c87a5dffd --- /dev/null +++ b/lib/WebGUI/Asset/Sku/FlatDiscount.pm @@ -0,0 +1,227 @@ +package WebGUI::Asset::Sku::FlatDiscount; + +=head1 LEGAL + + ------------------------------------------------------------------- + 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use Tie::IxHash; +use base 'WebGUI::Asset::Sku'; +use WebGUI::Asset::Template; +use WebGUI::Form; + + +=head1 NAME + +Package WebGUI::Asset::Sku::FlatDiscount + +=head1 DESCRIPTION + +This asset is a basic coupon. + +=head1 SYNOPSIS + +use WebGUI::Asset::Sku::FlatDiscount; + +=head1 METHODS + +These methods are available from this class: + +=cut + + + + +#------------------------------------------------------------------- + +=head2 addToCart ( ) + +Checks to make sure there isn't already a coupon of this type in the cart. + +=cut + +sub addToCart { + my ($self, $options) = @_; + my $found = 0; + foreach my $item (@{$self->getCart->getItems()}) { + $found =1 if (ref($item->getSku) eq ref($self)); + } + unless ($found) { + $self->SUPER::addToCart($options); + } +} + +#------------------------------------------------------------------- + +=head2 definition + +Adds templateId, thankYouMessage, and defaultPrice fields. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift; + my %properties; + tie %properties, 'Tie::IxHash'; + my $i18n = WebGUI::International->new($session, "Asset_FlatDiscount"); + %properties = ( + templateId => { + tab => "display", + fieldType => "template", + namespace => "FlatDiscount", + defaultValue => "63ix2-hU0FchXGIWkG3tow", + label => $i18n->get("template"), + hoverHelp => $i18n->get("template help"), + }, + mustSpend => { + tab => "shop", + fieldType => "float", + defaultValue => 0.00, + label => $i18n->get("must spend"), + hoverHelp => $i18n->get("must spend help"), + }, + percentageDiscount => { + tab => "shop", + fieldType => "integer", + defaultValue => 0, + label => $i18n->get("percentage discount"), + hoverHelp => $i18n->get("percentage discount help"), + }, + priceDiscount => { + tab => "shop", + fieldType => "float", + defaultValue => 0.00, + label => $i18n->get("price discount"), + hoverHelp => $i18n->get("price discount help"), + }, + ); + push(@{$definition}, { + assetName => $i18n->get('assetName'), + icon => 'FlatDiscount.gif', + autoGenerateForms => 1, + tableName => 'FlatDiscount', + className => 'WebGUI::Asset::Sku::FlatDiscount', + properties => \%properties + }); + return $class->SUPER::definition($session, $definition); +} + + +#------------------------------------------------------------------- + +=head2 getMaxAllowedInCart ( ) + +Returns 1. + +=cut + +sub getMaxAllowedInCart { + return 1; +} + + +#------------------------------------------------------------------- + +=head2 getPrice + +Returns either 0 or a percentage off the price or a flat amount off the price depending upon what's in the cart. +=cut + +sub getPrice { + my $self = shift; + my $subtotal = 0; + foreach my $item (@{$self->getCart->getItems()}) { + next if ($item->get('assetId') eq $self->getId); # avoid an infinite loop + $subtotal += $item->getSku->getPrice * $item->get('quantity'); + } + if ($subtotal >= $self->get('mustSpend')) { + if ($self->get('percentageDiscount') > 0) { + return $subtotal * $self->get('percentageDiscount') / -100; + } + else { + return $self->get('priceDiscount'); + } + } + return 0; +} + +#------------------------------------------------------------------- + +=head2 isCoupon + +Returns 1. + +=cut + +sub isCoupon { + return 1; +} + + +#------------------------------------------------------------------- + +=head2 prepareView + +Prepares the template. + +=cut + +sub prepareView { + my $self = shift; + $self->SUPER::prepareView(); + my $templateId = $self->get("templateId"); + my $template = WebGUI::Asset::Template->new($self->session, $templateId); + $template->prepare; + $self->{_viewTemplate} = $template; +} + +#------------------------------------------------------------------- + +=head2 view + +Displays the FlatDiscount form. + +=cut + +sub view { + my ($self) = @_; + my $session = $self->session; + my $i18n = WebGUI::International->new($session, "Asset_FlatDiscount"); + my %var = ( + formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl }) + . WebGUI::Form::hidden( $session, { name=>"func", value=>"addToCart" }), + formFooter => WebGUI::Form::formFooter($session), + addToCartButton => WebGUI::Form::submit( $session, { value => $i18n->get("add to cart") }), + ); + return $self->processTemplate(\%var,undef,$self->{_viewTemplate}); +} + +#------------------------------------------------------------------- + +=head2 wwww_addToCart + +Accepts the information from the form and adds it to the cart. + +=cut + +sub www_addToCart { + my $self = shift; + if ($self->canView) { + $self->addToCart(); + } + return $self->www_view; +} + +1; diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 8bfe7bd0f..470224c7e 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -489,26 +489,6 @@ sub setCollateral { } -#------------------------------------------------------------------- - -=head2 www_edit ( ) - -Returns an edit form for this asset. - -=cut - -sub www_edit { - my $self = shift; - return $self->session->privilege->insufficient() unless $self->canEdit; - return $self->session->privilege->locked() unless $self->canEditIfLocked; - my ($tag) = ($self->get("className") =~ /::(\w+)$/); - my $tag2 = $tag; - $tag =~ s/([a-z])([A-Z])/$1 $2/g; #Separate studly caps - $tag =~ s/([A-Z]+(?![a-z]))/$1 /g; #Separate acronyms - return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel); -} - - #------------------------------------------------------------------- =head2 www_view ( ) diff --git a/lib/WebGUI/Help/Asset_FlatDiscount.pm b/lib/WebGUI/Help/Asset_FlatDiscount.pm new file mode 100644 index 000000000..47bf45b8c --- /dev/null +++ b/lib/WebGUI/Help/Asset_FlatDiscount.pm @@ -0,0 +1,34 @@ +package WebGUI::Help::Asset_FlatDiscount; + +use strict; + + +our $HELP = { + 'template' => { + + title => 'flat discount coupon template', + body => 'flat discount coupon template help', + isa => [ + { + tag => 'sku properties', + namespace => 'Asset_Sku', + }, + ], + fields => [ + ], + variables => [ + { name => "formHeader" , required=>1}, + { name => "formFooter" , required=>1 }, + { name => "addToCartButton" , required=>1 }, + { name => "mustSpend", description=>"must spend help" }, + { name => "percentageDiscount", description=>"percentage discount help" }, + { name => "priceDiscount", description=>"price discount help" }, + { name => "templateId", description=>"template help" }, + ], + related => [ + ], + }, + +}; + +1; diff --git a/lib/WebGUI/Help/Asset_Sku.pm b/lib/WebGUI/Help/Asset_Sku.pm new file mode 100644 index 000000000..391dbfd2f --- /dev/null +++ b/lib/WebGUI/Help/Asset_Sku.pm @@ -0,0 +1,29 @@ +package WebGUI::Help::Asset_Sku; +use strict; + +our $HELP = { + + 'sku properties' => { + private => 1, + title => 'sku properties title', + body => '', + isa => [ + { tag => 'asset template asset variables', + namespace => 'Asset' + }, + ], + fields => [], + variables => [ + { 'name' => 'sku', description=>'sku help'}, + { 'name' => 'description', description=>'description help' }, + { 'name' => 'displayTitle', description=>'display title help' }, + { 'name' => 'overrideTaxRate', description=>'override tax rate help' }, + { 'name' => 'taxRateOverride', description=>'tax rate override help' }, + { 'name' => 'vendorId', description=>'vendor help' }, + ], + related => [] + }, + +}; + +1; diff --git a/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm b/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm new file mode 100644 index 000000000..6dfd423e7 --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm @@ -0,0 +1,98 @@ +package WebGUI::i18n::English::Asset_FlatDiscount; + +use strict; + +our $I18N = { + 'add to cart' => { + message => q|Add To Cart|, + lastUpdated => 0, + context => q|a button label| + }, + + 'template' => { + message => q|Template|, + lastUpdated => 0, + context => q|a property label| + }, + + 'template help' => { + message => q|Choose the template you wish to use to display this coupon.|, + lastUpdated => 0, + context => q|help for a property label| + }, + + 'must spend' => { + message => q|Must Spend|, + lastUpdated => 0, + context => q|a property label| + }, + + 'must spend help' => { + message => q|How much must a visitor spend in this transaction for the discount to be applied?|, + lastUpdated => 0, + context => q|help for a property label| + }, + + 'percentage discount' => { + message => q|Percentage Discount|, + lastUpdated => 0, + context => q|a property label| + }, + + 'percentage discount help' => { + message => q|What percentage of the price will be subtracted by this coupon?|, + lastUpdated => 0, + context => q|help for a property label| + }, + + 'price discount' => { + message => q|Price Discount|, + lastUpdated => 0, + context => q|a property label| + }, + + 'price discount help' => { + message => q|What flat amount should be subtracted by this coupon?|, + lastUpdated => 0, + context => q|help for a property label| + }, + + 'flat discount coupon template' => { + message => q|Flat Discount Coupon Template|, + lastUpdated => 0, + context => q|a help label| + }, + + 'flat discount coupon template help' => { + message => q|The following template variables are available for this asset.|, + lastUpdated => 0, + context => q|help for a help label| + }, + + 'assetName' => { + message => q|Flat Discount Coupon|, + lastUpdated => 0, + context => q|The name of this asset.| + }, + + 'formHeader' => { + message => q|The top of the form.|, + lastUpdated => 0, + context => q|template variable description| + }, + + 'formFooter' => { + message => q|The bottom of the form.|, + lastUpdated => 0, + context => q|template variable description| + }, + + 'addToCartButton' => { + message => q|A submit button with 'add to cart' written on it.|, + lastUpdated => 0, + context => q|template variable description| + }, + +}; + +1; diff --git a/lib/WebGUI/i18n/English/Asset_Sku.pm b/lib/WebGUI/i18n/English/Asset_Sku.pm index 4f163939b..999d41d61 100644 --- a/lib/WebGUI/i18n/English/Asset_Sku.pm +++ b/lib/WebGUI/i18n/English/Asset_Sku.pm @@ -3,12 +3,30 @@ package WebGUI::i18n::English::Asset_Sku; use strict; our $I18N = { + 'sku properties title' => { + message => q|Sku Properties|, + lastUpdated => 0, + context => q|a help label| + }, + 'shop' => { message => q|Shop|, lastUpdated => 0, context => q|The name of a tab that all Sku based assets have to put their commerce related settings.| }, + 'display title' => { + message => q|Display Title?|, + lastUpdated => 0, + context => q|propertly label| + }, + + 'display title help' => { + message => q|Indicate whether the title should be displayed or not.|, + lastUpdated => 0, + context => q|property label help| + }, + 'description' => { message => q|Description|, lastUpdated => 0,