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 {
print "\tAdding Event Management System Templates.\n" unless ($quiet);
## Display Template ##
my $template = <<EOT1;
<a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a>
@ -399,12 +400,68 @@ my $template = <<EOT1;
<tmpl_var paginateBar>
EOT1
## Event Template ##
my $template2 = <<EOT2;
<h1><tmpl_var title></h1><br>
<tmpl_var description>&nbsp;<tmpl_var price><br>
<a href="<tmpl_var purchase.url>"><tmpl_var purchase.label></a>
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);
$in->addChild({
className=>'WebGUI::Asset::Template',
@ -419,6 +476,13 @@ EOT2
namespace=>'EventManagementSystem_product',
}, "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,
revisionDate bigint(20) not null,
displayTemplateId varchar(22),
checkoutTemplateId varchar(22),
paginateAfter int(11) default 10,
groupToAddEvents varchar(22),
groupToApproveEvents varchar(22),

View file

@ -123,6 +123,14 @@ sub definition {
hoverHelp=>$i18n->get('display template description'),
label=>$i18n->get('display template')
},
checkoutTemplateId =>{
fieldType=>"template",
defaultValue=>'EventManagerTmpl000003',
tab=>"display",
namespace=>"EventManagementSystem_checkout",
hoverHelp=>'',
label=>"Checkout Template"
},
paginateAfter =>{
fieldType=>"integer",
defaultValue=>10,
@ -421,6 +429,38 @@ sub findSubEvents {
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 {
my $self = shift;
@ -504,36 +544,40 @@ sub getSubEventForm {
my $pids = shift;
my $subEvents = $self->getSubEvents($pids);
my @usedEventIds;
#
# 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 %var;
my $i18n = WebGUI::International->new($self->session, 'Asset_EventManagementSystem');
$f->hidden(-name=>"func",-value=>"addToCart");
$f->hidden(-name=>"method",-value=>"addSubEvents");
$f->readOnly(-value=>$i18n->get('allowed sub events'));
$var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
.WebGUI::Form::hidden($self->session,{name=>"func",value=>"addToCart"})
.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) {
while (my $eventData = $subEvent->hashRef) {
# Track used event ids so we can prevent listing a subevent more than once.
next if (WebGUI::Utility::isIn($eventData->{productId}, @usedEventIds));
push (@usedEventIds, $eventData->{productId});
$f->checkbox(-value=>$eventData->{productId},
-label=>$eventData->{title}.
"&nbsp;".$eventData->{description}."&nbsp;".$eventData->{price}."<br />",
-name=>"subEventPID"
);
push(@subEventLoop, {
'form.checkBox' => WebGUI::Form::checkbox($self->session, {
value => $eventData->{productId},
name => "subEventPID"}),
'title' => $eventData->{title},
'description' => $eventData->{description},
'price' => $eventData->{price}
});
}
}
$f->submit;
my $output = $f->print if (scalar (@$subEvents) > 0);
$var{'subevents_loop'} = \@subEventLoop;
$var{'chooseSubevents'} = 1;
my $output = \%var if (scalar (@$subEvents) > 0);
return $output;
}
@ -543,10 +587,9 @@ sub resolveConflictForm {
my $self = shift;
my $event1 = shift;
my $event2 = shift;
my $output;
my $extrasURL = $self->session->config->get("extrasURL");
my $deleteIcon = $extrasURL."/toolbar/bullet/delete.gif";
my %var;
my $sth = $self->session->db->read("
select productId, title, price, description
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');
$output .= sprintf "<table><tr><td>%s</td></tr>", $i18n->get('scheduling conflict message');
$output .= "<form action='".$self->getUrl."' method='post'";
$output .= "<input type='hidden' name='func' value='deleteCartItem' />";
$output .= "<input type='hidden' name='event1' value='$event1' />";
$output .= "<input type='hidden' name='event2' value='$event2' />";
$var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl})
.WebGUI::Form::hidden($self->session,{name=>"func",value=>"deleteCartItem"})
.WebGUI::Form::hidden($self->session,{name=>"event1",value=>"$event1"})
.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) {
$output .= "<tr><td>";
$output .= "<input type='image' src='$deleteIcon' name='productToRemove' value='$data->{productId}' style='border: 0px;'/>";
$output .= "</td><td>";
$output .= $data->{title}."&nbsp;".$data->{description}."&nbsp;".$data->{price};
$output .= "</td></tr>";
push(@loop, {
'form.deleteControl' => "<input type='image' src='$deleteIcon' name='productToRemove' value='".$data->{productId}."' style='border: 0px;'/>",
'title' => $data->{title},
'description' => $data->{description},
'price' => $data->{price}
});
}
$output .= "</form>";
$output .= "</table>";
$output .= sprintf "<a href=''>%s</a>", $i18n->get('scheduling conflict continue');
$var{'conflict_loop'} = \@loop;
$var{'resolveConflicts'} = 1;
#
# This will all be templated
#
return $output;
return \%var;
}
#------------------------------------------------------------------
@ -641,14 +686,12 @@ sub www_addToCart {
$pid = shift;
# 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
if ($self->session->form->get("method") eq "addSubEvents") { # List of ids from subevent form
@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
push(@pids, $self->session->form->get("pid") || $pid);
@ -664,11 +707,10 @@ sub www_addToCart {
$errors = $self->checkConflicts;
if (scalar(@$errors) > 0) { return $self->error($errors, "www_addToCart"); }
#
# Also need to make all of this output use a template
$output = $self->getRegistrationInfo unless ($output);
}
#return $self->session->style->process($self->processTemplate($f->print,$self->getValue("gradebookTemplateId")),$self->getValue("styleTemplateId"));
return $self->session->style->process($output,$self->getValue("styleTemplateId"));
return $self->session->style->process($self->processTemplate($output,$self->getValue("checkoutTemplateId")),$self->getValue("styleTemplateId"));
}
#-------------------------------------------------------------------

View file

@ -187,7 +187,9 @@ Returns a reference to an array of all enabled instantiated payment plugins.
=cut
sub getEnabledPlugins {
my ($session) = @_;
#my ($session) = @_;
my $class = shift;
my $session = shift;
my (@enabledPlugins, $plugin, @plugins);
@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
sub getEnabledPlugins {
my ($session) = @_;
my $class = shift;
my $session = shift;
my (@enabledPlugins, $plugin, @plugins);
@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
# normal settings table for easy access.
if (/~([^~]*)~([^~]*)~([^~]*)/) {
WebGUI::Commerce::setCommerceSetting({
WebGUI::Commerce::setCommerceSetting($session,{
type => $1,
namespace => $2,
fieldName => $3,
@ -915,7 +915,8 @@ sub www_selectPaymentGateway {
});
}
} 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');
}
@ -944,8 +945,10 @@ Returns the user to the operation C<checkout> when it is done.
sub www_selectPaymentGatewaySave {
my $session = shift;
if (WebGUI::Commerce::Payment->load($session, $session->form->process("paymentGateway"))->enabled) {
$session->scratch->set('paymentGateway', $session->form->process("paymentGateway"));
# shifting stow first because it's only set when one payment gateway is defined
my $paymentGateway = $session->stow->get("paymentGateway") || $session->form->process("paymentGateway");
if (WebGUI::Commerce::Payment->load($session, $paymentGateway)->enabled) {
$session->scratch->set('paymentGateway', $paymentGateway);
} else {
$session->scratch->set('paymentGateway', '-delete-');
}
@ -980,7 +983,8 @@ sub www_selectShippingMethod {
});
}
} 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");
}
@ -988,9 +992,9 @@ sub www_selectShippingMethod {
$var{message} = $i18n->get('select shipping method');
$var{pluginsAvailable} = @$plugins;
$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{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));
}
@ -1012,7 +1016,9 @@ Returns the user to the operation C<checkout> when it is done.
sub www_selectShippingMethodSave {
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;
return WebGUI::Operation::execute($session,'selectShipping') unless ($shipping->optionsOk);

View file

@ -106,7 +106,8 @@ The name of the variable.
sub get {
my $self = 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};
}