Checking in commerce stuff
This commit is contained in:
parent
d0374dcca3
commit
6e4cefc7c0
14 changed files with 1006 additions and 44 deletions
|
|
@ -54,12 +54,15 @@ The number of items to add. Defaults to 1 if quantity is not given.
|
|||
=cut
|
||||
|
||||
sub add {
|
||||
my ($self, $itemId, $itemType, $quantity);
|
||||
my ($self, $itemId, $itemType, $quantity, $item);
|
||||
$self = shift;
|
||||
$itemId = shift;
|
||||
$itemType = shift;
|
||||
$quantity = shift || 1;
|
||||
|
||||
$item = WebGUI::Commerce::Item->new($itemId, $itemType);
|
||||
return "" unless ($item->available);
|
||||
|
||||
$self->{_items}{$itemId."_".$itemType} = {
|
||||
itemId => $itemId,
|
||||
itemType => $itemType,
|
||||
|
|
@ -72,6 +75,38 @@ sub add {
|
|||
"(".quote($self->{_sessionId}).",".quote($itemId).",".quote($itemType).",".$self->{_items}{$itemId."_".$itemType}{quantity}.")");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub delete {
|
||||
my ($self, $itemId, $itemType);
|
||||
|
||||
$self = shift;
|
||||
$itemId = shift;
|
||||
$itemType = shift;
|
||||
|
||||
WebGUI::SQL->write("delete from shoppingCart where sessionId=".quote($self->{_sessionId}).
|
||||
" and itemId=".quote($itemId)." and itemType=".quote($itemType));
|
||||
|
||||
delete $self->{_items}{$itemId."_".$itemType};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub setQuantity {
|
||||
my ($self, $itemId, $itemType, $quantity);
|
||||
$self = shift;
|
||||
$itemId = shift;
|
||||
$itemType = shift;
|
||||
$quantity = shift;
|
||||
|
||||
WebGUI::ErrorHandler::fatal('No quantity or quantity is not a number: ('.$quantity.')') unless ($quantity =~ /^-?\d+$/);
|
||||
|
||||
return $self->delete($itemId, $itemType) if ($quantity <= 0);
|
||||
|
||||
$self->{_items}{$itemId."_".$itemType}->{quantity} = $quantity;
|
||||
|
||||
WebGUI::SQL->write("update shoppingCart set quantity=".quote($quantity).
|
||||
" where sessionId=".quote($self->{_sessionId})." and itemId=".quote($itemId)." and itemType=".quote($itemType));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 empty ( )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue