From d9c4bd5576bdaf17cf4a8386edff0bbd15651805 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Sat, 13 May 2006 14:20:55 +0000 Subject: [PATCH] this should do it... --- .../Asset/Wobject/EventManagementSystem.pm | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index b39d388cd..54900334e 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -2067,6 +2067,7 @@ sub www_addEventsToBadge { push(@pastEvents,$_->{productId}) unless isIn($_->{productId},@pastEvents); $eventId = $_->{productId} unless $_->{prerequisiteId}; } + $self->removePurchaseFromCart($self->session->scratch->get("purchaseId".$purchaseCounter)); } else { # gotta use the existing purchaseId, b/c we're loading a completed purchase. my ($purchaseId) = $self->session->db->quickArray("select purchaseId from EventManagementSystem_registrations where badgeId=? and productId=? limit 1",[$bid,$eventId]); @@ -2088,18 +2089,8 @@ sub www_addEventsToBadge { my $purchaseCounter = $self->session->form->process('purchaseCounter'); if ($purchaseCounter ne "") { my $purchaseIdToDelete = $self->session->scratch->get('purchaseId'.$purchaseCounter); - my @eventsToSubtract = $self->session->db->buildArray("select r.productId from EventManagementSystem_registrations as r, EventManagementSystem_purchases as p, where r.purchaseId=? and (p.transactionId='' or p.transactionId is null) and p.purchaseId=r.purchaseId",[$purchaseIdToDelete]); - my $shoppingCart = WebGUI::Commerce::ShoppingCart->new($self->session); - my ($items, $nothing) = $shoppingCart->getItems; - foreach my $event (@eventsToSubtract) { - foreach my $item (@$items) { - if ($item->{item}->{productId} eq $event) { - $shoppingCart->setQuantity($event,'Event',($item->{item} - 1)); - } - } - } + $self->removePurchaseFromCart($purchaseIdToDelete); $self->session->scratch->delete('purchaseId'.$purchaseCounter); - } } return $self->www_resetScratchCart(); @@ -2107,6 +2098,28 @@ sub www_addEventsToBadge { #------------------------------------------------------------------- +=head2 removePurchaseFromCart ( ) + +Method to remove some items from the cart + +=cut + +sub removePurchaseFromCart { + my $self = shift; + my $purchaseId = shift; + my @eventsToSubtract = $self->session->db->buildArray("select r.productId from EventManagementSystem_registrations as r, EventManagementSystem_purchases as p, where r.purchaseId=? and (p.transactionId='' or p.transactionId is null) and p.purchaseId=r.purchaseId",[$purchaseIdToDelete]); + my $shoppingCart = WebGUI::Commerce::ShoppingCart->new($self->session); + my ($items, $nothing) = $shoppingCart->getItems; + foreach my $event (@eventsToSubtract) { + foreach my $item (@$items) { + if ($item->{item}->{productId} eq $event) { + $shoppingCart->setQuantity($event,'Event',($item->{item} - 1)); + } + } + } +} +#------------------------------------------------------------------- + =head2 www_returnItem ( ) Method to set some registrations as returned.