Add a creation date to the Cart.
Use that date to expire carts older than an interval, via a new workflow. Config file changes, tests, i18n.
This commit is contained in:
parent
6bd159bcfd
commit
60a3906b05
9 changed files with 299 additions and 5 deletions
|
|
@ -175,7 +175,7 @@ sub create {
|
|||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $cartId = $session->id->generate;
|
||||
$session->db->write('insert into cart (cartId, sessionId) values (?,?)', [$cartId, $session->getId]);
|
||||
$session->db->write('insert into cart (cartId, sessionId, creationDate) values (?,?,UNIX_TIMESTAMP())', [$cartId, $session->getId]);
|
||||
return $class->new($session, $cartId);
|
||||
}
|
||||
|
||||
|
|
@ -561,6 +561,10 @@ The unique id of the configured shipping driver that will be used to ship these
|
|||
|
||||
The ID of a user being checked out, if they're being checked out by a cashier.
|
||||
|
||||
=head4 creationDate
|
||||
|
||||
The date the cart was created.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
|
|
@ -569,7 +573,7 @@ sub update {
|
|||
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
|
||||
}
|
||||
my $id = id $self;
|
||||
foreach my $field (qw(shippingAddressId posUserId shipperId)) {
|
||||
foreach my $field (qw(shippingAddressId posUserId shipperId creationDate)) {
|
||||
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||
}
|
||||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||
|
|
|
|||
110
lib/WebGUI/Workflow/Activity/RemoveOldCarts.pm
Normal file
110
lib/WebGUI/Workflow/Activity/RemoveOldCarts.pm
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
package WebGUI::Workflow::Activity::RemoveOldCarts;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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::International;
|
||||
use WebGUI::Asset::Sku::Product;
|
||||
use WebGUI::Inbox;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Activity::RemoveOldCarts
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Remove carts that are older than a configurable threshold.
|
||||
|
||||
=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, 'Workflow_Activity_RemoveOldCarts');
|
||||
push(@{$definition}, {
|
||||
name=>$i18n->get('activityName'),
|
||||
properties=> {
|
||||
cartTimeout => {
|
||||
fieldType=>'interval',
|
||||
label=>$i18n->get('cart timeout'),
|
||||
defaultValue=>48*3600,
|
||||
hoverHelp=>$i18n->get('cart timeout help'),
|
||||
},
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($session,$definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 execute ( [ object ] )
|
||||
|
||||
See WebGUI::Workflow::Activity::execute() for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my ($self) = @_;
|
||||
my $session = $self->session;
|
||||
my $now = time();
|
||||
my $finishTime = $now + $self->getTTL;
|
||||
my $expired = 0;
|
||||
my $cartIds = [];
|
||||
my $limit = $now - $self->get('cartTimeout');
|
||||
$session->log->warn("limit: $limit");
|
||||
my $expiredCarts = $session->db->read('select cartId from cart where creationDate < '.$limit);
|
||||
$expiredCarts->execute();
|
||||
CART: while( my ($cartId) = $expiredCarts->array() ) {
|
||||
my $cart = eval {
|
||||
WebGUI::Shop::Cart->new($session, $cartId);
|
||||
};
|
||||
next CART if WebGUI::Error->caught;
|
||||
$session->log->warn("cartId: $cartId");
|
||||
$cart->delete; ##Delete will empty, then delete.
|
||||
##Time check and set flag
|
||||
if (time() > $finishTime) {
|
||||
$expired = 1;
|
||||
last CART;
|
||||
}
|
||||
}
|
||||
##If timer expired, then store message and limit and release
|
||||
if ($expired) {
|
||||
return $self->WAITING(1);
|
||||
}
|
||||
|
||||
return $self->COMPLETE;
|
||||
}
|
||||
|
||||
1;
|
||||
25
lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldCarts.pm
Normal file
25
lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldCarts.pm
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package WebGUI::i18n::English::Workflow_Activity_RemoveOldCarts;
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'cart timeout help' => {
|
||||
message => q|How old should carts be before we delete them?|,
|
||||
context => q|the hover help for the storage timeout field|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'cart timeout' => {
|
||||
message => q|Cart Timeout|,
|
||||
context => q|a label indicating how old carts should be before we delete them|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'activityName' => {
|
||||
message => q|Remove Old Carts|,
|
||||
context => q|The name of this workflow activity.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue