Fixed syntax error

This commit is contained in:
Frank Dillon 2006-05-10 19:34:05 +00:00
parent 34eded2de7
commit 21bdb2a5d3

View file

@ -1,192 +1,192 @@
package WebGUI::Commerce::Item::Event; package WebGUI::Commerce::Item::Event;
=head1 LEGAL =head1 LEGAL
------------------------------------------------------------------- -------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation. WebGUI is Copyright 2001-2006 Plain Black Corporation.
------------------------------------------------------------------- -------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using (docs/license.txt) that came with this distribution before using
this software. this software.
------------------------------------------------------------------- -------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com http://www.plainblack.com info@plainblack.com
------------------------------------------------------------------- -------------------------------------------------------------------
=head1 NAME =head1 NAME
Package WebGUI::Commerce::Item::Event Package WebGUI::Commerce::Item::Event
=head1 DESCRIPTION =head1 DESCRIPTION
Item plugin for events in the EventManagement system. Allows events entered there Item plugin for events in the EventManagement system. Allows events entered there
to be part of the Commerce system. to be part of the Commerce system.
=cut =cut
use strict; use strict;
our @ISA = qw(WebGUI::Commerce::Item); our @ISA = qw(WebGUI::Commerce::Item);
use WebGUI::Utility; use WebGUI::Utility;
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub available { sub available {
return $_[0]->{_event}->{approved}; return $_[0]->{_event}->{approved};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub description { sub description {
return $_[0]->{_event}->{description}; return $_[0]->{_event}->{description};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub handler { sub handler {
my $self = shift; my $self = shift;
my $transactionId = shift; my $transactionId = shift;
#mark all purchaseIds as paid #mark all purchaseIds as paid
my $counter = 0; my $counter = 0;
while (1) { while (1) {
my $purchaseId; my $purchaseId;
if ($purchaseId = $self->session->scratch->get("purchaseId".$counter)) { if ($purchaseId = $self->session->scratch->get("purchaseId".$counter)) {
$self->session->db->setRow('EventManagementSystem_purchases', 'purchaseId', {'purchaseId'=>$purchaseId, 'transactionId'=>$transactionId}, $purchaseId); $self->session->db->setRow('EventManagementSystem_purchases', 'purchaseId', {'purchaseId'=>$purchaseId, 'transactionId'=>$transactionId}, $purchaseId);
my $theseRegs = $self->session->db->buildArrayRefOfHashRefs("select * from EventManagementSystem_registrations where purchaseId=?",[$purchaseId]); my $theseRegs = $self->session->db->buildArrayRefOfHashRefs("select * from EventManagementSystem_registrations where purchaseId=?",[$purchaseId]);
foreach (@$theseRegs) { foreach (@$theseRegs) {
# clean up the duplicate registrations, if any. # clean up the duplicate registrations, if any.
$self->session->db->write("delete from EventManagementSystem_registrations where badgeId=? and productId=? and registrationId!=?,[$_->{badgeId},$_->{productId},$_->{registrationId}]); $self->session->db->write("delete from EventManagementSystem_registrations where badgeId=? and productId=? and registrationId!=?",[$_->{badgeId},$_->{productId},$_->{registrationId}]);
} }
$self->session->scratch->delete("purchaseId".$counter); $self->session->scratch->delete("purchaseId".$counter);
$counter++; $counter++;
} }
else { last; } else { last; }
} }
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub id { sub id {
return $_[0]->{_event}->{productId}; return $_[0]->{_event}->{productId};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub isRecurring { sub isRecurring {
return 0; return 0;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub name { sub name {
return $_[0]->{_event}->{title}; return $_[0]->{_event}->{title};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 new ( $session ) =head2 new ( $session )
Overload default constructor to glue in information from the EMS. Overload default constructor to glue in information from the EMS.
=cut =cut
sub new { sub new {
my ($class, $session, $eventId); my ($class, $session, $eventId);
$class = shift; $class = shift;
$session = shift; $session = shift;
$eventId = shift; $eventId = shift;
my $eventData = $session->db->quickHashRef("select p.productId, p.title, p.description, p.price, e.approved, e.passId, e.passType my $eventData = $session->db->quickHashRef("select p.productId, p.title, p.description, p.price, e.approved, e.passId, e.passType
from EventManagementSystem_products as e, products as p from EventManagementSystem_products as e, products as p
where p.productId = e.productId and p.productId=".$session->db->quote($eventId)); where p.productId = e.productId and p.productId=".$session->db->quote($eventId));
bless {_event => $eventData, _session => $session, priceLineItem => 1}, $class; bless {_event => $eventData, _session => $session, priceLineItem => 1}, $class;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub needsShipping { sub needsShipping {
return 0; return 0;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub price { sub price {
return $_[0]->{_event}->{price}; return $_[0]->{_event}->{price};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub priceLineItem { sub priceLineItem {
my $self = shift; my $self = shift;
# this will become the total number of normally-priced events. # this will become the total number of normally-priced events.
my $quantity = shift; my $quantity = shift;
# this is the output of ShoppingCart->getItems (the \@normal arrayref). # this is the output of ShoppingCart->getItems (the \@normal arrayref).
my $cartItems = shift; my $cartItems = shift;
use Data::Dumper; use Data::Dumper;
# $self->session->errorHandler->warn('normal contents: '.Dumper($cartItems)); # $self->session->errorHandler->warn('normal contents: '.Dumper($cartItems));
# this is the default price of this event. # this is the default price of this event.
my $price = $self->{_event}->{price}; my $price = $self->{_event}->{price};
# get the list of discount passes that this event is "under" # get the list of discount passes that this event is "under"
my @discountPasses = split(/::/,$self->{_event}->{passId}); my @discountPasses = split(/::/,$self->{_event}->{passId});
# $self->session->errorHandler->warn('discount passes: '.Dumper(\@discountPasses)); # $self->session->errorHandler->warn('discount passes: '.Dumper(\@discountPasses));
# return the default behavior if this event does not have a pass assigned. # return the default behavior if this event does not have a pass assigned.
return ($price * $quantity) unless (scalar(@discountPasses) && ($self->{_event}->{passType} eq 'member')); return ($price * $quantity) unless (scalar(@discountPasses) && ($self->{_event}->{passType} eq 'member'));
# keep a running total of this line item. # keep a running total of this line item.
my $totalPrice = 0; my $totalPrice = 0;
# build the list of passes in our cart. # build the list of passes in our cart.
my %passesInCart; # key: passId, value: quantity in cart my %passesInCart; # key: passId, value: quantity in cart
my $totalPassesInCart; my $totalPassesInCart;
foreach my $passId (@discountPasses) { foreach my $passId (@discountPasses) {
# get a list of events that define this pass # get a list of events that define this pass
my @passEvents = $self->session->db->buildArray("select productId from EventManagementSystem_products where passType='defines' and passId=?",[$passId]); my @passEvents = $self->session->db->buildArray("select productId from EventManagementSystem_products where passType='defines' and passId=?",[$passId]);
$self->session->errorHandler->warn('pass events: '.Dumper(\@passEvents)); $self->session->errorHandler->warn('pass events: '.Dumper(\@passEvents));
my $numberOfPasses = 0; my $numberOfPasses = 0;
# find out if we have any of this pass's events in our cart. # find out if we have any of this pass's events in our cart.
foreach my $item (@$cartItems) { foreach my $item (@$cartItems) {
# $self->session->errorHandler->warn('quantity of this pass event: '.$item->{quantity}); # $self->session->errorHandler->warn('quantity of this pass event: '.$item->{quantity});
$numberOfPasses += $item->{quantity} if ( $numberOfPasses += $item->{quantity} if (
$item->{item}->type eq 'Event' $item->{item}->type eq 'Event'
&& isIn($item->{item}->{_event}->{productId},@passEvents) && isIn($item->{item}->{_event}->{productId},@passEvents)
); );
} }
if ($numberOfPasses) { if ($numberOfPasses) {
# $self->session->errorHandler->warn('adding a discount pass.'); # $self->session->errorHandler->warn('adding a discount pass.');
$passesInCart{$passId} = $numberOfPasses; $passesInCart{$passId} = $numberOfPasses;
$totalPassesInCart += $numberOfPasses; $totalPassesInCart += $numberOfPasses;
} }
} }
foreach my $passId (keys(%passesInCart)) { foreach my $passId (keys(%passesInCart)) {
my $pass = $self->session->db->quickHashRef("select * from EventManagementSystem_discountPasses where passId=?",[$passId]); my $pass = $self->session->db->quickHashRef("select * from EventManagementSystem_discountPasses where passId=?",[$passId]);
my $discountedPrice = $price; my $discountedPrice = $price;
my $numberOfThisPass = $passesInCart{$passId}; my $numberOfThisPass = $passesInCart{$passId};
# calculate discount. # calculate discount.
if ($pass->{type} eq 'newPrice') { if ($pass->{type} eq 'newPrice') {
$self->session->errorHandler->warn('discounted price: '.$pass->{amount}); $self->session->errorHandler->warn('discounted price: '.$pass->{amount});
$discountedPrice = (0 + $pass->{amount}) if ($price > (0 + $pass->{amount})); $discountedPrice = (0 + $pass->{amount}) if ($price > (0 + $pass->{amount}));
} elsif ($pass->{type} eq 'amountOff') { } elsif ($pass->{type} eq 'amountOff') {
# not yet implemented! # not yet implemented!
} elsif ($pass->{type} eq 'percentOff') { } elsif ($pass->{type} eq 'percentOff') {
# not yet implemented! # not yet implemented!
} }
# while we still have passes and items left to discount. # while we still have passes and items left to discount.
while ($numberOfThisPass && $quantity) { while ($numberOfThisPass && $quantity) {
# $self->session->errorHandler->warn('applying a discount pass.'); # $self->session->errorHandler->warn('applying a discount pass.');
$totalPrice += $discountedPrice; $totalPrice += $discountedPrice;
$self->session->errorHandler->warn('new discounted price: '.$discountedPrice); $self->session->errorHandler->warn('new discounted price: '.$discountedPrice);
$quantity--; $quantity--;
$numberOfThisPass--; $numberOfThisPass--;
} }
} }
# return the total of the discounted items plus the total of the non discounted items. # return the total of the discounted items plus the total of the non discounted items.
return ($totalPrice + ($quantity * $price)); return ($totalPrice + ($quantity * $price));
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub session { sub session {
my $self = shift; my $self = shift;
return $self->{_session}; return $self->{_session};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub type { sub type {
return 'Event'; return 'Event';
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub weight { sub weight {
return 0; return 0;
} }
1; 1;