Checking in commerce stuff

This commit is contained in:
Martin Kamerbeek 2005-04-25 22:33:57 +00:00
parent d0374dcca3
commit 6e4cefc7c0
14 changed files with 1006 additions and 44 deletions

View file

@ -300,6 +300,15 @@ sub getAdminFunction {
op=>"listSubscriptions",
group=>"3"
},
"productManager"=>{
title=>{
id=>"manage products",
namespace=>"ProductManager"
},
icon=>"productManager.gif",
op=>"listProducts",
group=>"14"
},
"cache"=>{
title=>{
id=>"manage cache",

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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 ( )

View file

@ -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

View file

@ -160,6 +160,9 @@ sub readConfig {
$data{$directive} = {};
}
}
if (ref $data{shippingPlugins} ne "ARRAY") {
$data{shippingPlugins} = [$data{shippingPlugins}] if ($data{shippingPlugins});
}
if( defined( $data{scripturl} ) ) {
# get rid of leading "/" if present.
$data{scripturl} =~ s/^\///;

View file

@ -184,20 +184,50 @@ sub getOperations {
'redeemSubscriptionCode' => 'WebGUI::Operation::Subscription',
'listSubscriptionCodes' => 'WebGUI::Operation::Subscription',
'deleteSubscriptionCodes' => 'WebGUI::Operation::Subscription',
'addToCart' => 'WebGUI::Operation::Commerce',
'checkout' => 'WebGUI::Operation::Commerce',
'checkoutConfirm' => 'WebGUI::Operation::Commerce',
'checkoutSubmit' => 'WebGUI::Operation::Commerce',
'deleteCartItem' => 'WebGUI::Operation::Commerce',
'editCommerceSettings' => 'WebGUI::Operation::Commerce',
'editCommerceSettingsSave' => 'WebGUI::Operation::Commerce',
'listPendingTransactions' => 'WebGUI::Operation::Commerce',
'listTransactions' => 'WebGUI::Operation::Commerce',
'cancelTransaction' => 'WebGUI::Operation::Commerce',
'completePendingTransaction' => 'WebGUI::Operation::Commerce',
'selectPaymentGateway' => 'WebGUI::Operation::Commerce',
'selectPaymentGatewaySave' => 'WebGUI::Operation::Commerce',
'selectShippingMethod' => 'WebGUI::Operation::Commerce',
'selectShippingMethodSave' => 'WebGUI::Operation::Commerce',
'updateCart' => 'WebGUI::Operation::Commerce',
'viewCart' => 'WebGUI::Operation::Commerce',
'viewPurchaseHistory' => 'WebGUI::Operation::TransactionLog',
'cancelRecurringTransaction' => 'WebGUI::Operation::TransactionLog',
'deleteTransaction' => 'WebGUI::Operation::TransactionLog',
'deleteTransactionItem' => 'WebGUI::Operation::TransactionLog',
'deleteProduct' => 'WebGUI::Operation::ProductManager',
'deleteProductParameter' => 'WebGUI::Operation::ProductManager',
'deleteProductParameterOption' => 'WebGUI::Operation::ProductManager',
'editProduct' => 'WebGUI::Operation::ProductManager',
'editProductSave' => 'WebGUI::Operation::ProductManager',
'editProductParameter' => 'WebGUI::Operation::ProductManager',
'editProductParameterSave' => 'WebGUI::Operation::ProductManager',
'editProductParameterOption' => 'WebGUI::Operation::ProductManager',
'editProductParameterOptionSave' => 'WebGUI::Operation::ProductManager',
'editProductVariant' => 'WebGUI::Operation::ProductManager',
'editProductVariantSave' => 'WebGUI::Operation::ProductManager',
'editSkuTemplate' => 'WebGUI::Operation::ProductManager',
'editSkuTemplateSave' => 'WebGUI::Operation::ProductManager',
'listProducts' => 'WebGUI::Operation::ProductManager',
'listProductVariants' => 'WebGUI::Operation::ProductManager',
'listProductVariantsSave' => 'WebGUI::Operation::ProductManager',
'manageProduct' => 'WebGUI::Operation::ProductManager',
'manageCache' => 'WebGUI::Operation::Cache',
'flushCache' => 'WebGUI::Operation::Cache',
};
};
}
1;

View file

