Post by Jan R » Sun Oct 18, 2009 7:04 am

Jan here...
After adding a "Product Review Email Notice"
http://forum.opencart.com/viewtopic.php ... 647#p33580

I got inspired to take a try at modifying the conformation email (For the Customer and Admin) so that they would be sent as formated HTML .. See Sample.

Image
After poking around in the code i found that Opencart's Mail class had a HTML option.
So after a test to see if I could call to it from the "order.php" file was successful, I set out to reprogramming the file for HTML formated e-mail with store logo.
This method may not be exactly 'mvc' but it worked for me and I hope someone else can get some good out of it.
Save a copy of this code someplace on your computer because I am sure you will have to make the changes again if the order.php gets changed in a future update.

Here is what you need to know:
  • FIRST! If any of these instruction sound foreign to you or if you don't know what a FTP program is or how to find files. Don't try it! :-*
  • This is for OpenCart 1.3.2 un-altered order.php -- for any other version, you are on your own.
  • The file you need to edit is catalog/model/checkout/order.php
  • BACK UP THIS FILE !!!
  • Go to line 64 or just after the line that starts "$order_download_query..."
  • DELETE EVERYTHING below line 64.
  • Replace it with the script below.
  • Make changes to the lines marked as /*Logo*/ so that the paths point to your site and your logo file
  • Save! :)
Have Fun -=:@:=-

Code: Select all

	
/*Get user info*/ $addressEmail= $this->customer->getAddress($this->session->data['shipping_address_id']);
// Mail to Custumer	-----------------------------------------------------------		
/* message start ->*/ $message =""
/*Logo*/        ."<div style='text-align:center'><a href='http://YOURSITE.com'><img src='http://YOURSITE.com/image/logo.png'align='center'/></a></div>"

/*Order */      ."<h2>".$language->get('mail_new_order_order')."<span style='color:red;'>".$order_id."</span></h2>"
				."<div style='color:blue;text-align:center'>".sprintf($language->get('mail_new_order_greeting'),$this->config->get('config_store'))."</div><br>"
				."<table border 1 cellpadding='3' cellspacing='0' width='250' bgcolor='#e6edff'>"
				.$addressEmail[firstname]." ".$addressEmail[lastname]."<br>"
				.$addressEmail[address_1]." - ".$addressEmail[address_2]."<br>"
				.$addressEmail[city]." ".$addressEmail[zone]." ".$addressEmail[postcode]."<br>"
				.$addressEmail[country]."</table>"	
				
/*date/status*/	."<table border='0' cellpadding='3' cellspacing='0' width='500'>"."<tr>"
				."<td>".$language->get('mail_new_order_date_added').' '.date($language->get('date_format_short'), strtotime($order_query->row['date_added']))."</td>"
				."<td align='right' >".$language->get('mail_new_order_order_status') . ' ' . $order_status_query->row['name']."</td>"."</tr>"."</table>"
			    
/*PRODUCTS:*/	."<strong>".$language->get('mail_new_order_product')."</strong>"
				
/*Prod. loop*/  ."<table border='1' cellpadding='3' cellspacing='0'  width='500' bgcolor='#f4fdd9'>"."<tr>";
				foreach ($order_product_query->rows as $result) {
				$message .="<tr>" 
					."<td>".$result['quantity'].'x '."</td>"
					."<td>".$result['name'].' ('.$result['model'].')'."</td>"
					."<td  width='100'>".$this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value'])."</td>"
					."</tr>";};
				$message .="</table>"

/*TOTAL:*/   	."<strong>".$language->get('mail_new_order_total')."</strong>"
				
/*Total loop*/	."<table border='0' cellpadding='3' cellspacing='0'  width='500'>";
                foreach ($order_total_query->rows as $result) {
				$message .= "<tr><td width='400' align='right'><b>".$result['title']."</b></td><td width='100' border='1' bgcolor='#d9fde3'> ".$result['text']."</td></tr>";};
				$message .= "</table>";
				
/*invoice link*/ //$message .= $language->get('mail_new_order_invoice') . "<br>"
   				$message .="<a href='".html_entity_decode($this->url->http('account/invoice&order_id='.$order_id))."'><b color='red'>ONLINE INVOICE</b></a><br><br>";
				
/*Download info*/	if ($order_download_query->num_rows) {
					$message .=""
					."<strong>".$language->get('mail_new_order_download') ."</strong><br>"
					."<table border='1' cellpadding='3' cellspacing='0'  width='500'>"
					.$this->url->http('account/download')."</table>";
				}
				
/*Comments*/  if ($comment) {
					$message .=""
					."<strong>".$language->get('mail_new_order_comment') . "</strong><br>"
					."<table border='1' cellpadding='3' cellspacing='0'  width='500'>"
					.$comment."</table>";
				}
			
			$message .= $language->get('mail_new_order_footer');

			$mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password')), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout')); 
			$mail->setTo($order_query->row['email']);
			$mail->setFrom($this->config->get('config_email'));
			$mail->setSender($this->config->get('config_store'));
			$mail->setSubject($subject);
/* html */	$mail->setHtml($message); 
			$mail->send();

// Mail to Administrator---------------------------------------------
		if ($this->config->get('config_alert_mail')) {

/* message start ->*/ $message =""
/*Logo*/         ."<div style='text-align:center'><a href='http://YOURSITE.com'><img src='http://YOURSITE.com/image/logo.png'align='center'/></a></div>"

/*Order recived*/ ."<h2>".$language->get('mail_new_order_received')."<br>".$language->get('mail_new_order_order')."<span style='color:red;'>".$order_id."</span></h2><br>"
				."<table border 1 cellpadding='3' cellspacing='0' width='250' bgcolor='#e6edff'>"
				.$addressEmail[firstname]." ".$addressEmail[lastname]."<br>"
				.$addressEmail[address_1]." - ".$addressEmail[address_2]."<br>"
				.$addressEmail[city]." ".$addressEmail[zone]." ".$addressEmail[postcode]."<br>"
				.$addressEmail[country]."</table>"	
				
/*date/status*/	."<table border='0' cellpadding='3' cellspacing='0' width='500'>"."<tr>"
				."<td>".$language->get('mail_new_order_date_added').' '.date($language->get('date_format_short'), strtotime($order_query->row['date_added']))."</td>"
				."<td align='right' >".$language->get('mail_new_order_order_status') . ' ' . $order_status_query->row['name']."</td>"."</tr>"."</table>"
			    
/*PRODUCTS:*/	."<strong>".$language->get('mail_new_order_product')."</strong>"
				
/*Prod. loop*/  ."<table border='1' cellpadding='3' cellspacing='0'  width='500' bgcolor='#f4fdd9' >"."<tr>";
				foreach ($order_product_query->rows as $result) {
				$message .="<tr>" 
					."<td>".$result['quantity'].'x '."</td>"
					."<td>".$result['name'].' ('.$result['model'].')'."</td>"
					."<td  width='100'>".$this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value'])."</td>"
					."</tr>";};
				$message .="</table>"

/*TOTAL:*/   	."<strong>".$language->get('mail_new_order_total')."</strong>"
				
/*Total loop*/	."<table border='0' cellpadding='3' cellspacing='0'  width='500'>";
                foreach ($order_total_query->rows as $result) {
				$message .= "<tr><td width='400' align='right'><b>".$result['title']."</b></td><td width='100' border='1' bgcolor='#d9fde3'> ".$result['text']."</td></tr>";};
				$message .= "</table>";
				
/*Download info*/	if ($order_download_query->num_rows) {
					$message .=""
					."<strong>".$language->get('mail_new_order_download') ."</strong><br>"
					."<table border='1' cellpadding='3' cellspacing='0'  width='500'>"
					.$this->url->http('account/download')."</table>";
				}
				
/*Comments*/  if ($comment) {
					$message .=""
					."<strong>".$language->get('mail_new_order_comment') . "</strong><br>"
					."<table border='1' cellpadding='3' cellspacing='0'  width='500'>"
					.$comment."</table>";
				}
			
				$mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), $this->config->get('config_smtp_password'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout')); 
				$mail->setTo($this->config->get('config_email'));
				$mail->setFrom($this->config->get('config_email'));
				$mail->setSender($this->config->get('config_store'));
				$mail->setSubject($subject);
/* html */		$mail->setHtml($message); 
				$mail->send();				
			}
			
						
		}
	}
	
	public function update($order_id, $order_status_id, $comment = '', $notifiy = FALSE) {
		$order_query = $this->db->query("SELECT *, o.language_id, l.code AS language FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "' AND o.order_status_id > '0'");
		
		if ($order_query->num_rows) {
			$this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
		
			$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notifiy . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
	
			if ($notifiy) {
				$language = new Language($order_query->row['language']);
				$language->load('checkout/confirm');
	
				$subject = sprintf($language->get('mail_update_order_subject'), $this->config->get('config_store'), $order_id);
	
				$message  = $language->get('mail_update_order_order') . ' ' . $order_id ."\n";
				$message .= $language->get('mail_update_order_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n\n";
				$message .= $language->get('mail_update_order_order_status') . "\n\n";
				
				$order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "' AND language_id = '" . (int)$order_query->row['language_id'] . "'");
				
				$message .= $order_status_query->row['name'] . "\n\n THIS IS THE ONE";
					
				$message .= $language->get('mail_update_order_invoice') . "\n";
				$message .= html_entity_decode($this->url->http('account/invoice&order_id=' . $order_id)) . "\n\n";
					
				if ($comment) { 
					$message .= $language->get('mail_update_order_comment') . "\n\n";
					$message .= $comment . "\n\n";
				}
					
				$message .= $language->get('mail_update_order_footer');

				$mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password')), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout'));
				$mail->setTo($order_query->row['email']);
				$mail->setFrom($this->config->get('config_email'));
				$mail->setSender($this->config->get('config_store'));
				$mail->setSubject($subject);
				$mail->setText($message);
				$mail->send();
			}
		}
	}
}

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Daniel » Sun Oct 18, 2009 7:22 am

I'm including this in the next release!

I will update it to intergrate a bit better.

Well done! Thank you!

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Jan R » Sun Oct 18, 2009 7:33 am

Jan here...

Thanks Daniel. :)
I hope I did not jumble the code to much. I am just getting to understand a little about "MVC" so I stuck with what i know. But working with OpenCart has shown me how powerful it is. I have done a lot of work with Joomla but could never understand [or took the time to learn] how to begin programing anything for it. But this stuff is good. I look forward to seeing what is ahead. -=:@:=-

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Qphoria » Mon Oct 19, 2009 4:48 am

Daniel wrote:I'm including this in the next release!

I will update it to intergrate a bit better.

Well done! Thank you!
Yes please. A separate MVC style mail.tpl would be nice... like 0.x had

But very nice work Jan!

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Jan R » Mon Oct 26, 2009 5:57 am

Jan here... :( :(

There is a bug [really an omission] from my "HTML Email confirmation" modification..
Earlier before creating the modification I had made a correction to the order.php based on
http://forum.opencart.com/viewtopic.php ... act#p30407
and because I had my new script removed the "Stock substation" routine.

It is included below just as it is from the original file.

place this scrip in on line about 49 right after the line $order_query = $this->db->query in the "public function confirm( )" method

I placed mine there and it now work correctly.

Sorry for the omission.. :(

Code: Select all

if ($this->config->get('config_stock_subtract')) {
				$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
			
				foreach ($order_product_query->rows as $result) {
					$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$result['quantity'] . ") WHERE product_id = '" . (int)$result['product_id'] . "'");
				}
			}

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Donce » Mon Oct 26, 2009 6:50 am

hi Jan,

hmm, very interesting script..;) but..i can start it, it displays default stuff, and nothing else..hmm, any tip?

thanks..

New member

Posts

Joined
Fri Aug 28, 2009 8:22 pm

Post by Jan R » Mon Oct 26, 2009 11:00 am

Jan here... First two silly little questions? ;)

1st .. did you use both scripts? The one I placed today (the omitted code for the "Stock substation" ) and the one from the top of this topic (the email script) perhaps I should have included them both together.

2nd .. If you are not using the default theme ... did you make the change to the correct theme?

if you place both scripts, you should not see any old email stuff because this replaces everything for the "order conformation" to the customer and"order notice" to the store admin.

-=:@:=-

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Donce » Mon Oct 26, 2009 7:07 pm

hmm,

i use default theme..and i use, Q email enchanter..;) yes, i included both scripts..

please, Jan, could you show me an example of yours working script? i would love to see ;)))

New member

Posts

Joined
Fri Aug 28, 2009 8:22 pm

Post by Jan R » Wed Oct 28, 2009 2:08 am

Jan here... Donce
I sent you my whole order.php file.. Didi you get it.
Did it work?
-=:@:=-

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Donce » Wed Oct 28, 2009 3:57 am

Hi Jan,

of course i got it ;)) ive send personal message to you.

New member

Posts

Joined
Fri Aug 28, 2009 8:22 pm

Post by Donce » Wed Oct 28, 2009 4:17 am

Hi Jan,

i got it, look what it looks like when i download it..

<br />
<b>Fatal error</b>: Class 'Model' not found in <b>/...................order.php</b> on line <b>2</b><br />

something wrong..

New member

Posts

Joined
Fri Aug 28, 2009 8:22 pm

Post by Lapremedia » Wed Oct 28, 2009 8:05 pm

I installed this option, but its not sending the e-mail. Any idea's why that is?

Thanks in advance

Newbie

Posts

Joined
Tue Oct 13, 2009 5:01 pm

Post by Jan R » Fri Oct 30, 2009 5:17 am

Jan here...

Lapremedia

There has been some trouble getting e-mail to send from OpenCart for even the standard e-mail code .. this has more to do with the servers and setting of your web host account than it dose with OpenCart itself.

Was your e-mail working before you made the change?

There are many topic on this forum concerning this .. do some searches and you should find some answers.

I would suggest going back to the original order.php file and make sure the e-mail is working like you want it to then try implementing the changes I have shown above.

The changes made above make no change in the logic of order.php except changing one mail setting from text to html. All other changes are just simple formating of items with tables and color.
-=:@:=-

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by Lapremedia » Fri Oct 30, 2009 3:27 pm

Hi there Jan,

There were some things i checked before posting that are;

Checked order.php original and it worked
Checked order.php after adding the txtoptions module (alreadymade)
Then installed ur "mod" and it stopped working.

I will look into the problems of this e-mail thing, shop is going online in 2 days i probably wont be able to implement it working. I'll use the original order.php.

Thanks anyway mate

Newbie

Posts

Joined
Tue Oct 13, 2009 5:01 pm

Post by guisauer » Sun Dec 06, 2009 9:32 am

Jan, do you think you can mod this for version. 1.3.4 please?
It would be really helpful.
Thanks!

New member

Posts

Joined
Sun Dec 06, 2009 7:51 am

Post by Jan R » Sun Dec 06, 2009 11:17 am

Jan Here...
Hi guisauer

I have not moved up from 1.3.2 yet and i have not had much time to play with it. I will soon. perhaps i can take a look and make a 1.3.4 one soon.

I have not look yet but the code should be able to be easy to insert into 1.3.4 there is nothing in the code to do with the templates system. you might be able to look and see were the mail routine are and replace them with mine but don't try it without first backing up the file.

And unless you know PHP reasonably well, I would not attempt it.
-=:@:=-

»-(¯`·.·´¯)->"The most wasted day in that in which we have not laughed."<-(¯`·.·´¯)-«


User avatar
New member

Posts

Joined
Fri Oct 16, 2009 2:20 am

Post by guisauer » Sun Dec 06, 2009 1:22 pm

Hey Jan, yeah, I don't know PHP that well, that's why I was a little hesitant to try anything.
I can live with the plain text emails for now, so I think I'll just wait until something better comes up. Let us know if you update it for 1.3.4! That would be awesome!
Thanks!

New member

Posts

Joined
Sun Dec 06, 2009 7:51 am

Post by zone97 » Sun Dec 06, 2009 10:55 pm

Lapremedia wrote:Hi there Jan,

There were some things i checked before posting that are;

Checked order.php original and it worked
Checked order.php after adding the txtoptions module (alreadymade)
Then installed ur "mod" and it stopped working.

I will look into the problems of this e-mail thing, shop is going online in 2 days i probably wont be able to implement it working. I'll use the original order.php.

Thanks anyway mate
I have the same mod installed but when the email is sent it arrives as base64 encoded not html? It works with my iphone? Maybe its the structure. Here is what I found as far as sending html via PHP. I didnt notice a header section in your code.

Code: Select all

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Image
Custom t-shirts, mugs and more!


New member

Posts

Joined
Fri Oct 30, 2009 1:15 am

Who is online

Users browsing this forum: No registered users and 9 guests