added email receipt and "my purchases" page
This commit is contained in:
parent
93454e36f9
commit
74b3d3def6
10 changed files with 203 additions and 181 deletions
|
|
@ -121,12 +121,18 @@ sub www_editSettings {
|
|||
$form->submit;
|
||||
$form->hidden(name=>"shop", value=>"admin");
|
||||
$form->hidden(name=>"method", value=>"editSettingsSave");
|
||||
$form->group(
|
||||
name => "groupIdAdminCommerce",
|
||||
value => $setting->get("groupIdAdminCommerce"),
|
||||
label => $i18n->get('who can manage'),
|
||||
hoverHelp => $i18n->get('who can manage help'),
|
||||
);
|
||||
$form->template(
|
||||
name => "shopCartTemplateId",
|
||||
value => $setting->get("shopCartTemplateId"),
|
||||
label => $i18n->get("shopping cart template"),
|
||||
label => $i18n->get("cart template"),
|
||||
namespace => "Shop/Cart",
|
||||
hoverHelp => $i18n->get("shopping cart template help"),
|
||||
hoverHelp => $i18n->get("cart template help"),
|
||||
);
|
||||
$form->template(
|
||||
name => "shopAddressBookTemplateId",
|
||||
|
|
@ -172,11 +178,11 @@ sub www_editSettingsSave {
|
|||
my $self = shift;
|
||||
return $self->session->privilege->adminOnly() unless ($self->session->user->isInGroup("3"));
|
||||
my ($setting, $form) = $self->session->quick(qw(setting form));
|
||||
$setting->set("shopMyPurchasesDetailTemplateId", $form->get("shopMyPurchasesDetailTemplateId", "template"));
|
||||
$setting->set("shopMyPurchasesTemplateId", $form->get("shopMyPurchasesTemplateId", "template"));
|
||||
$setting->set("shopCartTemplateId", $form->get("shopCartTemplateId", "template"));
|
||||
$setting->set("shopAddressBookTemplateId", $form->get("shopAddressBookTemplateId", "template"));
|
||||
$setting->set("shopAddressTemplateId", $form->get("shopAddressTemplateId", "template"));
|
||||
foreach my $template (qw(shopMyPurchasesDetailTemplateId shopMyPurchasesTemplateId
|
||||
shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId)) {
|
||||
$setting->set($template, $form->get($template, "template"));
|
||||
}
|
||||
$setting->set("groupIdAdminCommerce", $form->get("groupIdAdminCommerce", "group"));
|
||||
return $self->www_editSettings();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -183,18 +183,11 @@ sub definition {
|
|||
},
|
||||
receiptEmailTemplateId => {
|
||||
fieldType => 'template',
|
||||
namespace => "Shop/ReceiptEmail",
|
||||
namespace => "Shop/EmailReceipt",
|
||||
label => $i18n->get("receipt email template"),
|
||||
hoverHelp => $i18n->get("receipt email template help"),
|
||||
defaultValue => '',
|
||||
},
|
||||
saleNotificationTemplateId => {
|
||||
namespace => "Shop/SaleEmail",
|
||||
fieldType => 'template',
|
||||
label => $i18n->get("sale notification template"),
|
||||
hoverHelp => $i18n->get("sale notification template help"),
|
||||
defaultValue => '',
|
||||
},
|
||||
saleNotificationGroupId => {
|
||||
fieldType => 'group',
|
||||
label => $i18n->get("sale notification group"),
|
||||
|
|
@ -232,6 +225,21 @@ sub delete {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 displayPaymentError ( transaction )
|
||||
|
||||
The default error message that gets displayed when a payment is rejected.
|
||||
|
||||
=cut
|
||||
|
||||
sub displayPaymentError {
|
||||
my ($self, $transaction) = @_;
|
||||
my $i18n = WebGUI::International->new($self->session, "PayDriver");
|
||||
my $output = q{<h1>}.$i18n->get('error processing payment').q{</h1><p>}.$i18n->get('error processing payment message').q{</p><p>}.$transaction->get('statusMessage').{</p>};
|
||||
return $self->session->style->userStyle($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ $param ] )
|
||||
|
||||
This is an enhanced accessor for the options property. By default,
|
||||
|
|
@ -521,7 +529,7 @@ sub processTransaction {
|
|||
if ($success) {
|
||||
$transaction->completePurchase($transactionCode, $statusCode, $statusMessage);
|
||||
$cart->onCompletePurchase;
|
||||
# $self->sendNotifications($transaction);
|
||||
$self->sendNotifications($transaction);
|
||||
}
|
||||
else {
|
||||
$transaction->denyPurchase($transactionCode, $statusCode, $statusMessage);
|
||||
|
|
@ -551,22 +559,86 @@ 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 %var = (); # this needs to be filled in with transaction data for these emails
|
||||
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'),
|
||||
}),
|
||||
);
|
||||
|
||||
my $i18n = WebGUI::International->new($session,'PayDriver');
|
||||
# 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;
|
||||
|
||||
# render
|
||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("receiptEmailTemplateId"));
|
||||
my $inbox = WebGUI::Inbox->new($session);
|
||||
$inbox->addMessage({
|
||||
|
||||
# purchase receipt
|
||||
$inbox->addMessage(
|
||||
message => $template->process(\%var),
|
||||
subject => $i18n->get('receipt subject').' '.$transaction->get('orderNumber'),
|
||||
userId => $transaction->get('userId'),
|
||||
subject => $i18n->get('thank you for your order'),
|
||||
message => WebGUI::Asset::Template->new($session, $self->get('receiptEmailTemplateId'))->process(\%var),
|
||||
status => 'completed',
|
||||
});
|
||||
$inbox->addMessage({
|
||||
);
|
||||
|
||||
# shop owner notification
|
||||
$var{viewDetailUrl} = $url->page('shop=transaction;method=view;transactionId='.$transaction->getId,1);
|
||||
$inbox->addMessage(
|
||||
message => $template->process(\%var),
|
||||
subject => $i18n->get('a sale has been made').' '.$transaction->get('orderNumber'),
|
||||
groupId => $self->get('saleNotificationGroupId'),
|
||||
subject => $i18n->get('a sale has been made'),
|
||||
message => WebGUI::Asset::Template->new($session, $self->get('saleNotificationTemplateId'))->process(\%var),
|
||||
status => 'completed',
|
||||
});
|
||||
status => 'unread',
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -28,32 +28,6 @@ sub definition {
|
|||
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
|
||||
|
||||
tie my %fields, 'Tie::IxHash';
|
||||
%fields = (
|
||||
sendReceipt => {
|
||||
fieldType => 'yesNo',
|
||||
label => $i18n->echo('send receipt'),
|
||||
hoverHelp => $i18n->echo('send receipt help'),
|
||||
defaultValue => 0,
|
||||
},
|
||||
receiptFromAddress => {
|
||||
fieldType => 'email',
|
||||
label => $i18n->echo('receipt from address'),
|
||||
hoverHelp => $i18n->echo('receipt from address help'),
|
||||
defaultValue => $session->setting->get('companyEmail'),
|
||||
},
|
||||
receiptSubject => {
|
||||
fieldType => 'text',
|
||||
label => $i18n->echo('receipt subject'),
|
||||
hoverHelp => $i18n->echo('receipt subject help'),
|
||||
},
|
||||
receiptTemplate => {
|
||||
fieldType => 'template',
|
||||
label => $i18n->echo('receipt template'),
|
||||
hoverHelp => $i18n->echo('receipt template help'),
|
||||
namespace => 'PayDriver/Cash/Receipt',
|
||||
defaultValue => undef,
|
||||
},
|
||||
);
|
||||
|
||||
push @{ $definition }, {
|
||||
name => $i18n->echo('Cash'),
|
||||
|
|
@ -88,44 +62,6 @@ sub getButton {
|
|||
return $payForm;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getCartTemplateVariables {
|
||||
my $self = shift;
|
||||
my $cart = $self->getCart;
|
||||
my @itemLoop;
|
||||
|
||||
# Process items in cart
|
||||
foreach my $item (@{ $cart->getItems }) {
|
||||
my $sku = $item->getSku;
|
||||
$sku->applyOptions( $item->get('options') );
|
||||
|
||||
# Item properties
|
||||
my $itemProperties = $item->get;
|
||||
$itemProperties->{ itemName } = $sku->get('title');
|
||||
$itemProperties->{ itemUrl } = $sku->getUrl;
|
||||
$itemProperties->{ itemPrice } = $cart->formatCurrency( $sku->getPrice );
|
||||
$itemProperties->{ totalItemPrice } = $cart->formatCurrency( $sku->getPrice * $item->get('quantity') );
|
||||
|
||||
# Custom item shipping address
|
||||
my $address = eval { $item->getShippingAddress };
|
||||
$itemProperties->{ itemShippingAddres } = $address->getHtmlFormatted unless (WebGUI::Error->caught);
|
||||
|
||||
push @itemLoop, $itemProperties;
|
||||
}
|
||||
|
||||
my $cartProperties = $cart->get;
|
||||
$cartProperties->{ totalPrice } = $cart->calculateSubtotal;
|
||||
$cartProperties->{ tax } = $cart->calculateTaxes;
|
||||
|
||||
# Include shipping address
|
||||
my $address = eval { $cart->getShippingAddress };
|
||||
$cartProperties->{ shippingAddress } = $address->getHtmlFormatted unless (WebGUI::Error->caught);
|
||||
# $cartProperties->{ shippingPrice } =
|
||||
|
||||
$cartProperties->{ item_loop } = \@itemLoop;
|
||||
|
||||
return $cartProperties;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -198,30 +134,8 @@ sub www_pay {
|
|||
my $billingAddress = $self->getAddress( $session->form->process('addressId') );
|
||||
return $self->www_getCredentials unless $billingAddress;
|
||||
|
||||
# Generate a receipt and send it if enabled.
|
||||
if ( $self->get('sendReceipt') ) {
|
||||
# Setup receipt tmpl_vars
|
||||
my $var = $self->getCartTemplateVariables;
|
||||
|
||||
# Instanciate receipt template
|
||||
my $template = WebGUI::Asset::Template->new( $session, $self->get('receiptTemplate') );
|
||||
WebGUI::Error::ObjectNotFound->throw( id => $self->get('receiptTemplate') )
|
||||
unless $template;
|
||||
|
||||
# Send receipt
|
||||
my $receipt = WebGUI::Mail::Send->create( $session, {
|
||||
to => $session->user->profileField('email'),
|
||||
from => $self->get('receiptFromAddress'),
|
||||
subject => $self->get('receiptSubject'),
|
||||
});
|
||||
$receipt->addText( $template->process( $var ) );
|
||||
$receipt->queue;
|
||||
}
|
||||
|
||||
|
||||
# Complete the transaction
|
||||
my $transaction = $self->processTransaction( $billingAddress );
|
||||
|
||||
return $transaction->thankYou();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -594,8 +594,10 @@ sub www_pay {
|
|||
|
||||
# Payment time!
|
||||
my $transaction = $self->processTransaction;
|
||||
|
||||
return $transaction->thankYou();
|
||||
if ($transaction->get('isSuccessful')) {
|
||||
return $transaction->thankYou();
|
||||
}
|
||||
return $self->displayPaymentError($transaction);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use WebGUI::Asset::Template;
|
|||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Inbox;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Shop::Admin;
|
||||
use WebGUI::Shop::AddressBook;
|
||||
|
|
@ -354,6 +355,27 @@ sub getPaymentGateway {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getTransactionIdsForUser (session, [ userId ])
|
||||
|
||||
Returns an array reference of transactionIds for a given user ordered by date descending. Class method.
|
||||
|
||||
=head3 userId
|
||||
|
||||
The id of the user to fetch transactions for. Defaults to the current user.
|
||||
|
||||
=cut
|
||||
|
||||
sub getTransactionIdsForUser {
|
||||
my ($class, $session, $userId) = @_;
|
||||
unless (defined $userId) {
|
||||
$userId = $session->user->userId;
|
||||
}
|
||||
return $session->db->buildArrayRef("select transactionId from transaction where userId=? order by dateOfPurchase desc",[$userId]);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session, transactionId )
|
||||
|
|
@ -437,8 +459,6 @@ sub newByGatewayId {
|
|||
return $class->new( $session, $transactionId );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 thankYou ()
|
||||
|
|
@ -745,6 +765,34 @@ STOP
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_manageMy ()
|
||||
|
||||
Makes transaction information printable.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_manageMy {
|
||||
my ($class, $session) = @_;
|
||||
my %var = ();
|
||||
my $url = $session->url;
|
||||
|
||||
# build list
|
||||
foreach my $id (@{$class->getTransactionIdsForUser($session)}) {
|
||||
my $transaction = $class->new($session, $id);
|
||||
push @{$var{transactions}}, {
|
||||
%{$transaction->get},
|
||||
viewDetailUrl => $url->page('shop=transaction;method=viewMy;transactionId='.$id),
|
||||
amount => sprintf("%.2f", $transaction->get('amount')),
|
||||
};
|
||||
}
|
||||
|
||||
# render
|
||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopMyPurchasesTemplateId"));
|
||||
return $session->style->userStyle($template->process(\%var));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_print ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue