From 7e4e7898c09458c6bb22524d3724bbfbc90aed90 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 8 Apr 2008 18:48:43 +0000 Subject: [PATCH] fixed several checkout bugs --- lib/WebGUI/Asset/Sku/EMSRibbon.pm | 2 +- lib/WebGUI/Asset/Sku/EMSToken.pm | 4 +- lib/WebGUI/Shop/Cart.pm | 74 ++++++++++++++++++++++--------- lib/WebGUI/Shop/PayDriver.pm | 4 +- lib/WebGUI/URL/Content.pm | 5 ++- 5 files changed, 60 insertions(+), 29 deletions(-) diff --git a/lib/WebGUI/Asset/Sku/EMSRibbon.pm b/lib/WebGUI/Asset/Sku/EMSRibbon.pm index 0f433f710..a194a978f 100644 --- a/lib/WebGUI/Asset/Sku/EMSRibbon.pm +++ b/lib/WebGUI/Asset/Sku/EMSRibbon.pm @@ -132,7 +132,7 @@ Does bookkeeping on EMSRegistrationRibbon table. sub onCompletePurchase { my ($self, $item) = @_; - $self->session->db->write("insert into EMSRegistrationRibbon (ribbonAssetId, badgeId) values (?,?)", + $self->session->db->write("insert into EMSRegistrantRibbon (ribbonAssetId, badgeId) values (?,?)", [$self->getId, $self->getOptions->{badgeId}]); return undef; } diff --git a/lib/WebGUI/Asset/Sku/EMSToken.pm b/lib/WebGUI/Asset/Sku/EMSToken.pm index 8a32f1907..e8add53e6 100644 --- a/lib/WebGUI/Asset/Sku/EMSToken.pm +++ b/lib/WebGUI/Asset/Sku/EMSToken.pm @@ -118,10 +118,10 @@ sub onCompletePurchase { my $currentQuantity = $db->quickScalar("select quantity from EMSRegistrantToken where tokenAssetId=? and badgeId=?",\@params); unshift @params, $item->get("quantity"); if (defined $currentQuantity) { - $db->write("update EMSRegistrationToken set quantity=quantity+? where tokenAssetId=? and badgeId=?",\@params); + $db->write("update EMSRegistrantToken set quantity=quantity+? where tokenAssetId=? and badgeId=?",\@params); } else { - $db->write("insert into EMSRegistrationToken (quantity, tokenAssetId, badgeId) values (?,?,?)",\@params); + $db->write("insert into EMSRegistrantToken (quantity, tokenAssetId, badgeId) values (?,?,?)",\@params); } return undef; } diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index ba0f735cf..e2bbfb579 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -399,11 +399,11 @@ sub readyForCheckout { my $self = shift; # Check if the shipping address is set and correct - my $address = $self->getShippingAddress; + my $address = eval{$self->getShippingAddress}; return 0 if WebGUI::Error->caught; # Check if the ship driver is chosen and existant - my $ship = $self->getShipper; + my $ship = eval {$self->getShipper}; return 0 if WebGUI::Error->caught; # Check if the cart has items @@ -467,6 +467,53 @@ sub update { #------------------------------------------------------------------- +=head2 updateFromForm ( ) + +Updates the cart totals. + +=cut + +sub updateFromForm { + my $self = shift; + my $form = $self->session->form; + foreach my $item (@{$self->getItems}) { + if ($form->get("quantity-".$item->getId) ne "") { + eval { $item->setQuantity($form->get("quantity-".$item->getId)) }; + if (WebGUI::Error->caught("WebGUI::Error::Shop::MaxOfItemInCartReached")) { + my $i18n = WebGUI::International->new($self->session, "Shop"); + $error{id $self} = sprint($i18n->get("too many of this item"), $item->get("configuredTitle")); + } + elsif (my $e = WebGUI::Error->caught) { + $error{id $self} = "An unknown error has occured: ".$e->message; + } + } + } + + my $cartProperties; + $cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' ); + $self->update( $cartProperties ); +} + +#------------------------------------------------------------------- + +=head2 www_checkout ( ) + +Update the cart and then redirect the user to the payment gateway screen. + +=cut + +sub www_continueShopping { + my $self = shift; + $self->updateFromForm; + if ($error{id $self} ne "") { + return $self->www_view; + } + $self->session->http->setRedirect($self->session->url->page('shop=pay;method=selectPaymentGateway')); + return undef; +} + +#------------------------------------------------------------------- + =head2 www_continueShopping ( ) Update the cart and the return the user back to the asset. @@ -475,9 +522,9 @@ Update the cart and the return the user back to the asset. sub www_continueShopping { my $self = shift; - my $cartView = $self->www_update; + $self->updateFromForm; if ($error{id $self} ne "") { - return $cartView; + return $self->www_view; } return undef; } @@ -529,24 +576,7 @@ Updates the cart totals and then displays the cart again. sub www_update { my $self = shift; - my $form = $self->session->form; - foreach my $item (@{$self->getItems}) { - if ($form->get("quantity-".$item->getId) ne "") { - eval { $item->setQuantity($form->get("quantity-".$item->getId)) }; - if (WebGUI::Error->caught("WebGUI::Error::Shop::MaxOfItemInCartReached")) { - my $i18n = WebGUI::International->new($self->session, "Shop"); - $error{id $self} = sprint($i18n->get("too many of this item"), $item->get("configuredTitle")); - } - elsif (my $e = WebGUI::Error->caught) { - $error{id $self} = "An unknown error has occured: ".$e->message; - } - } - } - - my $cartProperties; - $cartProperties->{ shipperId } = $form->process( 'shipperId' ) if $form->process( 'shipperId' ); - $self->update( $cartProperties ); - + $self->updateFromForm; return $self->www_view; } diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index e3b3d2b26..be48a9d2b 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -500,12 +500,12 @@ sub processTransaction { }); my ($success, $transactionCode, $statusCode, $statusMessage) = $self->processPayment; if ($success) { - $transaction->completePurchase($cart, $transactionCode, $statusCode, $statusMessage); + $transaction->completePurchase($transactionCode, $statusCode, $statusMessage); $cart->onCompletePurchase; $self->sendNotifications($transaction); } else { - $transaction->denyTransaction($transactionCode, $statusCode, $statusMessage); + $transaction->denyPurchase($transactionCode, $statusCode, $statusMessage); } return $transaction; } diff --git a/lib/WebGUI/URL/Content.pm b/lib/WebGUI/URL/Content.pm index 9b30a7a4d..514bef913 100644 --- a/lib/WebGUI/URL/Content.pm +++ b/lib/WebGUI/URL/Content.pm @@ -17,6 +17,7 @@ package WebGUI::URL::Content; use strict; use Apache2::Const -compile => qw(OK DECLINED); use WebGUI::Affiliate; +use WebGUI::Exception; use WebGUI::Pluggable; use WebGUI::Session; @@ -53,8 +54,8 @@ sub handler { my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server); foreach my $handler (@{$config->get("contentHandlers")}) { my $output = eval { WebGUI::Pluggable::run($handler, "handler", [ $session ] ) }; - if ( $@ ) { - $session->errorHandler->error($@); + if ( my $e = WebGUI::Error->caught ) { + $session->errorHandler->error($e->package.":".$e->line." - ".$e->error); } else { if ($output eq "chunked") {