Adding POD to the commerce system, as well as objectifying everything.

This commit is contained in:
Martin Kamerbeek 2005-01-10 16:06:11 +00:00
parent 702905c9db
commit 61d74619c5
4 changed files with 827 additions and 1 deletions

View file

@ -6,7 +6,53 @@ use WebGUI::SQL;
use WebGUI::Commerce::Item;
use WebGUI::Commerce::Payment;
=head1 NAME
Package WebGUI::Commerce::ShoppingCart
=head1 DESCRIPTION
This package implements a shopping cart for the E-Commerce system of WebGUI. This
shopping cart is tied to the sessionId and, thus, expires when the sessionId expires.
=head1 SYNOPSIS
$shoppingCart = WebGUI::Commerce::ShoppingCart->new;
$shoppingCart->add('myItemId', 'myItem', 3);
$shoppingCart->empty;
($normal, $recurring) = $shoppingCart->getItems;
$normal->[0]->{quantity} # quantity of first normal item
$recurring->[2]->{period} # period of third recurring item
$normal->[0]->{item}->id # the id of the first normal item
=head1 METHODS
This package provides the following methods:
=cut
#-------------------------------------------------------------------
=head2 add ( itemId, itemType, quantity )
This will add qunatity items of type itemType and with id itemId to the shopping cart.
=head3 itemId
The id of the item to add.
=head3 itemType
The type (namespace) of the item that's to be added to the cart.
=head3 quantity
The number of items to add. Defaults to 1 if quantity is not given.
=cut
sub add {
my ($self, $itemId, $itemType, $quantity);
$self = shift;
@ -27,6 +73,13 @@ sub add {
}
#-------------------------------------------------------------------
=head2 empty ( )
Invoking this method will putrge all content from the shopping cart.
=cut
sub empty {
my ($self);
$self = shift;
@ -35,6 +88,43 @@ sub empty {
}
#-------------------------------------------------------------------
=head2 getItems ( )
This method will return two arrayrefs repectively containing the normal items and the recurring
items in the shoppingcart.
Items are returned as a hashref with the following properties:
=head3 quantity
The quantity of this item.
=head3 period
The duration of a billingperiod if this this is a recurring transaction.
=head3 name
The name of this item.
=head3 price
The price of a single item.
=head3 totalPrice
The total price of this item. Ie. totalPrice = quantity * price.
=head3 item
The instanciated plugin of this item. See WebGUI::Commerce::Item for a detailed API.
For example:
=cut
sub getItems {
my ($self, $periodResolve, %cartContent, $item, $properties, @recurring, @normal);
$self = shift;
@ -63,6 +153,18 @@ sub getItems {
}
#-------------------------------------------------------------------
=head2 new ( sessionId )
Returns a shopping cart object tied to session id sessionId or the current session.
=head3 sessionId
The session id this cart should be tied to. If omitted this will default to the session id
of the current user.
=cut
sub new {
my ($class, $sessionId, $sth, $row, %items);
$class = shift;