From 02c24aa44a6cd4cdfdb6e681261426ecdae5d130 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 9 Apr 2008 22:48:15 +0000 Subject: [PATCH] fixed more c2 bugs added a workflow activity that removes EMS items from the cart if they've been in there too long --- docs/upgrades/upgrade_7.5.2-7.5.3.pl | 1 + lib/WebGUI/Shop/Cart.pm | 4 +- lib/WebGUI/Shop/CartItem.pm | 1 + lib/WebGUI/Shop/PayDriver.pm | 2 +- lib/WebGUI/URL/Content.pm | 1 + .../Workflow/Activity/ExpireEmsCartItems.pm | 104 ++++++++++++++++++ .../English/Asset_EventManagementSystem.pm | 18 +++ 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 lib/WebGUI/Workflow/Activity/ExpireEmsCartItems.pm diff --git a/docs/upgrades/upgrade_7.5.2-7.5.3.pl b/docs/upgrades/upgrade_7.5.2-7.5.3.pl index c4fe86f00..c832dac8d 100644 --- a/docs/upgrades/upgrade_7.5.2-7.5.3.pl +++ b/docs/upgrades/upgrade_7.5.2-7.5.3.pl @@ -156,6 +156,7 @@ sub upgradeEMS { price float not null default 0.00, primary key (assetId, revisionDate) )"); + $session->config->addToArray("workflowActivities/None","WebGUI::Workflow::Activity::ExpireEmsCartItems"); } #------------------------------------------------- diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index e2bbfb579..ad9149a4f 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -502,7 +502,7 @@ Update the cart and then redirect the user to the payment gateway screen. =cut -sub www_continueShopping { +sub www_checkout { my $self = shift; $self->updateFromForm; if ($error{id $self} ne "") { @@ -643,7 +643,7 @@ sub www_view { formFooter => WebGUI::Form::formFooter($session), updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button")}), checkoutButton => WebGUI::Form::submit($session, {value=>$i18n->get("checkout button"), - extras=>q|onclick="this.form.shop.value='pay';this.form.method.value='selectPaymentGateway';this.form.submit;"|}), + extras=>q|onclick="this.form.method.value='checkout';this.form.submit;"|}), continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"), extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}), chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"), diff --git a/lib/WebGUI/Shop/CartItem.pm b/lib/WebGUI/Shop/CartItem.pm index d8aabd23c..f3728416a 100644 --- a/lib/WebGUI/Shop/CartItem.pm +++ b/lib/WebGUI/Shop/CartItem.pm @@ -160,6 +160,7 @@ Returns the WebGUI::Shop::Address object that is attached to this item for shipp sub getShippingAddress { my $self = shift; my $addressId = $self->get("shippingAddressId") || $self->cart->get("shippingAddressId"); + $self->cart->session->errorHandler->warn("address id: ". $addressId); return $self->cart->getAddressBook->getAddress($addressId); } diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index be48a9d2b..cda9981fe 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -502,7 +502,7 @@ sub processTransaction { if ($success) { $transaction->completePurchase($transactionCode, $statusCode, $statusMessage); $cart->onCompletePurchase; - $self->sendNotifications($transaction); + # $self->sendNotifications($transaction); } else { $transaction->denyPurchase($transactionCode, $statusCode, $statusMessage); diff --git a/lib/WebGUI/URL/Content.pm b/lib/WebGUI/URL/Content.pm index 514bef913..dea05949d 100644 --- a/lib/WebGUI/URL/Content.pm +++ b/lib/WebGUI/URL/Content.pm @@ -56,6 +56,7 @@ sub handler { my $output = eval { WebGUI::Pluggable::run($handler, "handler", [ $session ] ) }; if ( my $e = WebGUI::Error->caught ) { $session->errorHandler->error($e->package.":".$e->line." - ".$e->error); + $session->errorHandler->debug($e->package.":".$e->line." - ".$e->trace); } else { if ($output eq "chunked") { diff --git a/lib/WebGUI/Workflow/Activity/ExpireEmsCartItems.pm b/lib/WebGUI/Workflow/Activity/ExpireEmsCartItems.pm new file mode 100644 index 000000000..f9a2a5ab9 --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/ExpireEmsCartItems.pm @@ -0,0 +1,104 @@ +package WebGUI::Workflow::Activity::ExpireEmsCartItems; + + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Workflow::Activity'; +use WebGUI::Shop::Cart; + +=head1 NAME + +Package WebGUI::Workflow::Activity::ExpireEmsCartItems + +=head1 DESCRIPTION + +Removes EMS items from shopping carts that have been held up by the user too long. + +=head1 SYNOPSIS + +See WebGUI::Workflow::Activity for details on how to use any activity. + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 definition ( session, definition ) + +See WebGUI::Workflow::Activity::defintion() for details. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift; + my $i18n = WebGUI::International->new($session, "Asset_EventManagementSystem"); + push(@{$definition}, { + name=>$i18n->get("expire ems cart items"), + properties=> { + expireAfter => { + fieldType=>"interval", + label=>$i18n->get("item expiration time"), + defaultValue=>60*60, + hoverHelp=>$i18n->get('item expiration time help') + }, + } + }); + return $class->SUPER::definition($session,$definition); +} + + +#------------------------------------------------------------------- + +=head2 execute ( [ object ] ) + +See WebGUI::Workflow::Activity::execute() for details. + +=cut + +sub execute { + my $self = shift; + my $object = shift; + my $instance = shift; + my $start = time(); + my $log = $self->session->errorHandler; + $log->info('Searching for EMS items that have been in the cart too long.'); + my $items = $self->session->db->read("select itemId, cartId, assetId from cartItem where + assetId in (select assetId from asset where className like 'WebGUI::Asset::Sku::EMS%') + and DATE_ADD(dateAdded, interval ".($self->get("expireAfter") + 0)." second) < now()"); + while (my ($itemId, $cartId, $assetId) = $items->array) { + $log->info('Removing item '.$itemId.' (asset '.$assetId.') from cart '.$cartId); + WebGUI::Shop::Cart->new($self->session, $cartId)->getItem($itemId)->remove; + if (time() - $start > 55) { + $items->finish; + $log->('Ran out of time. Will have to expire the rest later.'); + return $self->WAITING; + } + } + $log->info('No more EMS items to expire.'); + return $self->COMPLETE; +} + + + +1; + + diff --git a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm index c2f859bd2..5fef4d06f 100644 --- a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm +++ b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm @@ -2,6 +2,24 @@ package WebGUI::i18n::English::Asset_EventManagementSystem; use strict; our $I18N = { + 'expire ems cart items' => { + message => q|Expire EMS Cart Items|, + lastUpdated => 0, + context => q|workflow activity title|, + }, + + 'item expiration time' => { + message => q|Item Expiration Time|, + lastUpdated => 0, + context => q|a workflow activity field label|, + }, + + 'item expiration time help' => { + message => q|How long should EMS items be allowed to sit in a cart before they are expired to be freed up for someone else to purchase?|, + lastUpdated => 0, + context => q|help for a workflow activity field label|, + }, + 'percentage discount' => { message => q|Percentage Discount|, lastUpdated => 0,