News:

Looking for documentation? Take a look on our wiki

Main Menu

[SOLVED] Mail_html alteration to allow for Description inclusion

Started by WebStuff, June 11, 2013, 13:26:49 PM

Previous topic - Next topic

WebStuff

I've made an alteration to the standard mail_html.php file as I didn't see the point of sending a complete copy of the whole invoice every time an order status was updated.
This now sends a shorter email stating the change in status plus the message in the Description field of the Configuration->Order Statuses option.
Orders Statuses that receive full emails can be added to this line 68:
$receive_full_mail_statuses = array("C", "X", "P");
Thought I'd post it in case it was useful to anyone else.

Here's the full code.:
<?php
/**
 *
 * Layout for the shopper mail, when they have confirmed an order
 *
 * The addresses are reachable with $this->BTaddress, take a look for an example at shopper_addresses.php
 *
 * With $this->orderDetails['shipmentName'] or paymentName, you get the name of the used paymentmethod/shipmentmethod
 *
 * In the array order you have details and items ($this->orderDetails['details']), the items gather the products, but that is done directly from the cart data
 *
 * $this->orderDetails['details'] contains the raw address data (use the formatted ones, like BTaddress). Interesting information here is,
 * order_number ($this->orderDetails['details']['BT']->order_number), order_pass, coupon_code, order_status, order_status_name,
 * user_currency_rate, created_on, customer_note, ip_address
 *
 * @package VirtueMart
 * @subpackage Cart
 * @author Max Milbers, Valerie Isaksen
 *
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 *
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
?>


<html>
<head>
<style type="text/css">
body, td, span, p, th {  }
table.html-email {margin:2px auto;background:#fff;border:solid #dad8d8 1px;font-size: 16px;}
.html-email tr{border-bottom : 1px solid #eee;}
span.grey {color:#666;}
span.date {color:#666; }
a.default:link, a.default:hover, a.default:visited {color:#666;line-height:25px;background: #f2f2f2;margin: 10px ;padding: 3px 8px 1px 8px;border: solid #CAC9C9 1px;border-radius: 4px;-webkit-border-radius: 4px;-moz-border-radius: 4px;text-shadow: 1px 1px 1px #f2f2f2;font-size: 12px;background-position: 0px 0px;display: inline-block;text-decoration: none;}
a.default:hover {color:#888;background: #f8f8f8;}
.cart-summary{ }
.html-email th { background: #ccc;margin: 0px;padding: 2px;}
.sectiontableentry2, .html-email th, .cart-summary th{ background: #ccc;margin: 0px;padding: 10px;}
.sectiontableentry1, .html-email td, .cart-summary td {background: #fff;margin: 0px;padding: 0px;}
.line-through{text-decoration:line-through}
</style>

</head>

<body style="background: #F2F2F2;word-wrap: break-word;">
<div style="background-color: #e6e6e6;" width="100%">
<table style="margin: auto;" cellpadding="0" cellspacing="0" width="100%" >
<tr><td>
<?php
// Shop desc for shopper and vendor
echo $this->loadTemplate('header');
$cur_order_status $this->orderDetails['details']['BT']->order_status;
$cur_order_no $this->orderDetails['details']['BT']->order_number;
$db JFactory::getDBO();
$qrydata "SELECT order_status_description FROM #__virtuemart_orderstates WHERE order_status_code ='".$cur_order_status."'";
$db->setQuery($qrydata);
$db->query();
$order_status_description $db->loadResult();

// ADD ORDER STATE LETTERS TO THIS ARRAY WILL SHOW FULL EMAIL
$receive_full_mail_statuses = array("C""X""P");
if( in_array($cur_order_status$receive_full_mail_statuses) ) {
// Message for shopper or vendor
echo $this->loadTemplate($this->recipient);
// render shipto billto adresses
echo $this->loadTemplate('shopperaddresses');
// render price list
echo $this->loadTemplate('pricelist');
// more infos
echo $this->loadTemplate($this->recipient '_more');
// end of mail
}
else {
echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
switch ($cur_order_status) {
// STANDARD VM2 ORDER STATUSES
case "C";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_CONFIRMED") );
break;
}
case "X";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_CANCELLED") );
break;
}
case "P";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_PENDING") );
break;
}
case "R";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_REFUNDED") );
break;
}
case "S";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_SHIPPED") );
break;
}
case "U";
{
echo strtoupperJText::_("COM_VIRTUEMART_ORDER_STATUS_CONFIRMED_BY_SHOPPER") );
break;
}
// END OF STANDARD VM2 ORDER STATUSES
// ADD ANY NON STANDARD STATUSES YOU HAVE HERE
case "E";
{
echo "PROCESSED";
break;
}
case "F";
{
echo "READY FOR COLLECTION";
break;
}
case "L";
{
echo "COLLECTED";
break;
}
default: {
echo "";
}

}
echo "<br />";
echo $order_status_description != "" nl2br($order_status_description):"";
echo "<br />";
}
echo $this->loadTemplate('footer');
?>

</td></tr>
</table>
</div>
</body>
</html>



sfinx

Thank you for this. This is almost what I was looking for. It will certainly help a lot.
Do you have any idea how could I adapt this code so that it would load different templates for different order status?

Currently I managed to insert different templates (template is called mail_html_pending) with :
echo $this->loadTemplate('pending');
         

case "P";
{   
echo strtoupper( JText::_("COM_VIRTUEMART_ORDER_STATUS_PENDING") );
echo $this->loadTemplate('pending');
break;
};


However I still have problem, since I would like to put this template in front of order status. Currently I get mail with header, order status, my template + footer...
If I could somehow remove this part:
else {
echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
switch ($cur_order_status) {

I tryed with just eco, I tryed different combinations but I get error when sending....
Or if I could somehow load template in front of this order status statement....
Any suggestions?

WebStuff

Hi sfinx,
Hope I understand correctly what you are after.
Either move this line:
echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
Inside each of the case statements where you want it to appear and leave it out of the ones you don't.
e.g.
case "P";
{
echo strtoupper( JText::_("COM_VIRTUEMART_ORDER_STATUS_PENDING") );
echo $this->loadTemplate('pending');
echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
break;
}

OR if this is only for pending orders you could add an "if" statement around the status change message.
e.g.

else {
if ($cur_order_status != 'P') {
echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
}
switch ($cur_order_status) {

OR if you want the message after all statuses move the status message to after the case statement.
e.g. to here

echo "Your order number.".$cur_order_no." has Changed Status<br />New Status : ";
}
echo "<br />";
echo $order_status_description != "" ? nl2br($order_status_description):"";
echo "<br />";


Hope this helps.

sfinx

Thank you for this again, however in the mean time I managed to achive this, by copying everything from this part at the bottom of your code:
// ADD ORDER STATE LETTERS TO THIS ARRAY WILL SHOW FULL EMAIL
$receive_full_mail_statuses = array("C", "U");
if( in_array($cur_order_status, $receive_full_mail_statuses) ) {
// Shop desc for shopper and vendor
echo $this->loadTemplate('header');


I know this is probably not smartest solution, but it was all I could manage and it is working, so I guess I will leave it at that.
So what I did was:
I deleted all text calling your order status. I made 2 different header files, so they are called depending on status.  I deleted everything in mail_html_shopper.php since it was automaticly loaded after header and I couldnt find the line that is calling it.
For Order status confirmed by shoper I than created seperate file (mail_html_podatki) that has original shopper.php  code in it and loaded it after header.
In case of different statuses I will than just replace podatki  (in case of shiped statusm it is called shiped) with appropriate template and place it where I want it to be.

hopefully that makes sense. Here is my current code:


<table align="center"  cellpadding="0" cellspacing="0">
<tr><td>
<?php

$cur_order_status $this->orderDetails['details']['BT']->order_status;
$cur_order_no $this->orderDetails['details']['BT']->order_number;
$db JFactory::getDBO();
$qrydata "SELECT order_status_description FROM #__virtuemart_orderstates WHERE order_status_code ='".$cur_order_status."'";
$db->setQuery($qrydata);
$db->query();
$order_status_description $db->loadResult();

// ADD ORDER STATE LETTERS TO THIS ARRAY WILL SHOW FULL EMAIL
$receive_full_mail_statuses = array("C""U");
if( in_array($cur_order_status$receive_full_mail_statuses) ) {
// Shop desc for shopper and vendor
echo $this->loadTemplate('header');
// Message for shopper or vendor
echo $this->loadTemplate($this->recipient);
// render shipto billto adresses
echo $this->loadTemplate('podatki');
// render shipto billto adresses
echo $this->loadTemplate('shopperaddresses');
// render price list
echo $this->loadTemplate('pricelist');
// more infos
echo $this->loadTemplate($this->recipient '_more');
// end of mail
}
else {
echo " ";
switch ($cur_order_status) {
// STANDARD VM2 ORDER STATUSES
case "C";
{
echo strtoupperJText::_("") );
break;
}
case "X";
{

echo strtoupperJText::_("") );
break;
}
case "P";
{   
echo strtoupperJText::_("") );
break;
}
case "R";
{

echo strtoupperJText::_("") );
break;
}
case "S";
{
echo strtoupperJText::_("") );
break;
}
case "U";
{
echo strtoupperJText::_("") );
break;
}
// END OF STANDARD VM2 ORDER STATUSES
// ADD ANY NON STANDARD STATUSES YOU HAVE HERE

case "F";
{
echo "READY FOR COLLECTION";
break;
}
default: {
echo "";
}

}
echo "<br />";
echo $order_status_description != "" nl2br($order_status_description):"";
echo "<br />";
}
// SEND ORDER
$receive_full_mail_statuses = array("S""P");
if( in_array($cur_order_status$receive_full_mail_statuses) ) {
// Shop desc for shopper and vendor
echo $this->loadTemplate('head');
// Message for shopper or vendor
echo $this->loadTemplate($this->recipient);
// render shipto billto adresses
echo $this->loadTemplate('shiped');
// render shipto billto adresses
echo $this->loadTemplate('shopperaddresses');
// end of mail
}
else {
echo " ";
switch ($cur_order_status) {
// STANDARD VM2 ORDER STATUSES
case "C";
{
echo strtoupperJText::_("") );
break;
}
case "X";
{

echo strtoupperJText::_("") );
break;
}
case "P";
{   
echo strtoupperJText::_("") );
break;
}
case "R";
{

echo strtoupperJText::_("") );
break;
}
case "S";
{
echo strtoupperJText::_("") );
break;
}
case "U";
{
echo strtoupperJText::_("") );
break;
}
// END OF STANDARD VM2 ORDER STATUSES
// ADD ANY NON STANDARD STATUSES YOU HAVE HERE

case "F";
{
echo "READY FOR COLLECTION";
break;
}
default: {
echo "";
}

}
echo "<br />";
echo $order_status_description != "" nl2br($order_status_description):"";
echo "<br />";
}
echo $this->loadTemplate('footer');
?>

                   
</td></tr>
</table>

Maxim Pishnyak

You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart