Magento
Print Customer's Group Name on the transactional emails
One
of our Magento clients uses different customer groups to offer
different price discounts on orders. When customers buy $100 worth of
products within a year they become bronze member with 5% discount on
future orders and Silver member if $200 or over and Gold if $300 and
over and they get discount accordingly.
Also
when they are auto upgraded to next level they are sent welcome
letter with member benefits. As pickers and packers won't know if
customer has been upgraded. So client wanted an email mentioning that
customer has been upgraded, so they can include booklet or something
with the order.
As
we have our custom module to upgrade customers depending on the
requirement. I need to do was just add extra functionality to send
email to picker and packers.
On
the Observer file (app/code/local/Technooze/Sales/Model/Observer.php)
of our upgrade module, I added this condition.
if
customer has been upgraded to next level then:
1
|
$this->sendGroupUpdateEmailToPickerPacker($customer,
$order);
|
And
then created function for that.
01
|
public
function
sendGroupUpdateEmailToPickerPacker($customer,
$order){
|
02
|
$storeId
=
Mage::app()->getStore()->getId();
|
03
|
$templateId
=
'group upgrade notification';
|
04
|
$emailTemplate
=
Mage::getModel('core/email_template')->loadByCode($templateId);
|
05
|
$vars
=
array(
|
06
|
'customer'
=>
$customer,
|
07
|
'order'
=>
$order
|
08
|
);
|
09
|
$emailTemplate->getProcessedTemplate($vars);
|
10
|
$emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email',
$storeId));
|
11
|
$emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_support/name',
$storeId));
|
12
|
$emailTemplate->send($this->_getEmails(Mage_Sales_Model_Order::XML_PATH_EMAIL_COPY_TO),
'Picker Packer', $vars);
|
15
|
protected
function
_getEmails($configPath)
|
16
|
{
|
17
|
$data
=
Mage::getStoreConfig($configPath,
Mage::app()->getStore()->getId());
|
18
|
if
(!empty($data))
{
|
19
|
return
explode(',',
$data);
|
20
|
}
|
Then
copied file: app/code/core/Mage/Sales/Model/Order.php
to app/code/local/Mage/Sales/Model/Order.php
And
added new function:
01
|
//
Get customer group name for email template.
|
02
|
public
function
getCustomerGroupName(){
|
03
|
if
($groupId
=
$this->getCustomerGroupId()){
|
04
|
$group
=
Mage::getModel ('customer/group')->load($groupId);
|
05
|
if
($group->getId()){
|
06
|
return
$group->getCode();
|
Now
you can add {{var
order.getCustomerGroupName()}}
on transactional emails to get group name e.g. on new order email
template app/locale/en_US/template/email/sales/order_new.html
But
I needed separated email, so created new transaction email at:
Magento
admin / System / Transactional Emails
Template
Name
*: group upgrade notificationTemplate
Subject
*: group upgrade notificationTemplate
Content
*:
01
|
<body
style="background:#F6F6F6; font-family:Verdana, Arial,
Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
|
02
|
<div
style="background:#F6F6F6; font-family:Verdana, Arial,
Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
|
03
|
<table
cellspacing="0"
cellpadding="0"
border="0"
width="100%">
|
04
|
<tr>
|
05
|
<td
align="center"
valign="top"
style="padding:20px
0 20px 0">
|
06
|
<table
bgcolor="#FFFFFF"
cellspacing="0"
cellpadding="10"
border="0"
width="650"
style="border:1px
solid #E0E0E0;">
|
07
|
<!--
[ header starts here] -->
|
08
|
<tr>
|
09
|
<td
valign="top"><a href="{{store url=""}}"><img
src="{{var logo_url}}"
alt="{{var
logo_alt}}"
style="margin-bottom:10px;"
border="0"/></a></td>
|
10
|
</tr>
|
11
|
<!--
[ middle starts here] -->
|
12
|
<tr>
|
13
|
<td
valign="top">
|
14
|
<h1
style="font-size:22px; font-weight:normal; line-height:22px;
margin:0 0 11px 0;"">{{htmlescape
var=$order.getCustomerName()}} has been upgraded to <b>{{var
order.getCustomerGroupName()}}</b></h1>
|
17
|
<td>
|
18
|
<h2
style="font-size:18px; font-weight:normal; margin:0;">Last
Order #{{var
order.increment_id}}
<small>(placed on {{var
order.getCreatedAtFormated('long')}})</small></h2>
|
23
|
<table
cellspacing="0"
cellpadding="0"
border="0"
width="650">
|
24
|
<thead>
|
25
|
<tr>
|
26
|
<th
align="left"
width="325"
bgcolor="#EAEAEA"
style="font-size:13px;
padding:5px 9px 6px 9px; line-height:1em;">Billing
Information:</th>
|
27
|
<th
width="10"></th>
|
28
|
{{depend
order.getIsNotVirtual()}}
|
29
|
<th
align="left"
width="325"
bgcolor="#EAEAEA"
style="font-size:13px;
padding:5px 9px 6px 9px; line-height:1em;">Shipping
Address:</th>
|
30
|
{{/depend}}
|
35
|
<td
valign="top"
style="font-size:12px;
padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA;
border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
|
36
|
{{var
order.getBillingAddress().format('html')}}
|
37
|
</td>
|
38
|
<td> </td>
|
39
|
{{depend
order.getIsNotVirtual()}}
|
40
|
<td
valign="top"
style="font-size:12px;
padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA;
border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;">
|
41
|
{{var
order.getShippingAddress().format('html')}}
|
42
|
</td>
|
And
the result email is:
No comments:
Post a Comment