From b7840e7ed9492c567a2d730afd17f3914605b4b4 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 20 May 2008 22:14:55 +0000 Subject: [PATCH] added a very basic in shop credit manager screen --- lib/WebGUI/Content/Shop.pm | 23 +++++++++++++ lib/WebGUI/Shop/Admin.pm | 1 + lib/WebGUI/Shop/Credit.pm | 57 ++++++++++++++++++++++++++++++++- lib/WebGUI/Shop/Transaction.pm | 3 +- lib/WebGUI/i18n/English/Shop.pm | 12 +++++++ 5 files changed, 93 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Content/Shop.pm b/lib/WebGUI/Content/Shop.pm index c69d834d9..fb00abce2 100644 --- a/lib/WebGUI/Content/Shop.pm +++ b/lib/WebGUI/Content/Shop.pm @@ -19,6 +19,7 @@ use WebGUI::AdminConsole; use WebGUI::Exception::Shop; use WebGUI::Shop::AddressBook; use WebGUI::Shop::Cart; +use WebGUI::Shop::Credit; use WebGUI::Shop::Pay; use WebGUI::Shop::Ship; use WebGUI::Shop::Tax; @@ -142,6 +143,28 @@ sub www_cart { return $output; } + +#------------------------------------------------------------------- + +=head2 www_credit () + +Hand off to the credit system. + +=cut + +sub www_credit { + my $session = shift; + my $output = undef; + my $method = "www_".$session->form->get("method"); + if ($method ne "www_" && WebGUI::Shop::Credit->can($method)) { + $output = WebGUI::Shop::Credit->$method($session); + } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } + return $output; +} + #------------------------------------------------------------------- =head2 www_pay () diff --git a/lib/WebGUI/Shop/Admin.pm b/lib/WebGUI/Shop/Admin.pm index da87d6932..9635a2d55 100644 --- a/lib/WebGUI/Shop/Admin.pm +++ b/lib/WebGUI/Shop/Admin.pm @@ -68,6 +68,7 @@ sub getAdminConsole { $ac->addSubmenuItem($url->page("shop=ship;method=manage"), $i18n->get("shipping methods")); $ac->addSubmenuItem($url->page("shop=transaction;method=manage"), $i18n->get("transactions")); $ac->addSubmenuItem($url->page("shop=vendor;method=manage"), $i18n->get("vendors")); + $ac->addSubmenuItem($url->page("shop=credit;method=manage"), $i18n->get("in shop credit")); return $ac; } diff --git a/lib/WebGUI/Shop/Credit.pm b/lib/WebGUI/Shop/Credit.pm index 84717f5a7..d08f2214e 100644 --- a/lib/WebGUI/Shop/Credit.pm +++ b/lib/WebGUI/Shop/Credit.pm @@ -5,7 +5,8 @@ use Class::InsideOut qw{ :std }; use WebGUI::Shop::Admin; use WebGUI::Exception::Shop; use WebGUI::International; - +use WebGUI::HTMLForm; +use WebGUI::User; =head1 NAME @@ -166,5 +167,59 @@ Returns a reference to the userId. +#------------------------------------------------------------------- + +=head2 www_adjust + +Adjust credit for a user. + +=cut + +sub www_adjust { + my ($class, $session) = @_; + my $admin = WebGUI::Shop::Admin->new($session); + return $session->privilege->insufficient() unless $admin->canManage; + my $form = $session->form; + my $credit = $class->new($session, $form->get('userId')); + $credit->adjust($form->get('amount'), $form->get('comment')); + my $i18n = WebGUI::International->new($session, "Shop"); + my $message = sprintf $i18n->get('add credit message'), $form->get('amount'), WebGUI::User->new($session, $form->get('userId'))->username, $credit->getSum; + return $class->www_manage($session, $message); +} + +#------------------------------------------------------------------- + +=head2 www_manage + +Displays a credit management interface. + +=cut + +sub www_manage { + my ($class, $session, $message) = @_; + my $admin = WebGUI::Shop::Admin->new($session); + return $session->privilege->insufficient() unless $admin->canManage; + my $i18n = WebGUI::International->new($session, "Shop"); + my $f = WebGUI::HTMLForm->new($session); + $f->hidden(name=>'shop',value=>'credit'); + $f->hidden(name=>'method',value=>'adjust'); + $f->user( + name => 'userId', + label => $i18n->get('username'), + value => $session->user->userId, + ); + $f->float( + name => 'amount', + label => $i18n->get('amount'), + ); + $f->text( + name => 'comment', + label => $i18n->get('notes'), + ); + $f->submit; + return $admin->getAdminConsole->render($message.$f->print, $i18n->get('in shop credit')); +} + + 1; diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index c25910a7f..8a71584be 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -696,7 +696,7 @@ sub www_view { }. $i18n->get("username") .q{}. $transaction->get('username') .q{ - }. $i18n->get("price") .q{}. sprintf("%.2f", $transaction->get('amount')) .q{ + }. $i18n->get("amount") .q{}. sprintf("%.2f", $transaction->get('amount')) .q{ }. $i18n->get("in shop credit used") .q{}. sprintf("%.2f", $transaction->get('shopCreditDeduction')) .q{ @@ -846,7 +846,6 @@ sub www_view { }; - # send output if ($print) { return $output; diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 01e6944dd..22ef2f66c 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -105,6 +105,18 @@ our $I18N = { context => q|field label| }, + 'add credit message' => { + message => q|%s was added to %s's in-shop credit account, for a total credit of %s.|, + lastUpdated => 0, + context => q|field label| + }, + + 'amount' => { + message => q|Amount|, + lastUpdated => 0, + context => q|field label| + }, + 'notes' => { message => q|Notes|, lastUpdated => 0,