@ -7,6 +7,7 @@ use WebGUI::ErrorHandler;
use WebGUI::Commerce::Transaction;
use WebGUI::Commerce::ShoppingCart;
use WebGUI::Commerce::Payment;
use WebGUI::Commerce::Shipping;
use WebGUI::AdminConsole;
use WebGUI::TabForm;
use WebGUI::Style;
@ -19,6 +20,9 @@ use WebGUI::Asset::Template;
use WebGUI::HTTP;
use WebGUI::Paginator;
use WebGUI::Form;
use Storable;
use WebGUI::Icon;
#-------------------------------------------------------------------
sub _submenu {
@ -33,18 +37,55 @@ sub _submenu {
$ac->setHelp($help, 'Commerce');
}
$ac->addSubmenuItem(WebGUI::URL::page('op=editCommerceSettings'), $i18n->get('manage commerce settings'));
$ac->addSubmenuItem(WebGUI::URL::page('op=listPendingTransactions'), $i18n->get('pending transactions'));
$ac->addSubmenuItem(WebGUI::URL::page('op=listTransactions'), $i18n->get('list transactions'));
return $ac->render($workarea, $title);
}
#-------------------------------------------------------------------
sub _gatewaySelected {
return 0 unless ($session{form}{paymentGateway});
my $plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
sub _clearCheckoutScratch {
_clearShippingScratch();
_clearPaymentScratch();
}
#-------------------------------------------------------------------
sub _clearPaymentScratch {
WebGUI::Session::setScratch('paymentGateway', '-delete-');
}
#-------------------------------------------------------------------
sub _clearShippingScratch {
WebGUI::Session::setScratch('shippingMethod', '-delete-');
WebGUI::Session::setScratch('shippingOptions', '-delete-');
}
#-------------------------------------------------------------------
sub _paymentSelected {
return 0 unless (WebGUI::Session::getScratch('paymentGateway'));
my $plugin = WebGUI::Commerce::Payment->load(WebGUI::Session::getScratch('paymentGateway'));
return 1 if ($plugin && $plugin->enabled);
return 0;
}
#-------------------------------------------------------------------
sub _shippingSelected {
return 0 unless (WebGUI::Session::getScratch('shippingMethod'));
my $plugin = WebGUI::Commerce::Shipping->load(WebGUI::Session::getScratch('shippingMethod'));
if ($plugin) {
$plugin->setOptions(Storable::thaw(WebGUI::Session::getScratch('shippingOptions'))) if (WebGUI::Session::getScratch('shippingOptions'));
return 1 if ($plugin->enabled && $plugin->optionsOk);
}
return 0;
}
#-------------------------------------------------------------------
sub www_addToCart {
WebGUI::Commerce::ShoppingCart->new->add($session{form}{itemId}, $session{form}{itemType}, $session{form}{quantity});
return WebGUI::Operation::execute('viewCart');
}
#-------------------------------------------------------------------
sub www_cancelTransaction {
my ($transaction, %var);
@ -62,12 +103,16 @@ sub www_cancelTransaction {
# This operation is here for easier future extensions to the commerce system.
#-------------------------------------------------------------------
sub www_checkout {
return WebGUI::Operation::execute('selectShippingMethod') unless (_shippingSelected);
return WebGUI::Operation::execute('selectPaymentGateway') unless (_paymentSelected);
return WebGUI::Operation::execute('checkoutConfirm');
}
#-------------------------------------------------------------------
sub www_checkoutConfirm {
my ($plugin, $f, %var, $errors, $i18n, $shoppingCart, $normal, $recurring);
my ($plugin, $f, %var, $errors, $i18n, $shoppingCart, $normal, $recurring, $shipping, $total);
$errors = shift;
$i18n = WebGUI::International->new('Commerce');
@ -77,9 +122,9 @@ sub www_checkoutConfirm {
WebGUI::Session::setScratch('redirectAfterLogin', WebGUI::URL::page('op=checkout'));
return WebGUI::Operation::execute('auth');
}
# If no payment gateway has been selected yet, have the user do so now.
return WebGUI::Operation::execute('selectPaymentGateway') unless _gatewaySelected;
return WebGUI::Operation::execute('checkout') unless (_paymentSelected && _shippingSelected);
$var{errorLoop} = [ map {{message => $_}} @{$errors} ] if $errors;
@ -87,22 +132,54 @@ sub www_checkoutConfirm {
$shoppingCart = WebGUI::Commerce::ShoppingCart->new;
($normal, $recurring) = $shoppingCart->getItems;
$var{normalItemLoop} = $normal;
$var{normalItems} = scalar(@$normal);
$var{recurringLoop} = $recurring;
$var{recurringItems} = scalar(@$recurring);
$plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
foreach (@$normal) {
$_->{deleteIcon} = deleteIcon('op=deleteCartItem&itemId='.$_->{item}->id.'&itemType='.$_->{item}->type);
$_->{'quantity.form'} = WebGUI::Form::integer({
name => 'quantity~'.$_->{item}->type.'~'.$_->{item}->id,
value => $_->{quantity},
size => 3,
});
$total += $_->{totalPrice};
}
foreach (@$recurring) {
$_->{deleteIcon} = deleteIcon('op=deleteCartItem&itemId='.$_->{item}->id.'&itemType='.$_->{item}->type);
$_->{'quantity.form'} = WebGUI::Form::integer({
name => 'quantity~'.$_->{item}->type.'~'.$_->{item}->id,
value => $_->{quantity},
size => 3,
});
$total += $_->{totalPrice};
}
$var{normalItemsLoop} = $normal;
$var{normalItems} = scalar(@$normal);
$var{recurringItemsLoop} = $recurring;
$var{recurringItems} = scalar(@$recurring);
$var{subTotal} = sprintf('%.2f', $total);
$shipping = WebGUI::Commerce::Shipping->load(WebGUI::Session::getScratch('shippingMethod'));
$shipping->setOptions(Storable::thaw(WebGUI::Session::getScratch('shippingOptions'))) if (WebGUI::Session::getScratch('shippingOptions'));
$var{shippingName} = $shipping->name;
$var{shippingCost} = sprintf('%.2f', $shipping->calc);
$var{total} = sprintf('%.2f', $total + $shipping->calc);
$plugin = WebGUI::Commerce::Payment->load(WebGUI::Session::getScratch('paymentGateway'));
$f = WebGUI::HTMLForm->new;
$f->hidden('op', 'checkoutSubmit');
$f->hidden('paymentGateway', $session{form}{paymentGateway});
$f->raw($plugin->checkoutForm);
$f->submit($i18n->get('pay button'));
$var{form} = $f->print;
$var{title} = $i18n->get('checkout confirm title');
$var{'changePayment.url'} = WebGUI::URL::page('op=selectPaymentGateway');
$var{'changePayment.label'} = $i18n->get('change payment gateway');
$var{'changeShipping.url'} = WebGUI::URL::page('op=selectShippingMethod');
$var{'changeShipping.label'} = $i18n->get('change shipping method');
return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new($session{setting}{commerceConfirmCheckoutTemplateId})->process(\%var));
}
@ -110,7 +187,8 @@ sub www_checkoutConfirm {
#-------------------------------------------------------------------
sub www_checkoutSubmit {
my ($plugin, $shoppingCart, $transaction, $var, $amount, @cartItems, $i18n, @transactions,
@normal, $currentPurchase, $checkoutError, @resultLoop, %param, $normal, $recurring, $formError);
@normal, $currentPurchase, $checkoutError, @resultLoop, %param, $normal, $recurring,
$formError, $shipping, $shippingCost, $shippingDescription);
$i18n = WebGUI::International->new('Commerce');
@ -121,9 +199,14 @@ sub www_checkoutSubmit {
}
# Check if a valid payment gateway has bee selected. If not have the user do so.
return WebGUI::Operation::execute('selectPaymentGateway') unless _gatewaySelected;
return WebGUI::Operation::execute('checkout') unless (_paymentSelected && _shippingSelected);
# Load shipping plugin.
$shipping = WebGUI::Commerce::Shipping->load(WebGUI::Session::getScratch('shippingMethod'));
$shipping->setOptions(Storable::thaw(WebGUI::Session::getScratch('shippingOptions'))) if (WebGUI::Session::getScratch('shippingOptions'));
$plugin = WebGUI::Commerce::Payment->load($session{form}{paymentGateway});
# Load payment plugin.
$plugin = WebGUI::Commerce::Payment->load(WebGUI::Session::getScratch('paymentGateway'));
$shoppingCart = WebGUI::Commerce::ShoppingCart->new;
($normal, $recurring) = $shoppingCart->getItems;
@ -142,10 +225,17 @@ sub www_checkoutSubmit {
push(@transactions, {recurring => 0, items => [@$normal]}) if (@$normal);
$shoppingCart->empty;
foreach $currentPurchase (@transactions) {
$amount = 0;
$var = {};
$shipping->setShippingItems($currentPurchase->{items});
$shippingCost = $shipping->calc;
$shippingDescription = $shipping->description;
$plugin->shippingCost($shippingCost);
$plugin->shippingDescription($shippingDescription);
# Write transaction to the log with status pending
$transaction = WebGUI::Commerce::Transaction->new('new');
@ -154,8 +244,13 @@ sub www_checkoutSubmit {
$amount += ($_->{item}->price * $_->{quantity});
$var->{purchaseDescription} .= $_->{quantity}.' x '.$_->{item}->name.'<br>';
}
$transaction->shippingCost($shippingCost);
$transaction->shippingMethod($shipping->namespace);
$transaction->shippingOptions($shipping->getOptions);
$transaction->shippingStatus('NotSent');
$var->{purchaseAmount} = sprintf('%.2f', $amount);
# submit
if ($currentPurchase->{recurring}) {
$transaction->isRecurring(1);
@ -176,7 +271,7 @@ sub www_checkoutSubmit {
$transaction->gatewayId($plugin->gatewayId);
$transaction->gateway($plugin->namespace);
# check transaction result
unless ($plugin->connectionError) {
unless ($plugin->transactionError) {
@ -208,6 +303,8 @@ sub www_checkoutSubmit {
$param{title} = $i18n->get('transaction error title');
$param{statusExplanation} = $i18n->get('status codes information');
$param{resultLoop} = \@resultLoop;
_clearCheckoutScratch;
# If everythings ok show the purchase history
return WebGUI::Operation::execute('viewPurchaseHistory') unless ($checkoutError);
@ -245,21 +342,32 @@ sub www_confirmTransaction {
}
}
#-------------------------------------------------------------------
sub www_deleteCartItem {
WebGUI::Commerce::ShoppingCart->new->delete($session{form}{itemId}, $session{form}{itemType});
return WebGUI::Operation::execute('viewCart');
}
#-------------------------------------------------------------------
sub www_editCommerceSettings {
my (%tabs, $tabform, $jscript, $currentPlugin, $ac, $jscript, $i18n, $paymentPlugin, @paymentPlugins, %paymentPlugins, @failedPaymentPlugins, $plugin);
my (%tabs, $tabform, $jscript, $currentPlugin, $ac, $jscript, $i18n,
$paymentPlugin, @paymentPlugins, %paymentPlugins, @failedPaymentPlugins, $plugin,
$shippingPlugin, @shippingPlugins, %shippingPlugins, @failedShippingPlugins);
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
$i18n = WebGUI::International->new('Commerce');
tie %tabs, 'Tie::IxHash';
%tabs = (
payment=>{label=>$i18n->get('payment tab')},
general=>{label=>$i18n->get('general tab')},
payment=>{label=>$i18n->get('payment tab')},
shipping=>{label=>$i18n->get('shipping tab')},
);
$paymentPlugin = $session{config}{paymentPlugins}->[0];
$shippingPlugin = $session{config}{shippingPlugins}->[0];
$tabform = WebGUI::TabForm->new(\%tabs);
$tabform->hidden({name => 'op', value => 'editCommerceSettingsSave'});
@ -288,6 +396,19 @@ sub www_editCommerceSettings {
-value => $session{setting}{commerceSelectPaymentGatewayTemplateId},
-namespace => 'Commerce/SelectPaymentGateway'
);
$tabform->getTab('general')->template(
-name => 'commerceSelectShippingMethodTemplateId',
-label => $i18n->get('checkout select shipping template'),
-value => $session{setting}{commerceSelectShippingMethodTemplateId},
-namespace => 'Commerce/SelectShippingMethod'
);
$tabform->getTab('general')->template(
-name => 'commerceViewShoppingCartTemplateId',
-label => $i18n->get('view shopping cart template'),
-value => $session{setting}{commerceViewShoppingCartTemplateId},
-namespace => 'Commerce/ViewShoppingCart'
);
$tabform->getTab('general')->email(
-name => 'commerceSendDailyReportTo',
-label => $i18n->get('daily report email'),
@ -333,7 +454,43 @@ sub www_editCommerceSettings {
$tabform->getTab('payment')->raw('<tr><td colspan="2" align="left"><br>'.$i18n->get('failed payment plugins').
'<br><ul><li>'.join('</li><li>', @failedPaymentPlugins).'</li></ul></td></tr>');
}
# Shipping plugins...
# Check which payment plugins will compile, and load them.
foreach (@{$session{config}{shippingPlugins}}) {
$plugin = WebGUI::Commerce::Shipping->load($_);
if ($plugin) {
push(@shippingPlugins, $plugin);
$shippingPlugins{$_} = $plugin->name;
} else {
push(@failedShippingPlugins, $_);
}
}
# shipping plugin
if (%shippingPlugins) {
$tabform->getTab('shipping')->raw('<script language="JavaScript" > var activeShipping="'.$shippingPlugin.'"; </script>');
$tabform->getTab('shipping')->selectList(
-name => 'commerceShippingPlugin',
-options=> \%shippingPlugins,
-label => $i18n->get('shipping plugin label'),
-value => [$shippingPlugin],
-extras => 'onChange="activeShipping=operateHidden(this.options[this.selectedIndex].value,activeShipping)"'
);
$jscript = '<script language="JavaScript">';
foreach $currentPlugin (@shippingPlugins) {
$tabform->getTab('shipping')->raw('<tr id="'.$currentPlugin->namespace.'"><td colspan="2" width="100%">'.
'<table border=0 cellspacing=0 cellpadding=0 width="100%">'.
$currentPlugin->configurationForm.'<tr><td width="304">&nbsp;</td><td width="496">&nbsp;</td></tr></table></td></tr>');
$jscript .= "document.getElementById(\"".$currentPlugin->namespace."\").style.display='".(($currentPlugin->namespace eq $shippingPlugin)?"":"none")."';";
}
$jscript .= '</script>';
$tabform->getTab('shipping')->raw($jscript);
} else {
$tabform->getTab('shipping')->raw('<tr><td colspan="2" align="left">'.$i18n->get('no shipping plugins selected').'</td></tr>');
}
$tabform->submit;
WebGUI::Style::setScript($session{config}{extrasURL}.'/swapLayers.js',{language=>"Javascript"});
@ -395,10 +552,107 @@ sub www_listPendingTransactions {
_submenu($output, 'list pending transactions', 'list pending transactions');
}
#-------------------------------------------------------------------
sub www_listTransactions {
my ($output, %criteria, $transaction, @transactions);
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
my $i18n = WebGUI::International->new('TransactionLog');
my $transactionOptions = {
'' => 'Any',
'Pending' => 'Pending',
'Completed' => 'Completed',
};
my $shippingOptions = {
'' => 'Any',
'Shipped' => 'Shipped',
'NotShipped' => 'Not yet shipped',
'Delivered' => 'Delivered',
};
my $initStart = WebGUI::FormProcessor::date('initStart');
my $initStop = WebGUI::DateTime::addToTime(WebGUI::FormProcessor::date('initStop'),23,59);
my $completionStart = WebGUI::FormProcessor::date('completionStart');
my $completionStop = WebGUI::DateTime::addToTime(WebGUI::FormProcessor::date('completionStop'),23,59);
$output .= $i18n->get('selection message');
$output .= WebGUI::Form::formHeader;
$output .= WebGUI::Form::hidden({name=>'op', value=>'listTransactions'});
$output .= '<table>';
$output .= '<td>'.WebGUI::Form::radio({name=>'selection', value => 'init', checked=>($session{form}{selection} eq 'init')}).'</td>';
$output .= '<td align="left">'.$i18n->get('init date').'</td>';
$output .= '<td>'.WebGUI::Form::date({name=>'initStart', value=>$initStart}).' '.$i18n->get('and').' '.WebGUI::Form::date({name=>'initStop', value=>$initStop}).'</td>';
$output .= '</tr><tr>';
$output .= '<td>'.WebGUI::Form::radio({name=>'selection', value => 'completion', checked=>($session{form}{selection} eq 'completion')}).'</td>';
$output .= '<td align="left">'.$i18n->get('completion date').'</td>';
$output .= '<td>'.WebGUI::Form::date({name=>'completionStart', value=>$completionStart}).' '.$i18n->get('and').' '.WebGUI::Form::date({name=>'completionStop', value=>$completionStop}).'</td>';
$output .= '</tr><tr>';
$output .= '<td></td>';
$output .= '<td align="left">'.$i18n->get('transaction status').'</td>';
$output .= '<td>'.WebGUI::Form::selectList({name => 'tStatus', value => [$session{form}{tStatus}], options => $transactionOptions});
$output .= '</tr><tr>';
$output .= '<td></td>';
$output .= '<td align="left">'.$i18n->get('shipping status').'</td>';
$output .= '<td>'.WebGUI::Form::selectList({name => 'sStatus', value => [$session{form}{sStatus}], options => $shippingOptions});
$output .= '</tr><tr>';
$output .= '<td></td>';
$output .= '<td>'.WebGUI::Form::submit({value=>$i18n->get('select')}).'</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= WebGUI::Form::formFooter;
$criteria{initStart} = WebGUI::FormProcessor::date('initStart') if ($session{form}{initStart} && ($session{form}{selection} eq 'init'));
$criteria{initStop} = WebGUI::FormProcessor::date('initStop') if ($session{form}{initStop} && ($session{form}{selection} eq 'init'));
$criteria{completionStart} = WebGUI::FormProcessor::date('completionStart') if ($session{form}{completionStart} && ($session{form}{selection} eq 'completion'));
$criteria{completionStop} = WebGUI::FormProcessor::date('completionStop') if ($session{form}{completionStop} && ($session{form}{selection} eq 'completion'));
$criteria{shippingStatus} = $session{form}{sStatus} if ($session{form}{sStatus});
$criteria{paymentStatus} = $session{form}{tStatus} if ($session{form}{tStatus});
@transactions = WebGUI::Commerce::Transaction->getTransactions(\%criteria);
$output .= '<table border="1">';
$output .= '<tr><th></th><th>Init Date</th><th>Completion Date</th><th>Amount</th><th>Shipping Cost</th><th>Status</th><th>Shipping Status</th></tr>';
foreach $transaction (@transactions) {
$output .= '<tr bgcolor="#ddd">';
$output .= '<td>'.deleteIcon('op=deleteTransaction&tid='.$transaction->get('transactionId')).'</td>';
$output .= '<td>'.WebGUI::DateTime::epochToHuman($transaction->get('initDate')).'</td>';
$output .= '<td>'.WebGUI::DateTime::epochToHuman($transaction->get('completionDate')).'</td>';
$output .= '<td>'.$transaction->get('amount').'</td>';
$output .= '<td>'.$transaction->get('shippingCost').'</td>';
$output .= '<td>'.$transaction->get('status').'</td>';
$output .= '<td>'.$transaction->get('shippingStatus').'</td>';
$output .= '</tr>';
my @items = @{$transaction->getItems};
foreach (@items) {
$output .= '<tr>';
$output .= '<td></td>';
$output .= '<td colspan="3">'.
deleteIcon('op=deleteTransactionItem&tid='.$transaction->get('transactionId').'&iid='.$_->{itemId}.'&itype='.$_->{itemType}).
$_->{itemName}.'</td>';
$output .= '<td>'.$_->{quantity}.'</td>';
$output .= '<td> x </td>';
$output .= '<td>'.$_->{amount}.'</td>';
$output .= '</tr>';
}
}
$output .= '</table>';
return _submenu($output, 'list transactions')
}
#-------------------------------------------------------------------
sub www_selectPaymentGateway {
my ($plugins, $f, $i18n, @pluginLoop, %var);
_clearPaymentScratch;
$i18n = WebGUI::International->new('Commerce');
$plugins = WebGUI::Commerce::Payment->getEnabledPlugins;
if (scalar(@$plugins) > 1) {
@ -409,26 +663,151 @@ sub www_selectPaymentGateway {
formElement => WebGUI::Form::radio({name=>'paymentGateway', value=>$_->namespace})
});
}
} else {
} elsif (scalar(@$plugins) == 1) {
$session{form}{paymentGateway} = $plugins->[0]->namespace;
return WebGUI::Operation::execute("checkoutConfirm");
return WebGUI::Operation::execute('selectPaymentGatewaySave');
}
$var{pluginLoop} = \@pluginLoop;
$var{message} = $i18n->get('select payment gateway');
$var{pluginsAvailable} = @$plugins;
$var{noPluginsMessage} = $i18n->get('no payment gateway');
$var{formHeader} = WebGUI::Form::formHeader.WebGUI::Form::hidden({name=>'op', value=>'checkoutConfirm'});
$var{formHeader} = WebGUI::Form::formHeader.WebGUI::Form::hidden({name=>'op', value=>'selectPaymentGatewaySave'});
$var{formSubmit} = WebGUI::Form::submit({value=>$i18n->get('payment gateway select')});
$var{formFooter} = WebGUI::Form::formFooter;
return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new($session{setting}{commerceSelectPaymentGatewayTemplateId})->process(\%var));
}
#-------------------------------------------------------------------
sub www_selectPaymentGatewaySave {
if (WebGUI::Commerce::Payment->load($session{form}{paymentGateway})->enabled) {
WebGUI::Session::setScratch('paymentGateway', $session{form}{paymentGateway});
} else {
WebGUI::Session::setScratch('paymentGateway', '-delete-');
}
return WebGUI::Operation::execute('checkout');
}
#-------------------------------------------------------------------
sub www_selectShippingMethod {
my ($plugins, $f, $i18n, @pluginLoop, %var);
_clearShippingScratch;
$i18n = WebGUI::International->new('Commerce');
$plugins = WebGUI::Commerce::Shipping->getEnabledPlugins;
if (scalar(@$plugins) > 1) {
foreach (@$plugins) {
push(@pluginLoop, {
name => $_->name,
namespace => $_->namespace,
formElement => WebGUI::Form::radio({name=>'shippingMethod', value=>$_->namespace})
});
}
} elsif (scalar(@$plugins) == 1) {
$session{form}{shippingMethod} = $plugins->[0]->namespace;
return WebGUI::Operation::execute("selectShippingMethodSave");
}
$var{pluginLoop} = \@pluginLoop;
$var{message} = $i18n->get('select shipping method');
$var{pluginsAvailable} = @$plugins;
$var{noPluginsMessage} = $i18n->get('no shipping methods available');
$var{formHeader} = WebGUI::Form::formHeader.WebGUI::Form::hidden({name=>'op', value=>'selectShippingMethodSave'});
$var{formSubmit} = WebGUI::Form::submit({value=>$i18n->get('shipping select button')});
$var{formFooter} = WebGUI::Form::formFooter;
return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new($session{setting}{commerceSelectShippingMethodTemplateId})->process(\%var));
}
#-------------------------------------------------------------------
sub www_selectShippingMethodSave {
my $shipping = WebGUI::Commerce::Shipping->load($session{form}{shippingMethod});
$shipping->processOptionsForm;
return WebGUI::Operation::execute('selectShipping') unless ($shipping->optionsOk);
if ($shipping->enabled) {
WebGUI::Session::setScratch('shippingMethod', $shipping->namespace);
WebGUI::Session::setScratch('shippingOptions', Storable::freeze($shipping->getOptions));
} else {
WebGUI::Session::setScratch('shippingMethod', '-delete-');
}
return WebGUI::Operation::execute('checkout');
}
#-------------------------------------------------------------------
sub www_transactionComplete {
return WebGUI::Operation::execute('viewPurchaseHistory');
}
#-------------------------------------------------------------------
sub www_updateCart {
my $shoppingCart = WebGUI::Commerce::ShoppingCart->new;
foreach my $formElement (keys(%{$session{form}})) {
if ($formElement =~ m/^quantity~([^~]*)~([^~]*)$/) {
$shoppingCart->setQuantity($2, $1, $session{form}{$formElement});
}
}
return WebGUI::Operation::execute('viewCart');
}
#-------------------------------------------------------------------
sub www_viewCart {
my ($shoppingCart, $normal, $recurring, %var, $total, $i18n);
$i18n = WebGUI::International->new('Commerce');
# Put contents of cart in template vars
$shoppingCart = WebGUI::Commerce::ShoppingCart->new;
($normal, $recurring) = $shoppingCart->getItems;
foreach (@$normal) {
$_->{deleteIcon} = deleteIcon('op=deleteCartItem&itemId='.$_->{item}->id.'&itemType='.$_->{item}->type);
$_->{'quantity.form'} = WebGUI::Form::integer({
name => 'quantity~'.$_->{item}->type.'~'.$_->{item}->id,
value => $_->{quantity},
size => 3,
});
$total += $_->{totalPrice};
}
foreach (@$recurring) {
$_->{deleteIcon} = deleteIcon('op=deleteCartItem&itemId='.$_->{item}->id.'&itemType='.$_->{item}->type);
$_->{'quantity.form'} = WebGUI::Form::integer({
name => 'quantity~'.$_->{item}->type.'~'.$_->{item}->id,
value => $_->{quantity},
size => 3,
});
$total += $_->{totalPrice};
}
$var{'cartEmpty'} = !(scalar(@$normal) || scalar(@$recurring));
$var{'cartEmpty.message'} = $i18n->get('shopping cart empty');
$var{'updateForm.header'} = WebGUI::Form::formHeader().
WebGUI::Form::hidden({name => 'op', value => 'updateCart'});
$var{'updateForm.button'} = WebGUI::Form::submit({value => $i18n->get('update cart')});
$var{'updateForm.footer'} = WebGUI::Form::formFooter;
$var{'checkoutForm.header'} = WebGUI::Form::formHeader().
WebGUI::Form::hidden({name => 'op', value => 'checkout'});
$var{'checkoutForm.button'} = WebGUI::Form::submit({value => $i18n->get('checkout')});
$var{'checkoutForm.footer'} = WebGUI::Form::formFooter;
$var{normalItemsLoop} = $normal;
$var{normalItems} = scalar(@$normal);
$var{recurringItemsLoop} = $recurring;
$var{recurringItems} = scalar(@$recurring);
$var{total} = sprintf('%.2f', $total);
return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new($session{setting}{commerceViewShoppingCartTemplateId})->process(\%var));
}
1;

View file

@ -6,6 +6,9 @@ use WebGUI::Commerce::Transaction;
use WebGUI::Asset::Template;
use WebGUI::DateTime;
use WebGUI::Operation;
use WebGUI::Form;
use WebGUI::Privilege;
use WebGUI::Grouping;
#-------------------------------------------------------------------
sub www_viewPurchaseHistory {
@ -47,6 +50,28 @@ sub www_cancelRecurringTransaction {
return www_viewPurchaseHistory($message);
}
#-------------------------------------------------------------------
sub www_deleteTransaction {
my $transactionId;
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
$transactionId = $session{form}{tid};
WebGUI::Commerce::Transaction->new($transactionId)->delete;
return WebGUI::Operation::execute('listTransactions');
}
#-------------------------------------------------------------------
sub www_deleteTransactionItem {
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
WebGUI::Commerce::Transaction->new($session{form}{tid})->deleteItem($session{form}{iid}, $session{form}{itype});
return WebGUI::Operation::execute('listTransactions');
}
1;

View file

@ -112,12 +112,6 @@ Your password.<br>|,
context => q|The menu title for 'Show pending transactions' in the AdminConsole side menu.|
},
'list pending transactions' => {
message => q|Pending transactions|,
lastUpdated => 1101772628,
context => q|The title of the 'Show pending transactions' AdminConsole screen.|
},
'transactionId' => {
message => q|TransactionId|,
lastUpdated => 0,
@ -421,7 +415,76 @@ A radio button tied to this plugin.<br>
lastUpdated => 1101881921,
context => q|The body of the help page of the select payment gateway template.|
},
'shipping tab' => {
message => q|Shipping|,
lastUpdated => 0,
context => q|The label of the SHipping tab in the commerce settings manager.|
},
'shipping plugin label' => {
message => q|Shipping plugin|,
lastUpdated => 0,
context => q|The label of the shipping plugin selection box in the commerce settings manager.|
},
'no shipping plugins selected' => {
message => q|There are no shipping plugins to select. Please enable plugins in the config file.|,
lastUpdated => 0,
context => q|The message that's shown in the AdminConsole/Commerce menu when there are no shipping plugins enabled.|
},
'select shipping method' => {
message => q|Please select a shipping method.|,
lastUpdated => 0,
context => q|The message asking the user to choose a shipping method during checkout.|
},
'no shipping methods available' => {
message => q|Shipping is not possible because no shipping plugins are enabled.|,
lastUpdated => 0,
context => q|A message that is shown when a user tries to checkout but no shipping plugins are enabled.|
},
'shipping select button' => {
message => q|Select shipping method|,
lastUpdated => 0,
context => q|The label of the select button of the select shipping form the user sees during checkout.|
},
'enable' => {
message => q|Enable|,
lastUpdated => 0,
context => q|The label of the enable option of the commerce plugins.|
},
'change payment gateway' => {
message => q|Change payment gateway|,
lastUpdated => 0,
context => q|The label for the change payament gateway url.|
},
'change shipping method' => {
message => q|Change shipping method|,
lastUpdated => 0,
context => q|The label for the change shipping method url.|
},
'checkout select shipping template' => {
message => q|Select shipping method template|,
lastUpdated => 0,
context => q|The formlabel for the 'select shipping method template' option in the commerce part of the admin console.|
},
'shopping cart empty' => {
message => q|Your shopping cart is empty.|,
lastUpdated => 0,
context => q|A message indicating that te shopping cart is empty.|
},
'update cart' => {
message => q|Update cart|,
lastUpdated => 0,
context => q|The label of the update cart button.|
},
'checkout' => {
message => q|Checkout|,
lastUpdated => 0,
context => q|The label of the checkout button.|
},
'list transactions' => {
message => q|List transactions|,
lastUpdated => 0,
context => q|List transactions label|
},
};
1;

View file

@ -85,5 +85,43 @@ A loop containing the transactions in the transaction history. Within this loop
lastUpdated => 0,
context => q|The title of the help page of the purchase history template.|
},
'init date' => {
message => q|Init date|,
lastUpdated => 0,
context => q|Init date label.|
},
'completion date' => {
message => q|Completion date|,
lastUpdated => 0,
context => q|Completion date label|
},
'and' => {
message => q|and|,
lastUpdated => 0,
context => q|The word 'and'|
},
'transaction status' => {
message => q|Transaction status|,
lastUpdated => 0,
context => q|Transaction status label.|
},
'shipping status' => {
message => q|Shipping status|,
lastUpdated => 0,
context => q|Shipping status label.|
},
'select' => {
message => q|Select|,
lastUpdated => 0,
context => q|Select button label.|
},
'list transactions title' => {
message => q|List transactions|,
lastUpdated => 0,
context => q|List transaction workarea title.|
},
};
1;
}