More EMS code

Lots of bug fixes in commerce
Temp bug fix for stow->get, better fix needed
This commit is contained in:
Roy Johnson 2006-03-19 16:11:21 +00:00
parent abfa6ed1ac
commit 5bdaa49f95
6 changed files with 178 additions and 61 deletions

View file

@ -381,6 +381,7 @@ sub updateTemplates {
sub addEMSTemplates { sub addEMSTemplates {
print "\tAdding Event Management System Templates.\n" unless ($quiet); print "\tAdding Event Management System Templates.\n" unless ($quiet);
## Display Template ##
my $template = <<EOT1; my $template = <<EOT1;
<a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a> <a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a>
@ -399,12 +400,68 @@ my $template = <<EOT1;
<tmpl_var paginateBar> <tmpl_var paginateBar>
EOT1 EOT1
## Event Template ##
my $template2 = <<EOT2; my $template2 = <<EOT2;
<h1><tmpl_var title></h1><br> <h1><tmpl_var title></h1><br>
<tmpl_var description>&nbsp;<tmpl_var price><br> <tmpl_var description>&nbsp;<tmpl_var price><br>
<a href="<tmpl_var purchase.url>"><tmpl_var purchase.label></a> <a href="<tmpl_var purchase.url>"><tmpl_var purchase.label></a>
EOT2 EOT2
## Checkout Template ##
my $template3 = <<EOT3;
<tmpl_var form.header>
<table width='100%'>
<tr><td><tmpl_var message></td></tr>
<tmpl_if chooseSubevents>
<tmpl_loop subevents_loop>
<tr>
<td><tmpl_var form.checkBox></td>
<td><tmpl_var title></td>
<td><tmpl_var description></td>
<td><tmpl_var price></td>
</tr>
</tmpl_loop>
</tmpl_if>
<tmpl_if resolveConflicts>
<tmpl_loop conflict_loop>
<tr>
<td><tmpl_var form.deleteControl></td>
<td><tmpl_var title></td>
<td><tmpl_var description></td>
<td><tmpl_var price></td>
</tr>
</tmpl_loop>
</tmpl_if>
<tr><td><tmpl_var form.submit></td></tr>
</table>
<tmpl_var form.footer>
<tmpl_if registration>
<tmpl_var form.header>
<table>
<tr><td><tmpl_var form.firstName.label></td><td><tmpl_var form.firstName></td></tr>
<tr><td><tmpl_var form.lastName.label></td><td><tmpl_var form.lastName></td></tr>
<tr><td><tmpl_var form.address.label></td><td><tmpl_var form.address></td></tr>
<tr><td><tmpl_var form.city.label></td><td><tmpl_var form.city></td></tr>
<tr><td><tmpl_var form.state.label></td><td><tmpl_var form.state></td></tr>
<tr><td><tmpl_var form.zipcode.label></td><td><tmpl_var form.zipcode></td></tr>
<tr><td><tmpl_var form.firstName.label></td><td><tmpl_var form.firstName></td></tr>
<tr><td><tmpl_var form.country.label></td><td><tmpl_var form.country></td></tr>
<tr><td><tmpl_var form.phoneNumber.label></td><td><tmpl_var form.phoneNumber></td></tr>
<tr><td><tmpl_var form.email.label></td><td><tmpl_var form.email></td></tr>
<tr><td rowspan='2' align='center'><tmpl_var form.submit></td></tr>
</table>
<tmpl_var form.footer>
</tmpl_if>
EOT3
## End Templates
my $in = WebGUI::Asset->getImportNode($session); my $in = WebGUI::Asset->getImportNode($session);
$in->addChild({ $in->addChild({
className=>'WebGUI::Asset::Template', className=>'WebGUI::Asset::Template',
@ -419,6 +476,13 @@ EOT2
namespace=>'EventManagementSystem_product', namespace=>'EventManagementSystem_product',
}, "EventManagerTmpl000002" }, "EventManagerTmpl000002"
); );
$in->addChild({
className=>'WebGUI::Asset::Template',
template=>$template3,
namespace=>'EventManagementSystem_checkout',
}, "EventManagerTmpl000003"
);
} }
#------------------------------------------------- #-------------------------------------------------
@ -432,6 +496,7 @@ create table EventManagementSystem (
assetId varchar(22) not null, assetId varchar(22) not null,
revisionDate bigint(20) not null, revisionDate bigint(20) not null,
displayTemplateId varchar(22), displayTemplateId varchar(22),
checkoutTemplateId varchar(22),
paginateAfter int(11) default 10, paginateAfter int(11) default 10,
groupToAddEvents varchar(22), groupToAddEvents varchar(22),
groupToApproveEvents varchar(22), groupToApproveEvents varchar(22),

View file

@ -123,6 +123,14 @@ sub definition {
hoverHelp=>$i18n->get('display template description'), hoverHelp=>$i18n->get('display template description'),
label=>$i18n->get('display template') label=>$i18n->get('display template')
}, },
checkoutTemplateId =>{
fieldType=>"template",
defaultValue=>'EventManagerTmpl000003',
tab=>"display",
namespace=>"EventManagementSystem_checkout",
hoverHelp=>'',
label=>"Checkout Template"
},
paginateAfter =>{ paginateAfter =>{
fieldType=>"integer", fieldType=>"integer",
defaultValue=>10, defaultValue=>10,
@ -421,6 +429,38 @@ sub findSubEvents {
return \@subEvents; return \@subEvents;
} }
#------------------------------------------------------------------
sub getRegistrationInfo {
my $self = shift;
my %var;
$var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
.WebGUI::Form::hidden($self->session,{name=>"func",value=>"www_saveRegistration"});
$var{'form.footer'} = WebGUI::Form::formFooter($self->session);
$var{'form.submit'} = WebGUI::Form::submit($self->session);
$var{'form.firstName.label'} = "First Name";
$var{'form.lastName.label'} = "Last Name";
$var{'form.address.label'} = "Address";
$var{'form.city.label'} = "City";
$var{'form.state.label'} = "State";
$var{'form.zipCode.label'} = "Zip Code";
$var{'form.country.label'} = "Country";
$var{'form.phoneNumber.label'} = "Phone Number";
$var{'form.email.label'} = "Email Address";
$var{'form.firstName'} = WebGUI::Form::Text($self->session,{});
$var{'form.lastName'} = WebGUI::Form::Text($self->session,{});
$var{'form.address'} = WebGUI::Form::Text($self->session,{});
$var{'form.city'} = WebGUI::Form::Text($self->session,{});
$var{'form.state'} = WebGUI::Form::Text($self->session,{});
$var{'form.zipCode'} = WebGUI::Form::Text($self->session,{});
$var{'form.country'} = WebGUI::Form::SelectList($self->session,{});
$var{'form.phoneNumber'} = WebGUI::Form::Phone($self->session,{});
$var{'form.email'} = WebGUI::Form::Email($self->session,{});
$var{'registration'} = 1;
return \%var;
}
#------------------------------------------------------------------ #------------------------------------------------------------------
sub getSubEventPrerequisites { sub getSubEventPrerequisites {
my $self = shift; my $self = shift;
@ -504,36 +544,40 @@ sub getSubEventForm {
my $pids = shift; my $pids = shift;
my $subEvents = $self->getSubEvents($pids); my $subEvents = $self->getSubEvents($pids);
my @usedEventIds; my @usedEventIds;
my %var;
#
# TODO : This will all be template variable assignments
# and need to make checkbox for each subevent so it can be selected
# and added to the cart
#
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
my $i18n = WebGUI::International->new($self->session, 'Asset_EventManagementSystem'); my $i18n = WebGUI::International->new($self->session, 'Asset_EventManagementSystem');
$f->hidden(-name=>"func",-value=>"addToCart"); $var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
$f->hidden(-name=>"method",-value=>"addSubEvents"); .WebGUI::Form::hidden($self->session,{name=>"func",value=>"addToCart"})
$f->readOnly(-value=>$i18n->get('allowed sub events')); .WebGUI::Form::hidden($self->session,{name=>"method",value=>"addSubEvents"}
);
$var{'form.footer'} = WebGUI::Form::formFooter($self->session);
$var{'form.submit'} = WebGUI::Form::Submit($self->session);
$var{'message'} = $i18n->get('allowed sub events');
my @subEventLoop;
foreach my $subEvent (@$subEvents) { foreach my $subEvent (@$subEvents) {
while (my $eventData = $subEvent->hashRef) { while (my $eventData = $subEvent->hashRef) {
# Track used event ids so we can prevent listing a subevent more than once. # Track used event ids so we can prevent listing a subevent more than once.
next if (WebGUI::Utility::isIn($eventData->{productId}, @usedEventIds)); next if (WebGUI::Utility::isIn($eventData->{productId}, @usedEventIds));
push (@usedEventIds, $eventData->{productId}); push (@usedEventIds, $eventData->{productId});
$f->checkbox(-value=>$eventData->{productId}, push(@subEventLoop, {
-label=>$eventData->{title}. 'form.checkBox' => WebGUI::Form::checkbox($self->session, {
"&nbsp;".$eventData->{description}."&nbsp;".$eventData->{price}."<br />", value => $eventData->{productId},
-name=>"subEventPID" name => "subEventPID"}),
); 'title' => $eventData->{title},
'description' => $eventData->{description},
'price' => $eventData->{price}
});
} }
} }
$f->submit; $var{'subevents_loop'} = \@subEventLoop;
$var{'chooseSubevents'} = 1;
my $output = $f->print if (scalar (@$subEvents) > 0); my $output = \%var if (scalar (@$subEvents) > 0);
return $output; return $output;
} }
@ -543,10 +587,9 @@ sub resolveConflictForm {
my $self = shift; my $self = shift;
my $event1 = shift; my $event1 = shift;
my $event2 = shift; my $event2 = shift;
my $output;
my $extrasURL = $self->session->config->get("extrasURL"); my $extrasURL = $self->session->config->get("extrasURL");
my $deleteIcon = $extrasURL."/toolbar/bullet/delete.gif"; my $deleteIcon = $extrasURL."/toolbar/bullet/delete.gif";
my %var;
my $sth = $self->session->db->read(" my $sth = $self->session->db->read("
select productId, title, price, description select productId, title, price, description
from products where productId in (".$self->session->db->quote($event1)."," from products where productId in (".$self->session->db->quote($event1).","
@ -554,28 +597,30 @@ sub resolveConflictForm {
); );
my $i18n = WebGUI::International->new($self->session, 'Asset_EventManagementSystem'); my $i18n = WebGUI::International->new($self->session, 'Asset_EventManagementSystem');
$output .= sprintf "<table><tr><td>%s</td></tr>", $i18n->get('scheduling conflict message');
$output .= "<form action='".$self->getUrl."' method='post'"; $var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
$output .= "<input type='hidden' name='func' value='deleteCartItem' />"; .WebGUI::Form::hidden($self->session,{name=>"func",value=>"deleteCartItem"})
$output .= "<input type='hidden' name='event1' value='$event1' />"; .WebGUI::Form::hidden($self->session,{name=>"event1",value=>"$event1"})
$output .= "<input type='hidden' name='event2' value='$event2' />"; .WebGUI::Form::hidden($self->session,{name=>"event2",value=>"$event2"}
);
$var{'form.footer'} = WebGUI::Form::formFooter($self->session);
$var{'form.submit'} = WebGUI::Form::Submit($self->session);
$var{'message'} = $i18n->get('allowed sub events');
my @loop;
while (my $data = $sth->hashRef) { while (my $data = $sth->hashRef) {
$output .= "<tr><td>"; push(@loop, {
$output .= "<input type='image' src='$deleteIcon' name='productToRemove' value='$data->{productId}' style='border: 0px;'/>"; 'form.deleteControl' => "<input type='image' src='$deleteIcon' name='productToRemove' value='".$data->{productId}."' style='border: 0px;'/>",
$output .= "</td><td>"; 'title' => $data->{title},
$output .= $data->{title}."&nbsp;".$data->{description}."&nbsp;".$data->{price}; 'description' => $data->{description},
$output .= "</td></tr>"; 'price' => $data->{price}
});
} }
$output .= "</form>"; $var{'conflict_loop'} = \@loop;
$output .= "</table>"; $var{'resolveConflicts'} = 1;
$output .= sprintf "<a href=''>%s</a>", $i18n->get('scheduling conflict continue');
# return \%var;
# This will all be templated
#
return $output;
} }
#------------------------------------------------------------------ #------------------------------------------------------------------
@ -641,14 +686,12 @@ sub www_addToCart {
$pid = shift; $pid = shift;
# Check if conflicts were found that the user needs to fix # Check if conflicts were found that the user needs to fix
$output = join '', @{ $conflicts } if defined $conflicts; $output = $conflicts->[0] if defined $conflicts;
unless ($output) { #Skip this if we have errors unless ($output) { #Skip this if we have errors
if ($self->session->form->get("method") eq "addSubEvents") { # List of ids from subevent form if ($self->session->form->get("method") eq "addSubEvents") { # List of ids from subevent form
@pids = $self->session->form->process("subEventPID", "checkList"); @pids = $self->session->form->process("subEventPID", "checkList");
#Hack until the form->process method returns elements like it should
#@pids = split("\n", $pids[0]);
} }
else { # A single id, i.e., a master event else { # A single id, i.e., a master event
push(@pids, $self->session->form->get("pid") || $pid); push(@pids, $self->session->form->get("pid") || $pid);
@ -664,11 +707,10 @@ sub www_addToCart {
$errors = $self->checkConflicts; $errors = $self->checkConflicts;
if (scalar(@$errors) > 0) { return $self->error($errors, "www_addToCart"); } if (scalar(@$errors) > 0) { return $self->error($errors, "www_addToCart"); }
# $output = $self->getRegistrationInfo unless ($output);
# Also need to make all of this output use a template
} }
#return $self->session->style->process($self->processTemplate($f->print,$self->getValue("gradebookTemplateId")),$self->getValue("styleTemplateId")); return $self->session->style->process($self->processTemplate($output,$self->getValue("checkoutTemplateId")),$self->getValue("styleTemplateId"));
return $self->session->style->process($output,$self->getValue("styleTemplateId"));
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -187,7 +187,9 @@ Returns a reference to an array of all enabled instantiated payment plugins.
=cut =cut
sub getEnabledPlugins { sub getEnabledPlugins {
my ($session) = @_; #my ($session) = @_;
my $class = shift;
my $session = shift;
my (@enabledPlugins, $plugin, @plugins); my (@enabledPlugins, $plugin, @plugins);
@enabledPlugins = $session->db->buildArray("select namespace from commerceSettings where type='Payment' and fieldName='enabled' and fieldValue='1'"); @enabledPlugins = $session->db->buildArray("select namespace from commerceSettings where type='Payment' and fieldName='enabled' and fieldValue='1'");

View file

@ -148,7 +148,8 @@ Returns a reference to an array of all enabled instantiated payment plugins.
=cut =cut
sub getEnabledPlugins { sub getEnabledPlugins {
my ($session) = @_; my $class = shift;
my $session = shift;
my (@enabledPlugins, $plugin, @plugins); my (@enabledPlugins, $plugin, @plugins);
@enabledPlugins = $session->db->buildArray("select namespace from commerceSettings where type='Shipping' and fieldName='enabled' and fieldValue='1'"); @enabledPlugins = $session->db->buildArray("select namespace from commerceSettings where type='Shipping' and fieldName='enabled' and fieldValue='1'");

View file

@ -719,7 +719,7 @@ sub www_editCommerceSettingsSave {
# Store the plugin configuration data in a special table for security and the general settings in the # Store the plugin configuration data in a special table for security and the general settings in the
# normal settings table for easy access. # normal settings table for easy access.
if (/~([^~]*)~([^~]*)~([^~]*)/) { if (/~([^~]*)~([^~]*)~([^~]*)/) {
WebGUI::Commerce::setCommerceSetting({ WebGUI::Commerce::setCommerceSetting($session,{
type => $1, type => $1,
namespace => $2, namespace => $2,
fieldName => $3, fieldName => $3,
@ -915,7 +915,8 @@ sub www_selectPaymentGateway {
}); });
} }
} elsif (scalar(@$plugins) == 1) { } elsif (scalar(@$plugins) == 1) {
$session->form->process("paymentGateway") = $plugins->[0]->namespace; #$session->form->process("paymentGateway") = $plugins->[0]->namespace;
$session->stow->set("paymentGateway", $plugins->[0]->namespace);
return WebGUI::Operation::execute($session,'selectPaymentGatewaySave'); return WebGUI::Operation::execute($session,'selectPaymentGatewaySave');
} }
@ -944,8 +945,10 @@ Returns the user to the operation C<checkout> when it is done.
sub www_selectPaymentGatewaySave { sub www_selectPaymentGatewaySave {
my $session = shift; my $session = shift;
if (WebGUI::Commerce::Payment->load($session, $session->form->process("paymentGateway"))->enabled) { # shifting stow first because it's only set when one payment gateway is defined
$session->scratch->set('paymentGateway', $session->form->process("paymentGateway")); my $paymentGateway = $session->stow->get("paymentGateway") || $session->form->process("paymentGateway");
if (WebGUI::Commerce::Payment->load($session, $paymentGateway)->enabled) {
$session->scratch->set('paymentGateway', $paymentGateway);
} else { } else {
$session->scratch->set('paymentGateway', '-delete-'); $session->scratch->set('paymentGateway', '-delete-');
} }
@ -980,7 +983,8 @@ sub www_selectShippingMethod {
}); });
} }
} elsif (scalar(@$plugins) == 1) { } elsif (scalar(@$plugins) == 1) {
$session->form->process("shippingMethod") = $plugins->[0]->namespace; #$session->form->process("shippingMethod") = $plugins->[0]->namespace;
$session->stow->set('shippingMethod', $plugins->[0]->namespace);
return WebGUI::Operation::execute($session,"selectShippingMethodSave"); return WebGUI::Operation::execute($session,"selectShippingMethodSave");
} }
@ -988,9 +992,9 @@ sub www_selectShippingMethod {
$var{message} = $i18n->get('select shipping method'); $var{message} = $i18n->get('select shipping method');
$var{pluginsAvailable} = @$plugins; $var{pluginsAvailable} = @$plugins;
$var{noPluginsMessage} = $i18n->get('no shipping methods available'); $var{noPluginsMessage} = $i18n->get('no shipping methods available');
$var{formHeader} = WebGUI::Form::formHeader.WebGUI::Form::hidden($session,{name=>'op', value=>'selectShippingMethodSave'}); $var{formHeader} = WebGUI::Form::formHeader($session).WebGUI::Form::hidden($session,{name=>'op', value=>'selectShippingMethodSave'});
$var{formSubmit} = WebGUI::Form::submit($session,{value=>$i18n->get('shipping select button')}); $var{formSubmit} = WebGUI::Form::submit($session,{value=>$i18n->get('shipping select button')});
$var{formFooter} = WebGUI::Form::formFooter; $var{formFooter} = WebGUI::Form::formFooter($session);
return $session->style->userStyle(WebGUI::Asset::Template->new($session,$session->setting->get("commerceSelectShippingMethodTemplateId"))->process(\%var)); return $session->style->userStyle(WebGUI::Asset::Template->new($session,$session->setting->get("commerceSelectShippingMethodTemplateId"))->process(\%var));
} }
@ -1012,7 +1016,9 @@ Returns the user to the operation C<checkout> when it is done.
sub www_selectShippingMethodSave { sub www_selectShippingMethodSave {
my $session = shift; my $session = shift;
my $shipping = WebGUI::Commerce::Shipping->load($session, $session->form->process("shippingMethod")); # Shifting stow first b/c it's only set when one shipping plug-in exists
my $shippingMethod = $session->stow->get('shippingMethod') || $session->form->process("shippingMethod");
my $shipping = WebGUI::Commerce::Shipping->load($session, $shippingMethod);
$shipping->processOptionsForm; $shipping->processOptionsForm;
return WebGUI::Operation::execute($session,'selectShipping') unless ($shipping->optionsOk); return WebGUI::Operation::execute($session,'selectShipping') unless ($shipping->optionsOk);

View file

@ -106,7 +106,8 @@ The name of the variable.
sub get { sub get {
my $self = shift; my $self = shift;
my $var = shift; my $var = shift;
return undef if $self->session->config->get("disableCache"); # wtf!? This line is breaking stuff, what does stow have to do with caching?
#return undef if $self->session->config->get("disableCache");
return $self->{_data}{$var}; return $self->{_data}{$var};
} }