created donation asset

This commit is contained in:
JT Smith 2008-02-27 02:44:33 +00:00
parent a61ab090ee
commit 4a73cadf64
12 changed files with 353 additions and 22 deletions

View file

@ -17,7 +17,6 @@ package WebGUI::Asset::Sku;
use strict;
use Tie::IxHash;
use base 'WebGUI::Asset';
use WebGUI::Utility;
@ -68,7 +67,7 @@ sub addToCart {
my ($self, $options) = @_;
$self->applyOptions($options);
my $cart = WebGUI::Shop::Cart->create($self->session);
my $cart->addItem($self, 1);
my $cart->addItem($self);
}
#-------------------------------------------------------------------
@ -104,6 +103,13 @@ sub definition {
tie %properties, 'Tie::IxHash';
my $i18n = WebGUI::International->new($session, "Asset_Sku");
%properties = (
description => {
tab=>"properties",
fieldType=>"HTMLArea",
defaultValue=>undef,
label=>$i18n->get("description"),
hoverHelp=>$i18n->get("description help")
},
sku => {
tab=>"commerce",
fieldType=>"text",
@ -111,10 +117,17 @@ sub definition {
label=>$i18n->get("sku"),
hoverHelp=>$i18n->get("sku help")
},
displayTitle => {
tab=>"display",
fieldType=>"yesNo",
defaultValue=>1,
label=>$i18n->get("display title"),
hoverHelp=>$i18n->get("display title")
},
overrideTaxRate => {
tab=>"commerce",
fieldType=>"text",
defaultValue=>$session->id->generate,
fieldType=>"yesNo",
defaultValue=>0,
label=>$i18n->get("override tax rate"),
hoverHelp=>$i18n->get("override tax rate help")
},
@ -145,6 +158,20 @@ sub definition {
}
#-------------------------------------------------------------------
=head2 getConfiguredTitle ( )
Returns a configured title like "Red XL T-Shirt" rather than just "T-Shirt". Needs to be overridden by subclasses to support this. Defaultly just returns getTitle().
=cut
sub getConfiguredTitle {
my $self = shift;
return $self->getTitle;
}
#-------------------------------------------------------------------
=head2 getEditTabs ( )
@ -169,7 +196,10 @@ Returns a hash reference of configuration data that can return this sku to a con
sub getOptions {
my $self = shift;
return $self->{_skuOptions};
if (ref $self->{_skuOptions} eq "HASH") {
return $self->{_skuOptions};
}
return {};
}
#-------------------------------------------------------------------
@ -280,21 +310,6 @@ sub processStyle {
#-------------------------------------------------------------------
=head2 www_edit ( )
Web facing method which is the default edit page
=cut
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,WebGUI::International::get('edit asset',"Asset_NewAsset"));
}
#-------------------------------------------------------------------
=head2 www_view ( )
Renders self->view based upon current style, subject to timeouts. Returns Privilege::noAccess() if canView is False.

View file

@ -0,0 +1,137 @@
package WebGUI::Asset::Sku::Donation;
=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::Donation
=head1 DESCRIPTION
This asset makes donations possible.
=head1 SYNOPSIS
use WebGUI::Asset::Sku::Dnoation;
=head1 METHODS
These methods are available from this class:
=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_Donation");
%properties = (
templateId => {
tab => "display",
fieldType => "template",
namespace => "Donation",
defaultValue => "vrKXEtluIhbmAS9xmPukDA",
label => $i18n->get("template"),
hoverHelp => $i18n->get("template help"),
},
thankYouMessage => {
tab => "properties",
defaultValue => $i18n->get("default thank you message"),
fieldType => "HTMLArea",
label => $i18n->get("thank you message"),
hoverHelp => $i18n->get("thank you message"),
},
defaultPrice => {
tab => "commerce",
fieldType => "float",
defaultValue => 100.00,
label => $i18n->get("default price"),
hoverHelp => $i18n->get("default price help"),
},
);
push(@{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'Donation.gif',
autoGenerateForms => 1,
tableName => 'donation',
className => 'WebGUI::Asset::Sku::Donation',
properties => \%properties
});
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
sub getConfiguredTitle {
my $self = shift;
return $self->getTitle." (".$self->getOptions->{price}.")";
}
#-------------------------------------------------------------------
sub getPrice {
my $self = shift;
return $self->getOptions->{price} || $self->get("defaultPrice") || 100.00;
}
#-------------------------------------------------------------------
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;
}
#-------------------------------------------------------------------
sub view {
my ($self) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, "Asset_Donation");
my %var = (
formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl })
. WebGUI::Form::hidden( $session, { name=>"func", value=>"donate" }),
formFooter => WebGUI::Form::formFooter($session),
donateButton => WebGUI::Form::submit( $session, { value => $i18n->get("donate button") }),
priceField => WebGUI::Form::float($session, { name => "price", defaultValue => $self->getPrice }),
hasAddedToCart => $self->{_hasAddedToCart},
);
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
}
#-------------------------------------------------------------------
sub www_donate {
my $self = shift;
if ($self->canView) {
$self->{_hasAddedToCart} = 1;
$self->addToCart({price => ($self->session->form->get("price") || $self->getPrice) });
}
return $self->www_view;
}
1;

View file

@ -222,7 +222,7 @@ A hash reference that contains one of the following:
=head4 asset
This is a special meta property. It is a reference to a WebGUI::Asset::Sku subclass object. If you pass this reference it will acquire the assetId and options properties automatically.
This is a special meta property. It is a reference to a WebGUI::Asset::Sku subclass object. If you pass this reference it will acquire the assetId, configuredTitle, and options properties automatically.
=head4 assetId
@ -232,6 +232,10 @@ The assetId of the asset to add to the cart.
The configuration options for this asset.
=head4 configuredTitle
The title of this product as configured.
=head4 shippingAddressId
The unique id for a shipping address attached to this cart.
@ -244,8 +248,10 @@ sub update {
if (exists $newProperties->{asset}) {
$newProperties->{options} = $newProperties->{asset}->getOptions;
$newProperties->{assetId} = $newProperties->{asset}->getId;
$newProperties->{configuredTitle} = $newProperties->{asset}->getConfiguredTitle;
}
$properties{$id}{assetId} = $newProperties->{assetId} || $properties{$id}{assetId};
$properties{$id}{configuredTitle} = $newProperties->{configuredTitle} || $properties{$id}{configuredTitle};
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
$properties{$id}{options} = JSON::to_json($newProperties->{options});
}

View file

@ -0,0 +1,62 @@
package WebGUI::i18n::English::Asset_Donation;
use strict;
our $I18N = {
'donate button' => {
message => q|Add Donation To Cart|,
lastUpdated => 0,
context => q|the text that will appear on the donation button|
},
'default thank you message' => {
message => q|Thank you for your kind donation.|,
lastUpdated => 0,
context => q|the default message that will go in the thank you message field|
},
'thank you message' => {
message => q|Thank You Message|,
lastUpdated => 0,
context => q|the label for the field where you type in a message thanking the user for their donation|
},
'thank you message help' => {
message => q|Write a thank you message to your user for donating. Be sincere. Remember they've just put the donation in the cart at this point, they haven't checked out yet.|,
lastUpdated => 0,
context => q|help for default price field|
},
'template' => {
message => q|Template|,
lastUpdated => 0,
context => q|the label for the field where you select the template for this asset|
},
'template help' => {
message => q|Choose a template that should be used to display the donation.|,
lastUpdated => 0,
context => q|help for default price field|
},
'default price' => {
message => q|Default Price|,
lastUpdated => 0,
context => q|the label for the field that asks what the default donation amount should be.|
},
'default price help' => {
message => q|How much money are you asking for per user? Note that they can type in any amount they wish, this is just a suggestion.|,
lastUpdated => 0,
context => q|help for default price field|
},
'assetName' => {
message => q|Donation|,
lastUpdated => 0,
context => "The name of this asset. Used to contribute money."
},
};
1;

View file

@ -9,6 +9,18 @@ our $I18N = {
context => q|The name of a tab that all Sku based assets have to put their commerce related settings.|
},
'description' => {
message => q|Description|,
lastUpdated => 0,
context => q|The label for the description of the product.|
},
'description help' => {
message => q|Describe the product or service here.|,
lastUpdated => 0,
context => q|help for description field|
},
'sku' => {
message => q|SKU|,
lastUpdated => 0,