made event handlers for cart/sku

created baseline emsbadge and emsticket
added completePurchase() and denyPurchase() utility methods for transaction
This commit is contained in:
JT Smith 2008-03-19 20:18:00 +00:00
parent f3fd67378f
commit 2a2e683dd9
9 changed files with 884 additions and 170 deletions

View file

@ -66,25 +66,7 @@ A hash reference as generated by getOptions().
sub addToCart {
my ($self, $options) = @_;
$self->applyOptions($options);
my $cart = WebGUI::Shop::Cart->create($self->session);
$cart->addItem($self);
}
#-------------------------------------------------------------------
=head2 adjustQuantityAvailable ( amount )
Adjust the quantity of this product that is available. Send a negative number to decrease, or a positive number to increase. Returns getQuantityAvailable.
=head3 amount
A signed integer that represents the amount to adjust
=cut
sub adjustQuantityAvailable {
my ($self, $amount) = @_;
return $self->setQuantityAvailable($self->getQuantityAvailable + $amount);
$self->getCart->addItem($self);
}
#-------------------------------------------------------------------
@ -175,6 +157,13 @@ sub definition {
}
#-------------------------------------------------------------------
=head2 getCart ( ) {
my $self = shift;
return WebGUI::Shop::Cart->getCartBySession($self->session);
}
#-------------------------------------------------------------------
=head2 getConfiguredTitle ( )
@ -345,6 +334,61 @@ sub newBySku {
return WebGUI::Asset->newByDynamicClass($session, $assetId);
}
#-------------------------------------------------------------------
=head2 onAdjustQuantityInCart ( item, amount )
Called just after the quantity is adjusted in the cart. Should be overridden by subclasses that need to account for inventory or other bookkeeping.
=head3 item
Receives a reference to the WebGUI::Shop::CartItem so it can determine things like itemId and quantity if it needs them for book keeping purposes.
=head3 amount
The amount to be adjusted for. Could be positive if more are being added to the cart or negative if more are being removed from the cart.
=cut
sub onAdjustQuantityInCart {
my ($self, $item, $amount) = @_;
return undef;
}
#-------------------------------------------------------------------
=head2 onCompletePurchase ( item )
Called just after payment has been made. It allows for privileges to be given, or bookkeeping
tasks to be performed. It should be overriden by subclasses that need to do special processing after the purchase.
=head3 item
Receives a reference to the WebGUI::Shop::CartItem so it can determine things like itemId and quantity if it needs them for book keeping purposes.
=cut
sub onCompletePurchase {
my ($self, $item) = @_;
return undef;
}
#-------------------------------------------------------------------
=head2 onRemoveFromCart ( item )
Called by the cart just B<before> the item is removed from the cart. This allows for cleanup. Should be overridden by subclasses for inventory control or other housekeeping.
=head3 item
Receives a reference to the WebGUI::Shop::CartItem so it can determine things like itemId and quantity if it needs them for book keeping purposes.
=cut
sub onRemoveFromCart {
my ($self, $item) = @_;
return undef;
}
#-------------------------------------------------------------------
@ -366,23 +410,6 @@ sub processStyle {
#-------------------------------------------------------------------
=head2 setQuantityAvailable ( amount )
Set the quantity of this product that is available. Returns getQuantityAvailable(). Should be overridden by skus that keep track of quantity.
=head3 amount
A signed integer that represents the quantity to set it to.
=cut
sub setQuantityAvailable {
my ($self, $amount) = @_;
return $self->getQuantityAvailable;
}
#-------------------------------------------------------------------
=head2 www_view ( )
Renders self->view based upon current style, subject to timeouts. Returns Privilege::noAccess() if canView is False.