Checking in commerce stuff
This commit is contained in:
parent
d0374dcca3
commit
6e4cefc7c0
14 changed files with 1006 additions and 44 deletions
|
|
@ -36,6 +36,12 @@ These methods are available from this class:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub available {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 description ( )
|
||||
|
||||
This returns the description of the item. This must be implemented by an item plugin.
|
||||
|
|
@ -111,6 +117,10 @@ sub name {
|
|||
return WebGUI::ErrorHandler::fatal('The name method of WebGUI::Commerce::Item must be overridden.');
|
||||
}
|
||||
|
||||
sub needsShipping {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( itemdId, itemType )
|
||||
|
|
@ -136,6 +146,9 @@ sub new {
|
|||
$id = shift;
|
||||
$namespace = shift;
|
||||
|
||||
WebGUI::ErrorHandler::fatal('No namespace') unless ($namespace);
|
||||
WebGUI::ErrorHandler::fatal('No ID') unless ($id);
|
||||
|
||||
$cmd = "WebGUI::Commerce::Item::$namespace";
|
||||
$load = "use $cmd";
|
||||
eval($load);
|
||||
|
|
@ -170,5 +183,18 @@ sub type {
|
|||
return WebGUI::ErrorHandler::fatalError('The type method of WebGUI::Commerce::Item must be overridden.');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 weight ( )
|
||||
|
||||
Returns the weight of the item. If your item has a weight, you'll want to overload this method. Weight is calculated on a unit based scale.
|
||||
So for instance if your units are kg's 3.154 means 3 kg and 154 grams.
|
||||
|
||||
=cut
|
||||
|
||||
sub weight {
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -85,8 +85,7 @@ sub configurationForm {
|
|||
$f->yesNo(
|
||||
-name => $self->prepend('enabled'),
|
||||
-value => $self->enabled,
|
||||
#### intl ####
|
||||
-label => 'Enable',
|
||||
-label => WebGUI::International->get('enable', 'Commerce'),
|
||||
);
|
||||
$f->raw($form);
|
||||
|
||||
|
|
@ -436,6 +435,16 @@ sub recurringPeriodValues {
|
|||
return \%periods;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingCost {
|
||||
return WebGUI::ErrorHandler::fatal("You must override the shippingCost method in the payment plugin.");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingDescription {
|
||||
return WebGUI::ErrorHandler::fatal("You must override the shippingDescription method in the payment plugin.");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 supports
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ sub cancelRecurringPayment {
|
|||
sub connectionError {
|
||||
my ($self, $resultCode);
|
||||
$self = shift;
|
||||
|
||||
|
||||
return $self->resultMessage if ($self->{_connectionError});
|
||||
return undef;
|
||||
}
|
||||
|
|
@ -555,7 +555,7 @@ sub getRecurringPaymentStatus {
|
|||
sub errorCode {
|
||||
my ($self, $resultCode);
|
||||
$self = shift;
|
||||
|
||||
|
||||
$resultCode = $self->{_response}->{Status};
|
||||
return $resultCode unless ($resultCode eq 'OK');
|
||||
return undef;
|
||||
|
|
@ -633,6 +633,18 @@ sub resultMessage {
|
|||
return $self->{_response}->{ErrorMessage};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingCost {
|
||||
my $self = shift;
|
||||
$self->{_shipping}->{cost} = shift;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingDescription {
|
||||
my $self = shift;
|
||||
$self->{_shipping}->{description} = shift;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub submit {
|
||||
my ($self, $xml, $items);
|
||||
|
|
@ -703,6 +715,15 @@ my %transactionData = %{$self->{_transactionParams}};
|
|||
</Item>\n";
|
||||
}
|
||||
|
||||
if ($self->{_shipping}->{cost}) {
|
||||
$xml .=
|
||||
" <Item>
|
||||
<Description>Shipping cost. ".$self->{_shipping}->{description}."</Description>
|
||||
<Cost>".sprintf('%.2f', $self->{_shipping}->{cost})."</Cost>
|
||||
<Qty>1</Qty>
|
||||
</Item>\n";
|
||||
};
|
||||
|
||||
$xml .=
|
||||
" </OrderItems>
|
||||
</TransactionData>
|
||||
|
|
@ -752,6 +773,7 @@ sub supports {
|
|||
#-------------------------------------------------------------------
|
||||
sub transactionCompleted {
|
||||
my ($self) = shift;
|
||||
|
||||
return ($self->{_response}->{Status} eq 'OK');
|
||||
}
|
||||
|
||||
|
|
@ -759,7 +781,7 @@ sub transactionCompleted {
|
|||
sub transactionError {
|
||||
my ($self, $resultCode);
|
||||
$self = shift;
|
||||
|
||||
|
||||
$resultCode = $self->resultCode;
|
||||
return $self->resultMessage if ($resultCode ne 'OK');
|
||||
return undef;
|
||||
|
|
|
|||
|
|
@ -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 ( )
|
||||
|
|
|
|||
|
|
@ -113,6 +113,41 @@ sub delete {
|
|||
undef $self;
|
||||
}
|
||||
|
||||
sub deleteItem {
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub deleteItem {
|
||||
my ($self, $itemId, $itemType, $amount, @items);
|
||||
$self = shift;
|
||||
$itemId = shift;
|
||||
$itemType = shift;
|
||||
|
||||
WebGUI::ErrorHandler::fatal('No itemId') unless ($itemId);
|
||||
WebGUI::ErrorHandler::fatal('No itemType') unless ($itemType);
|
||||
|
||||
$amount = $self->get('amount');
|
||||
|
||||
foreach (@{$self->getItems}) {
|
||||
|
||||
if (($_->{itemId} eq $itemId) && ($_->{itemType} eq $itemType)) {
|
||||
$amount = $amount - ($_->{quantity} * $_->{amount});
|
||||
} else {
|
||||
push(@items, $_);
|
||||
}
|
||||
}
|
||||
|
||||
WebGUI::SQL->write("delete from transactionItem where transactionId=".quote($self->get('transactionId')).
|
||||
" and itemId=".quote($itemId)." and itemType=".quote($itemType));
|
||||
|
||||
WebGUI::SQL->write("update transaction set amount=".quote($amount)." where transactionId=".quote($self->get('transactionId')));
|
||||
|
||||
$self->{_properties}{amount} = $amount;
|
||||
|
||||
$self->{_items} = \@items;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 gateway ( gatewayName )
|
||||
|
|
@ -228,6 +263,33 @@ sub getItems {
|
|||
return $self->{_items};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getTransactions {
|
||||
my ($self, $criteria, @constraints, $sql, @transactionIds, @transactions);
|
||||
|
||||
$self = shift;
|
||||
$criteria = shift;
|
||||
|
||||
push (@constraints, 'initDate >= '.quote($criteria->{initStart})) if (defined $criteria->{initStart});
|
||||
push (@constraints, 'initDate <= '.quote($criteria->{initStop})) if (defined $criteria->{initStop});
|
||||
push (@constraints, 'initDate >= '.quote($criteria->{completionStart})) if (defined $criteria->{completionStart});
|
||||
push (@constraints, 'initDate >= '.quote($criteria->{completionStop})) if (defined $criteria->{completionStop});
|
||||
push (@constraints, 'status='.quote($criteria->{paymentStatus})) if (defined $criteria->{paymentStatus});
|
||||
push (@constraints, 'shippingStatus='.quote($criteria->{shippingStatus})) if (defined $criteria->{shippingStatus});
|
||||
|
||||
$sql = 'select transactionId from transaction';
|
||||
$sql .= ' where '.join(' and ', @constraints) if (@constraints);
|
||||
|
||||
@transactionIds = WebGUI::SQL->buildArray($sql);
|
||||
|
||||
foreach (@transactionIds) {
|
||||
push(@transactions, WebGUI::Commerce::Transaction->new($_));
|
||||
}
|
||||
|
||||
return @transactions;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isRecurring ( recurring )
|
||||
|
|
@ -344,6 +406,62 @@ sub pendingTransactions {
|
|||
return \@transactions;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingCost {
|
||||
my ($self, $shippingCost);
|
||||
$self = shift;
|
||||
$shippingCost = shift;
|
||||
|
||||
if ($shippingCost) {
|
||||
$self->{_properties}{shippingCost} = $shippingCost;
|
||||
WebGUI::SQL->write("update transaction set shippingCost=".quote($shippingCost)." where transactionId=".quote($self->{_transactionId}));
|
||||
}
|
||||
|
||||
return $self->{_properties}{shippingCost};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingMethod {
|
||||
my ($self, $shippingMethod);
|
||||
$self = shift;
|
||||
$shippingMethod = shift;
|
||||
|
||||
if ($shippingMethod) {
|
||||
$self->{_properties}{shippingMethod} = $shippingMethod;
|
||||
WebGUI::SQL->write("update transaction set shippingMethod=".quote($shippingMethod)." where transactionId=".quote($self->{_transactionId}));
|
||||
}
|
||||
|
||||
return $self->{_properties}{shippingMethod};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingOptions {
|
||||
my ($self, $shippingOptions);
|
||||
$self = shift;
|
||||
$shippingOptions = shift;
|
||||
|
||||
if ($shippingOptions) {
|
||||
$self->{_properties}{shippingOptions} = $shippingOptions;
|
||||
WebGUI::SQL->write("update transaction set shippingOptions=".quote($shippingOptions)." where transactionId=".quote($self->{_transactionId}));
|
||||
}
|
||||
|
||||
return $self->{_properties}{shippingOptions};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub shippingStatus {
|
||||
my ($self, $shippingStatus);
|
||||
$self = shift;
|
||||
$shippingStatus = shift;
|
||||
|
||||
if ($shippingStatus) {
|
||||
$self->{_properties}{shippingStatus} = $shippingStatus;
|
||||
WebGUI::SQL->write("update transaction set shippingStatus=".quote($shippingStatus)." where transactionId=".quote($self->{_transactionId}));
|
||||
}
|
||||
|
||||
return $self->{_properties}{shippingStatus};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 status ( status )
|
||||
|
|
@ -369,6 +487,21 @@ sub status {
|
|||
return $self->{_properties}{status};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub trackingNumber {
|
||||
my ($self, $trackingNumber);
|
||||
$self = shift;
|
||||
$trackingNumber = shift;
|
||||
|
||||
if ($trackingNumber) {
|
||||
$self->{_properties}{trackingNumber} = $trackingNumber;
|
||||
WebGUI::SQL->write("update transaction set trackingNumber=".quote($trackingNumber)." where transactionId=".quote($self->{_transactionId}));
|
||||
}
|
||||
|
||||
return $self->{_properties}{trackingNumber};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 transactionId
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue