added coupons
This commit is contained in:
parent
05f14b3b76
commit
102b5fd1ae
13 changed files with 456 additions and 23 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,18 @@ sub getPrice {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isCoupon
|
||||
|
||||
Returns 1.
|
||||
|
||||
=cut
|
||||
|
||||
sub isCoupon {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 onCompletePurchase
|
||||
|
||||
Does bookkeeping on EMSRegistrationRibbon table.
|
||||
|
|
|
|||
227
lib/WebGUI/Asset/Sku/FlatDiscount.pm
Normal file
227
lib/WebGUI/Asset/Sku/FlatDiscount.pm
Normal file
|
|
@ -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;
|
||||
|
|
@ -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 ( )
|
||||
|
|
|
|||
34
lib/WebGUI/Help/Asset_FlatDiscount.pm
Normal file
34
lib/WebGUI/Help/Asset_FlatDiscount.pm
Normal file
|
|
@ -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;
|
||||
29
lib/WebGUI/Help/Asset_Sku.pm
Normal file
29
lib/WebGUI/Help/Asset_Sku.pm
Normal file
|
|
@ -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;
|
||||
98
lib/WebGUI/i18n/English/Asset_FlatDiscount.pm
Normal file
98
lib/WebGUI/i18n/English/Asset_FlatDiscount.pm
Normal file
|
|
@ -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;
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue