Fix problems with the Sales tab in the Shop Account plugin.

Only display the Sales tab to vendors, and prevent www_viewSales from erroring out if the
user is not a vendor.  New template, template variable, i18n.
This commit is contained in:
Colin Kuskie 2010-01-18 08:51:17 -08:00
parent 022495506f
commit 1e7f443126
5 changed files with 36 additions and 21 deletions

View file

@ -8,6 +8,7 @@
- fixed #11348: Typ-o in debug notice SQLReport
- fixed #11350: Story Topic asset missing description...
- fixed #11351: Double submits on ITransact checkout
- fixed #11353: shop - sales - error
7.8.9
- fixed #11235: wiki search

View file

@ -6,6 +6,7 @@ use WebGUI::Exception;
use WebGUI::International;
use WebGUI::Pluggable;
use WebGUI::Utility;
use WebGUI::Shop::Vendor;
use JSON qw{ from_json };
use base qw/WebGUI::Account/;
@ -58,6 +59,10 @@ sub appendCommonVars {
$var->{ 'manage_tax_url' } = $self->getUrl( 'module=shop;do=manageTaxData' );
$var->{ 'manageTaxIsActive' } = $method eq 'manageTaxData';
eval { WebGUI::Shop::Vendor->newByUserId($session, $session->user->userId); };
$var->{ 'userIsVendor' } = ! Exception::Class->caught();
$session->log->warn($@);
}
#-------------------------------------------------------------------
@ -253,32 +258,35 @@ Page that show your earnings if you are a vendor.
sub www_viewSales {
my $self = shift;
my $session = $self->session;
my $vendor = WebGUI::Shop::Vendor->newByUserId( $session, $session->user->userId );
my $var = $vendor->getPayoutTotals;
my $totalSales = 0;
my $vendor = eval { WebGUI::Shop::Vendor->newByUserId( $session, $session->user->userId ); };
my @products;
my $totalSales = 0;
my $var = {};
if (! Exception::Class->caught()) {
my $sth = $session->db->read(
q{ SELECT t1.*, sum(t1.quantity) as quantity, sum(t1.vendorPayoutAmount) as payoutAmount }
. q{ FROM transactionItem as t1, transaction as t2 }
. q{ WHERE t1.transactionId=t2.transactionId AND t2.isSuccessful <> 0 }
. q{ AND vendorId=? }
. q{ group by assetId order by quantity desc },
[ $vendor->getId ]
);
while (my $row = $sth->hashRef) {
my $data = $row;
$var = $vendor->getPayoutTotals;
# Add asset properties to tmpl_vars.
my $asset = WebGUI::Asset->newByDynamicClass( $session, $row->{ assetId } );
$row = { %{ $row }, %{ $asset->get } } if $asset;
push @products, $row;
my $sth = $session->db->read(
q{ SELECT t1.*, sum(t1.quantity) as quantity, sum(t1.vendorPayoutAmount) as payoutAmount }
. q{ FROM transactionItem as t1, transaction as t2 }
. q{ WHERE t1.transactionId=t2.transactionId AND t2.isSuccessful <> 0 }
. q{ AND vendorId=? }
. q{ group by assetId order by quantity desc },
[ $vendor->getId ]
);
while (my $row = $sth->hashRef) {
my $data = $row;
$totalSales += $row->{quantity};
# Add asset properties to tmpl_vars.
my $asset = WebGUI::Asset->newByDynamicClass( $session, $row->{ assetId } );
$row = { %{ $row }, %{ $asset->get } } if $asset;
push @products, $row;
$totalSales += $row->{quantity};
}
$sth->finish;
}
$sth->finish;
$var->{ product_loop } = \@products;
$var->{ total_products } = scalar @products;

View file

@ -18,6 +18,7 @@ our $HELP = {
variables => [
{ name => "manage_purchases_url", },
{ name => "managePurchasesIsActive", },
{ name => "userIsVendor", },
],
related => [ ],
},

View file

@ -44,6 +44,11 @@ our $I18N = {
lastUpdated => 1119068809,
},
'userIsVendor' => {
message => q{A boolean that is true if the current user is a vendor.},
lastUpdated => 1263833421,
},
'common account variables' => {
message => q{Common Account, Shop Plugin, Template Variables.},
lastUpdated => 1230867169,