Refactored genereation of tranasaction related tmpl_vars into WG::Shop::Transaction->getTransactionVars.
This commit is contained in:
parent
d432d1e115
commit
31c4bf83d7
4 changed files with 114 additions and 150 deletions
|
|
@ -283,95 +283,17 @@ sub www_viewTransaction {
|
|||
my $session = $self->session;
|
||||
|
||||
my $transactionId = $session->form->get('transactionId');
|
||||
my $transaction = shift || WebGUI::Shop::Transaction->new($session,$transactionId);
|
||||
my $transaction = shift || WebGUI::Shop::Transaction->new( $session,$transactionId );
|
||||
my $notice = shift;
|
||||
|
||||
return $session->insufficient unless ($transaction->get('userId') eq $session->user->userId);
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'Shop');
|
||||
my ($style, $url) = $session->quick(qw(style url));
|
||||
|
||||
my %var = (
|
||||
%{$transaction->get},
|
||||
notice => $notice,
|
||||
cancelRecurringUrl => $url->page('shop=transaction;method=cancelRecurring;transactionId='.$transaction->getId),
|
||||
amount => sprintf("%.2f", $transaction->get('amount')),
|
||||
inShopCreditDeduction => sprintf("%.2f", $transaction->get('inShopCreditDeduction')),
|
||||
taxes => sprintf("%.2f", $transaction->get('taxes')),
|
||||
shippingPrice => sprintf("%.2f", $transaction->get('shippingPrice')),
|
||||
shippingAddress => $transaction->formatAddress({
|
||||
name => $transaction->get('shippingAddressName'),
|
||||
address1 => $transaction->get('shippingAddress1'),
|
||||
address2 => $transaction->get('shippingAddress2'),
|
||||
address3 => $transaction->get('shippingAddress3'),
|
||||
city => $transaction->get('shippingCity'),
|
||||
state => $transaction->get('shippingState'),
|
||||
code => $transaction->get('shippingCode'),
|
||||
country => $transaction->get('shippingCountry'),
|
||||
phoneNumber => $transaction->get('shippingPhoneNumber'),
|
||||
}),
|
||||
paymentAddress => $transaction->formatAddress({
|
||||
name => $transaction->get('paymentAddressName'),
|
||||
address1 => $transaction->get('paymentAddress1'),
|
||||
address2 => $transaction->get('paymentAddress2'),
|
||||
address3 => $transaction->get('paymentAddress3'),
|
||||
city => $transaction->get('paymentCity'),
|
||||
state => $transaction->get('paymentState'),
|
||||
code => $transaction->get('paymentCode'),
|
||||
country => $transaction->get('paymentCountry'),
|
||||
phoneNumber => $transaction->get('paymentPhoneNumber'),
|
||||
}),
|
||||
);
|
||||
|
||||
# items
|
||||
my @items = ();
|
||||
foreach my $item (@{$transaction->getItems}) {
|
||||
my $address = '';
|
||||
if ($transaction->get('shippingAddressId') ne $item->get('shippingAddressId')) {
|
||||
$address = $transaction->formatAddress({
|
||||
name => $item->get('shippingAddressName'),
|
||||
address1 => $item->get('shippingAddress1'),
|
||||
address2 => $item->get('shippingAddress2'),
|
||||
address3 => $item->get('shippingAddress3'),
|
||||
city => $item->get('shippingCity'),
|
||||
state => $item->get('shippingState'),
|
||||
code => $item->get('shippingCode'),
|
||||
country => $item->get('shippingCountry'),
|
||||
phoneNumber => $item->get('shippingPhoneNumber'),
|
||||
});
|
||||
}
|
||||
|
||||
# Post purchase actions
|
||||
my $actionsLoop = [];
|
||||
my $actions = $item->getSku->getPostPurchaseActions( $item );
|
||||
for my $label ( keys %{$actions} ) {
|
||||
push @{$actionsLoop}, {
|
||||
label => $label,
|
||||
url => $actions->{$label},
|
||||
}
|
||||
}
|
||||
|
||||
my %taxConfiguration = %{ from_json( $item->get( 'taxConfiguration' ) || '{}' ) };
|
||||
my %taxVars =
|
||||
map { ( "tax_$_" => $taxConfiguration{ $_ } ) }
|
||||
keys %taxConfiguration;
|
||||
|
||||
push @items, {
|
||||
%{ $item->get },
|
||||
%taxVars,
|
||||
viewItemUrl => $url->page('shop=transaction;method=viewItem;transactionId='.$transaction->getId.';itemId='.$item->getId),
|
||||
price => sprintf("%.2f", $item->get('price')),
|
||||
itemShippingAddress => $address,
|
||||
orderStatus => $i18n->get($item->get('orderStatus')),
|
||||
actionsLoop => $actionsLoop,
|
||||
};
|
||||
}
|
||||
$var{items} = \@items;
|
||||
|
||||
$self->appendCommonVars(\%var);
|
||||
return $session->insufficient unless $transaction->get('userId') eq $session->user->userId;
|
||||
|
||||
my $var = $transaction->getTransactionVars;
|
||||
$var->{ notice } = $notice;
|
||||
$self->appendCommonVars( $var );
|
||||
|
||||
# render
|
||||
return $self->processTemplate(\%var,$session->setting->get("shopMyPurchasesDetailTemplateId"));
|
||||
return $self->processTemplate( $var, $session->setting->get('shopMyPurchasesDetailTemplateId') );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -673,87 +673,32 @@ Sends out a receipt and a sale notification to the buyer and the store owner res
|
|||
sub sendNotifications {
|
||||
my ($self, $transaction) = @_;
|
||||
my $session = $self->session;
|
||||
my $i18n = WebGUI::International->new($session, 'PayDriver');
|
||||
my ($style, $url) = $session->quick(qw(style url));
|
||||
my %var = (
|
||||
%{$transaction->get},
|
||||
viewDetailUrl => $url->page('shop=transaction;method=viewMy;transactionId='.$transaction->getId,1),
|
||||
amount => sprintf("%.2f", $transaction->get('amount')),
|
||||
inShopCreditDeduction => sprintf("%.2f", $transaction->get('inShopCreditDeduction')),
|
||||
taxes => sprintf("%.2f", $transaction->get('taxes')),
|
||||
shippingPrice => sprintf("%.2f", $transaction->get('shippingPrice')),
|
||||
shippingAddress => $transaction->formatAddress({
|
||||
name => $transaction->get('shippingAddressName'),
|
||||
address1 => $transaction->get('shippingAddress1'),
|
||||
address2 => $transaction->get('shippingAddress2'),
|
||||
address3 => $transaction->get('shippingAddress3'),
|
||||
city => $transaction->get('shippingCity'),
|
||||
state => $transaction->get('shippingState'),
|
||||
code => $transaction->get('shippingCode'),
|
||||
country => $transaction->get('shippingCountry'),
|
||||
phoneNumber => $transaction->get('shippingPhoneNumber'),
|
||||
}),
|
||||
paymentAddress => $transaction->formatAddress({
|
||||
name => $transaction->get('paymentAddressName'),
|
||||
address1 => $transaction->get('paymentAddress1'),
|
||||
address2 => $transaction->get('paymentAddress2'),
|
||||
address3 => $transaction->get('paymentAddress3'),
|
||||
city => $transaction->get('paymentCity'),
|
||||
state => $transaction->get('paymentState'),
|
||||
code => $transaction->get('paymentCode'),
|
||||
country => $transaction->get('paymentCountry'),
|
||||
phoneNumber => $transaction->get('paymentPhoneNumber'),
|
||||
}),
|
||||
);
|
||||
|
||||
# items
|
||||
my @items = ();
|
||||
foreach my $item (@{$transaction->getItems}) {
|
||||
my $address = '';
|
||||
if ($transaction->get('shippingAddressId') ne $item->get('shippingAddressId')) {
|
||||
$address = $transaction->formatAddress({
|
||||
name => $item->get('shippingAddressName'),
|
||||
address1 => $item->get('shippingAddress1'),
|
||||
address2 => $item->get('shippingAddress2'),
|
||||
address3 => $item->get('shippingAddress3'),
|
||||
city => $item->get('shippingCity'),
|
||||
state => $item->get('shippingState'),
|
||||
code => $item->get('shippingCode'),
|
||||
country => $item->get('shippingCountry'),
|
||||
phoneNumber => $item->get('shippingPhoneNumber'),
|
||||
});
|
||||
}
|
||||
push @items, {
|
||||
%{$item->get},
|
||||
viewItemUrl => $url->page('shop=transaction;method=viewItem;transactionId='.$transaction->getId.';itemId='.$item->getId, 1),
|
||||
price => sprintf("%.2f", $item->get('price')),
|
||||
itemShippingAddress => $address,
|
||||
orderStatus => $i18n->get($item->get('orderStatus'),'Shop'),
|
||||
};
|
||||
}
|
||||
$var{items} = \@items;
|
||||
my $i18n = WebGUI::International->new($session, 'PayDriver');
|
||||
my $url = $session->url;
|
||||
my $var = $transaction->getTransactionVars;
|
||||
|
||||
# render
|
||||
my $template = WebGUI::Asset::Template->new( $session, $self->get("receiptEmailTemplateId") );
|
||||
my $inbox = WebGUI::Inbox->new($session);
|
||||
my $receipt = $template->process(\%var);
|
||||
my $receipt = $template->process( $var );
|
||||
WebGUI::Macro::process($session, \$receipt);
|
||||
|
||||
# purchase receipt
|
||||
$inbox->addMessage( {
|
||||
message => $receipt,
|
||||
subject => $i18n->get('receipt subject').' '.$transaction->get('orderNumber'),
|
||||
subject => $i18n->get('receipt subject') . ' ' . $transaction->get('orderNumber'),
|
||||
userId => $transaction->get('userId'),
|
||||
status => 'completed',
|
||||
} );
|
||||
|
||||
# shop owner notification
|
||||
$var{viewDetailUrl} = $url->page('shop=transaction;method=view;transactionId='.$transaction->getId,1);
|
||||
my $notification = $template->process(\%var);
|
||||
# Shop owner uses method=view rather than method=viewMy
|
||||
$var->{viewDetailUrl} = $url->page( 'shop=transaction;method=view;transactionId='.$transaction->getId, 1 );
|
||||
my $notification = $template->process( $var );
|
||||
WebGUI::Macro::process($session, \$notification);
|
||||
$inbox->addMessage( {
|
||||
message => $notification,
|
||||
subject => $i18n->get('a sale has been made').' '.$transaction->get('orderNumber'),
|
||||
subject => $i18n->get('a sale has been made') . ' ' . $transaction->get('orderNumber'),
|
||||
groupId => $self->get('saleNotificationGroupId'),
|
||||
status => 'unread',
|
||||
} );
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package WebGUI::Shop::Transaction;
|
|||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use JSON;
|
||||
use JSON qw{ from_json };
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Form;
|
||||
|
|
@ -395,6 +395,102 @@ sub getTransactionIdsForUser {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub getTransactionVars {
|
||||
my $self = shift;
|
||||
my $url = $self->session->url;
|
||||
my $i18n = WebGUI::International->new( $self->session, 'Shop' );
|
||||
|
||||
my $var = {
|
||||
%{ $self->get },
|
||||
viewDetailUrl => $url->page( 'shop=transaction;method=viewMy;transactionId='.$self->getId, 1 ),
|
||||
cancelRecurringUrl => $url->page('shop=transaction;method=cancelRecurring;transactionId='.$self->getId),
|
||||
amount => sprintf( "%.2f", $self->get('amount') ),
|
||||
inShopCreditDeduction => sprintf( "%.2f", $self->get('inShopCreditDeduction') ),
|
||||
taxes => sprintf( "%.2f", $self->get('taxes') ),
|
||||
shippingPrice => sprintf( "%.2f", $self->get('shippingPrice') ),
|
||||
shippingAddress => $self->formatAddress( {
|
||||
name => $self->get('shippingAddressName'),
|
||||
address1 => $self->get('shippingAddress1'),
|
||||
address2 => $self->get('shippingAddress2'),
|
||||
address3 => $self->get('shippingAddress3'),
|
||||
city => $self->get('shippingCity'),
|
||||
state => $self->get('shippingState'),
|
||||
code => $self->get('shippingCode'),
|
||||
country => $self->get('shippingCountry'),
|
||||
phoneNumber => $self->get('shippingPhoneNumber'),
|
||||
} ),
|
||||
paymentAddress => $self->formatAddress({
|
||||
name => $self->get('paymentAddressName'),
|
||||
address1 => $self->get('paymentAddress1'),
|
||||
address2 => $self->get('paymentAddress2'),
|
||||
address3 => $self->get('paymentAddress3'),
|
||||
city => $self->get('paymentCity'),
|
||||
state => $self->get('paymentState'),
|
||||
code => $self->get('paymentCode'),
|
||||
country => $self->get('paymentCountry'),
|
||||
phoneNumber => $self->get('paymentPhoneNumber'),
|
||||
} ),
|
||||
};
|
||||
|
||||
# items
|
||||
my @items = ();
|
||||
foreach my $item (@{$self->getItems}) {
|
||||
my $address = '';
|
||||
if ($self->get('shippingAddressId') ne $item->get('shippingAddressId')) {
|
||||
$address = $self->formatAddress({
|
||||
name => $item->get('shippingAddressName'),
|
||||
address1 => $item->get('shippingAddress1'),
|
||||
address2 => $item->get('shippingAddress2'),
|
||||
address3 => $item->get('shippingAddress3'),
|
||||
city => $item->get('shippingCity'),
|
||||
state => $item->get('shippingState'),
|
||||
code => $item->get('shippingCode'),
|
||||
country => $item->get('shippingCountry'),
|
||||
phoneNumber => $item->get('shippingPhoneNumber'),
|
||||
});
|
||||
}
|
||||
|
||||
# Post purchase actions
|
||||
my $actionsLoop = [];
|
||||
my $actions = $item->getSku->getPostPurchaseActions( $item );
|
||||
for my $label ( keys %{$actions} ) {
|
||||
push @{$actionsLoop}, {
|
||||
label => $label,
|
||||
url => $actions->{$label},
|
||||
}
|
||||
}
|
||||
|
||||
my %taxConfiguration = %{ from_json( $item->get( 'taxConfiguration' ) || '{}' ) };
|
||||
my %taxVars =
|
||||
map { ( "tax_$_" => $taxConfiguration{ $_ } ) }
|
||||
keys %taxConfiguration;
|
||||
|
||||
my $price = $item->get('price');
|
||||
my $quantity = $item->get('quantity');
|
||||
my $taxRate = $item->get('taxRate');
|
||||
my $taxAmount = $price * $taxRate / 100;
|
||||
|
||||
push @items, {
|
||||
%{$item->get},
|
||||
%taxVars,
|
||||
viewItemUrl => $url->page('shop=transaction;method=viewItem;transactionId='.$self->getId.';itemId='.$item->getId, 1),
|
||||
price => sprintf("%.2f", $item->get('price')),
|
||||
pricePlusTax => sprintf( "%.2f", $price + $taxAmount ),
|
||||
extendedPrice => sprintf( "%.2f", $quantity * $price ),
|
||||
extendedPricePlusTax => sprintf( "%.2f", $quantity * ( $price + $taxAmount ) ),
|
||||
itemShippingAddress => $address,
|
||||
orderStatus => $i18n->get( $item->get('orderStatus'), 'Shop' ),
|
||||
actionsLoop => $actionsLoop,
|
||||
};
|
||||
}
|
||||
$var->{items} = \@items;
|
||||
|
||||
return $var;
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isFirst ( )
|
||||
|
||||
Returns 1 if this is the first of a set of recurring transactions.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue