Move email notifications about of PayDriver and into Transaction.  Send
a notification when the cart value is 0 due to shop credit.
This commit is contained in:
Colin Kuskie 2009-10-13 16:37:20 -07:00
parent e46ad0d8fd
commit b3858ef250
12 changed files with 206 additions and 150 deletions

View file

@ -194,6 +194,19 @@ sub www_editSettings {
label => $i18n->get("my purchases detail template"),
hoverHelp => $i18n->get("my purchases detail template help"),
);
$form->template(
name => 'receiptEmailTemplateId',
namespace => "Shop/EmailReceipt",
label => $i18n->get("receipt email template"),
hoverHelp => $i18n->get("receipt email template help"),
defaultValue => 'bPz1yk6Y9uwMDMBcmMsSCg',
);
$form->group(
name => 'saleNotificationGroupId',
label => $i18n->get("sale notification group"),
hoverHelp => $i18n->get("sale notification group help"),
defaultValue => '3',
);
$form->submit;
return $ac->render($form->print, $i18n->get("shop settings"));
}
@ -213,12 +226,12 @@ sub www_editSettingsSave {
# Save shop templates
foreach my $template (qw(shopMyPurchasesDetailTemplateId shopMyPurchasesTemplateId
shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId)) {
shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId shopReceiptEmailTemplateId)) {
$setting->set($template, $form->get($template, "template"));
}
# Save group settings
foreach my $group (qw(groupIdCashier groupIdAdminCommerce)) {
foreach my $group (qw(groupIdCashier groupIdAdminCommerce shopSaleNotificationGroupId)) {
$setting->set($group, $form->get($group, "group"));
}

View file

@ -413,6 +413,7 @@ sub www_selectPaymentGateway {
my $transaction = WebGUI::Shop::Transaction->create($session, {cart => $cart});
$transaction->completePurchase('zero', 'success', 'success');
$cart->onCompletePurchase;
$transaction->sendNotifications();
return $transaction->thankYou();
}

View file

@ -237,19 +237,6 @@ sub definition {
hoverHelp => $i18n->get('who can use help'),
defaultValue => 7,
},
receiptEmailTemplateId => {
fieldType => 'template',
namespace => "Shop/EmailReceipt",
label => $i18n->get("receipt email template"),
hoverHelp => $i18n->get("receipt email template help"),
defaultValue => 'bPz1yk6Y9uwMDMBcmMsSCg',
},
saleNotificationGroupId => {
fieldType => 'group',
label => $i18n->get("sale notification group"),
hoverHelp => $i18n->get("sale notification group help"),
defaultValue => '3',
},
);
my %properties = (
@ -662,7 +649,7 @@ sub processTransaction {
if ($success) {
$transaction->completePurchase($transactionCode, $statusCode, $statusMessage);
$cart->onCompletePurchase;
$self->sendNotifications($transaction);
$transaction->sendNotifications();
}
else {
$transaction->denyPurchase($transactionCode, $statusCode, $statusMessage);
@ -680,49 +667,6 @@ Accessor for the session object. Returns the session object.
=cut
#-------------------------------------------------------------------
=head2 sendNotifications ( transaction )
Sends out a receipt and a sale notification to the buyer and the store owner respectively.
=cut
sub sendNotifications {
my ($self, $transaction) = @_;
my $session = $self->session;
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 );
WebGUI::Macro::process($session, \$receipt);
# purchase receipt
$inbox->addMessage( {
message => $receipt,
subject => $i18n->get('receipt subject') . ' ' . $transaction->get('orderNumber'),
userId => $transaction->get('userId'),
status => 'completed',
} );
# shop owner notification
# 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'),
groupId => $self->get('saleNotificationGroupId'),
status => 'unread',
} );
}
#-------------------------------------------------------------------
=head2 update ( $options )

View file

@ -619,6 +619,48 @@ sub newByGatewayId {
#-------------------------------------------------------------------
=head2 sendNotifications ( transaction )
Sends out a receipt and a sale notification to the buyer and the store owner respectively.
=cut
sub sendNotifications {
my ($self) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'PayDriver');
my $url = $session->url;
my $var = $self->getTransactionVars;
# render
my $template = WebGUI::Asset::Template->new( $session, $session->setting->get("shopReceiptEmailTemplateId") );
my $inbox = WebGUI::Inbox->new($session);
my $receipt = $template->process( $var );
WebGUI::Macro::process($session, \$receipt);
# purchase receipt
$inbox->addMessage( {
message => $receipt,
subject => $i18n->get('receipt subject') . ' ' . $self->get('orderNumber'),
userId => $self->get('userId'),
status => 'completed',
} );
# shop owner notification
# Shop owner uses method=view rather than method=viewMy
$var->{viewDetailUrl} = $url->page( 'shop=transaction;method=view;transactionId='.$self->getId, 1 );
my $notification = $template->process( $var );
WebGUI::Macro::process($session, \$notification);
$inbox->addMessage( {
message => $notification,
subject => $i18n->get('a sale has been made') . ' ' . $self->get('orderNumber'),
groupId => $session->setting->get('shopSaleNotificationGroupId'),
status => 'unread',
} );
}
#-------------------------------------------------------------------
=head2 thankYou ()
Displays the default thank you page.

View file

@ -15,12 +15,6 @@ our $I18N = {
context => q|commerce setting|
},
'sale notification group' => {
message => q|Sale Notification Group|,
lastUpdated => 0,
context => q|commerce setting|
},
'error processing payment' => {
message => q|Error Processing Payment|,
lastUpdated => 0,
@ -33,24 +27,6 @@ our $I18N = {
context => q|the description on the error screen|
},
'sale notification group help' => {
message => q|Who should be notified of new transactions?|,
lastUpdated => 0,
context => q|commerce setting help|
},
'receipt email template' => {
message => q|Receipt Email Template|,
lastUpdated => 0,
context => q|commerce setting|
},
'receipt email template help' => {
message => q|Which template should be used to generate an email that will be sent to the user to acknowledge their purchase?|,
lastUpdated => 0,
context => q|commerce setting help|
},
'label' => {
message => q|Label|,
lastUpdated => 0,

View file

@ -1671,6 +1671,31 @@ our $I18N = {
context => q|Label to make the user choose a shipping method|,
},
'receipt email template' => {
message => q|Receipt Email Template|,
lastUpdated => 0,
context => q|commerce setting|
},
'receipt email template help' => {
message => q|Which template should be used to generate an email that will be sent to the user to acknowledge their purchase?|,
lastUpdated => 0,
context => q|commerce setting help|
},
'sale notification group' => {
message => q|Sale Notification Group|,
lastUpdated => 0,
context => q|commerce setting|
},
'sale notification group help' => {
message => q|Who should be notified of new transactions?|,
lastUpdated => 0,
context => q|commerce setting help|
},
};
1;