Post by MWYS » Wed Dec 16, 2009 6:16 pm

I havn't seen a HTML Order Email contribution so far, so i thought i would post mine. It's all hard coded but i'm hoping Daniel will develop his own version into future versions that would be much 'cleaner' using the MVC Model instead of it all being 'hard coded' in, but anyway, in the mean time feel free to use the one below.

Notes
This is for Open Cart 1.3.4 only, but should be fairly easy to port to earlier versions. This sends both a HTML and Plain Text email, although the plain text is basically the original order email and does not include the same information that the HTML Email does.

For the Admin alerts i basically send the same copy of the email to the administrator since i feel that it contains sufficient information to the administrator to act upon and didn't feel it required a seperate design, however using the same procedure you can customise this as you like.

Preview
Image

Installation
Open up the file: catalog/model/checkout/order.php and replace the confirm function with the one below. On an unmodified order.php running version 1.3.4 this should be from line 46 to 163.

I also recommend you take a backup of this file should you screw something up.

Finally change your logo, For the sake of this release i've just put a link to the Open Cart logo, but change this to your own.

Also put on pastebin so you can see the code easier.
http://pastebin.com/f4f28e365

Code: Select all

	public function confirm($order_id, $order_status_id, $comment = '') {
		$order_query = $this->db->query("SELECT *, 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) {	
			$language = new Language($order_query->row['language']);
			$language->load('checkout/confirm');
			
			$this->load->model('localisation/currency');
			
			$subject = sprintf($language->get('mail_new_order_subject'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'), $order_id);
			$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'] . "'");
			$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
			$order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
			$order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
			
			foreach ($order_product_query->rows as $product) {
				$option_data = array();
				
				$options = $this->getOrderOptions($order_id, $product['order_product_id']);
	
				foreach ($options as $option) {
					$option_data[] = array(
						'name'  => $option['name'],
						'value' => $option['value']
					);
				}
			  
				$orderProducts[] = array(
					'name'     => $product['name'],
					'model'    => $product['model'],
					'option'   => $option_data,
					'quantity' => $product['quantity'],
					'price'    => $this->currency->format($product['price'], $order_query->row['currency'], $order_query->row['value']),
					'total'    => $this->currency->format($product['total'], $order_query->row['currency'], $order_query->row['value'])
				);
			}
			
	/**
	 * HTML Order Email
	 * @ Lee Turver
	 */
	
	$htmlMessage = '<html>
				<head>
				<title>' . $this->config->get('config_store') . ' - Order Confirmation</title>
				</head>
				<body>
					<table cellspacing="0" cellpadding="0" border="0" width="98%" style="margin-top:10px; font-family: Arial, Verdana, Helvetica, sans-serif; margin-bottom:10px;">
						<tr>
							<td align="center" valign="top">
								<!-- [ header starts here] -->
								<table cellspacing="0" cellpadding="0" border="0" width="650">
									<tr>
										<td valign="top"><img src="http://demo.opencart.com/image/logo.png" alt="' . $this->config->get('config_store') . '" border="0"/></td>
									</tr>
								</table>
								<!-- [ middle starts here] -->
								<table cellspacing="0" cellpadding="0" border="0" width="650">
									<tr>
										<td valign="top">
											<p style="font-size: 10pt;">
												<strong>Hello ' . $order_query->row['firstname'] . ' ' . $order_query->row['lastname'] . '</strong>,<br/>
												' . sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . '
											</p>
											<p style="font-size: 10pt;">Your order confirmation is below. Thank you again for your business.</p>
											
											<h3 style="border-bottom:2px solid #eee; font-size:1.05em; padding-bottom:1px; ">Your Order #'. $order_id . '<small> (placed on ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . ')</small></h3>
											
											<table cellspacing="0" cellpadding="0" border="0" width="100%">
												<thead>
													<tr>
														<th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #fff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
															Billing Information:
														</th>
														<th width="3%"></th>
														<th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
															Payment Method:
														</th>
													</tr>
												</thead>
												<tbody>
													<tr>
														<td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
															' . $order_query->row['payment_firstname'] . ' ' . $order_query->row['payment_lastname'] . '<br />
															' . (!empty($order_query->row['payment_company']) ? $order_query->row['payment_company'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_address_1']) ? $order_query->row['payment_address_1'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_address_2']) ? $order_query->row['payment_address_2'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_city']) ? $order_query->row['payment_city'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_postcode']) ? $order_query->row['payment_postcode'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_zone']) ? $order_query->row['payment_zone'] . '<br />' : '') . '
															' . (!empty($order_query->row['payment_country']) ? $order_query->row['payment_country'] : '') . '
														</td>
														<td>&nbsp;</td>
														<td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
															' . $order_query->row['payment_method'] . '
														</td>
													</tr>
												</tbody>
											</table>
											
											<br/>
                    
											<table cellspacing="0" cellpadding="0" border="0" width="100%">
											<thead>
												<tr>
													<th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
														Shipping Information:
													</th>
													<th width="3%"></th>
													<th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
														Shipping Method:
													</th>
												</tr>
											</thead>
											<tbody>
											<tr>
												<td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">                                
													' . $order_query->row['shipping_firstname'] . ' ' . $order_query->row['shipping_lastname'] . '<br />
													' . (!empty($order_query->row['shipping_company']) ? $order_query->row['shipping_company'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_address_1']) ? $order_query->row['shipping_address_1'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_address_2']) ? $order_query->row['shipping_address_2'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_city']) ? $order_query->row['shipping_city'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_postcode']) ? $order_query->row['shipping_postcode'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_zone']) ? $order_query->row['shipping_zone'] . '<br />' : '') . '
													' . (!empty($order_query->row['shipping_country']) ? $order_query->row['shipping_country'] : '') . '
												</td>
												<td>&nbsp;</td>
												<td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
													' . $order_query->row['shipping_method'] . '
												</td>
											</tr>
										</tbody>
										</table>
										
										<br/>
                    
										<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
											<thead>
												<tr>
												<th align="left" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Item</th>
												<th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Qty</th>
												<th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Unit Price</th>
												<th align="right" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Subtotal</th>
											</tr>
										</thead>

										  <tbody bgcolor="#eeeded">';
											
											foreach($orderProducts as $product):
												$htmlMessage .= '
												<tr>
													<td align="left" valign="top" style="padding:3px 9px; font-size: 10pt; ">
														<strong>' . $product['name'] . '</strong>';
														foreach ($product['option'] as $option):
															$htmlMessage .= '<br />&nbsp;<small> - '. $option['name'] . ' ' . $option['value'] . '</small>';
														endforeach;
													$htmlMessage .= '
													</td>
													<td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['quantity'] . '</td>
													<td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['price'] . '</td>
													<td align="right" valign="top" style="padding:3px 9px; font-size: 10pt; ">' . $product['total'] . '</td>
												</tr>';
											endforeach;
											
										$htmlMessage .= '
										</tbody>
										
										<tfoot>';

										foreach ($order_total_query->rows as $result):
											if($result['title'] != 'Total:'):
												$htmlMessage .= '
													<tr>
														<td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;">' . $result['title'] . '</td>
														<td align="right" style="padding:3px 9px; font-size: 10pt;"><span class="price">' . $result['text'] . '</span></td>
													</tr>';
											else:
												$htmlMessage .= '
													<tr bgcolor="#DEE5E8">
														<td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;"><strong><big>' . $result['title'] . '</big></strong></td>
														<td align="right" style="padding:6px 9px; font-size: 10pt;"><strong><big><span class="price">' . $result['text'] . '</span></big></strong></td>
													</tr>';											
											endif;
										endforeach;
										
										$htmlMessage .= '
										</tfoot>
									</table>

									<br/>
                    
									<p>Thank you again,<br/><strong>' . $this->config->get('config_store') . '</strong></p>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</body>
		</html>';			
	
	/**
	 * HTML Order Text End
	 * Begin Plain Text Message
	 */
			// Text Mail
			$message = sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . "\n\n";
			$message .= $language->get('mail_new_order_order') . ' ' . $order_id . "\n";
			$message .= $language->get('mail_new_order_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n";
			$message .= $language->get('mail_new_order_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
			$message .= $language->get('mail_new_order_product') . "\n";
			
			foreach ($order_product_query->rows as $result) {
				$message .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
			}
			
			$message .= "\n";
			
			$message .= $language->get('mail_new_order_total') . "\n";
			
			foreach ($order_total_query->rows as $result) {
				$message .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
			}			
			
			$message .= "\n";
			
			$message .= $language->get('mail_new_order_invoice') . "\n";
			$message .= html_entity_decode($this->url->http('account/invoice&order_id=' . $order_id), ENT_QUOTES, 'UTF-8') . "\n\n";
			
			if ($order_download_query->num_rows) {
				$message .= $language->get('mail_new_order_download') . "\n";
				$message .= $this->url->http('account/download') . "\n\n";
			}
			
			if ($comment) {
				$message .= $language->get('mail_new_order_comment') . "\n\n";
				$message .= $comment . "\n\n";
			}
			
			$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'), ENT_QUOTES, 'UTF-8'), $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(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
			$mail->setSubject($subject);
			$mail->setHtml($htmlMessage);
			$mail->setText($message);
			$mail->send();
			
			if ($this->config->get('config_alert_mail')) {
				$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(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
				$mail->setSubject($subject);
				$mail->setHtml($htmlMessage);
				$mail->setText($message);
				$mail->send();
			}
			
			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 $product) {
					$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
				
					$order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
				
					foreach ($order_option_query->rows as $option) {
						$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
					}
				}
			}		
		}
	}
On request by the original author, the attachment is moved from a later posting to this here.

Attachments

Moved attachement


New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by Qphoria » Wed Dec 16, 2009 10:39 pm

Excellent!

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Thu Dec 17, 2009 4:18 pm

Thanks!

Does the e-mail also include the VAT/TAX?
I cannot see it on the image provided.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by MWYS » Thu Dec 17, 2009 5:02 pm

i2Paq wrote:Thanks!

Does the e-mail also include the VAT/TAX?
I cannot see it on the image provided.
Hey,

It will include the Tax / VAT at the bottom with the Order Totals, I didn't have Tax enabled on my store (above) which is why it doesn't display.

Thanks

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by DannyMacD » Thu Dec 17, 2009 5:45 pm

hello,

i have done what was said above but me being special i seem to get this error message:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/disifin/public_html/shop/catalog/model/checkout/order.php on line 323

i have attached a link to my order.php file i was wondering if you can spot the error for me please? (changed to txt as cant upload php files)

http://shop.disifin.co.uk/order.txt

thank you :)

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by MWYS » Thu Dec 17, 2009 5:49 pm

It looks like you have made some alterations yourself previously and the code after Line 323 was Outside of the confirmation function resulting with your error message.

I've corrected your file, the one below should be okay.
http://pastebin.com/f7cc2d656

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by DannyMacD » Thu Dec 17, 2009 5:54 pm

hello, thanks for that.

i have just changed it, uploaded and done a test order however it seems that once an order is processed it does not show up on the admin side nor does it show up in the customers account section of view order history :(

any ideas?

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by MWYS » Thu Dec 17, 2009 6:32 pm

Appologies, I had forgot to include an additional function to get the Product Options for the order email.

I have attached my Order.php below which i can confirm works correctly. Replace your catalog/model/checkout/order.php with the one attached.

Thanks

Attachment moved to first posting by request of the author.
Last edited by OSWorX on Wed Jan 27, 2010 4:54 am, edited 2 times in total.
Reason: Attachment moved to first post

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by DannyMacD » Fri Dec 18, 2009 8:18 am

cool, seems to work a treat!

i was wondering is there anyway to get this same template for where you print the invoices on the admin backend?

example of link: /admin/index.php?route=customer/order/invoice&order_id=16

many thanks

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by MWYS » Fri Dec 18, 2009 4:51 pm

DannyMacD wrote:cool, seems to work a treat!

i was wondering is there anyway to get this same template for where you print the invoices on the admin backend?

example of link: /admin/index.php?route=customer/order/invoice&order_id=16

many thanks
I'll work on that today and post it up later for you.

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by i2Paq » Fri Dec 18, 2009 8:50 pm

Make sure you create the invoice-layout in such a way that you can use window-enveloppes (I hope you know what I mean ;) )

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by scot80 » Sat Dec 19, 2009 3:48 am

Would be nice if you can add support for other languages.

Active Member

Posts

Joined
Fri Nov 06, 2009 12:14 am
Location - Germany

Post by zone97 » Mon Dec 21, 2009 6:53 am

Try as I might every time I add one of these mods for html email, outlook always gets it as BASE 64 encoded. Where as my iphone shows it correctly? My outlook gets other html email fine why would emails from my cart fail like this?

Image
Custom t-shirts, mugs and more!


New member

Posts

Joined
Fri Oct 30, 2009 1:15 am


Post by MWYS » Mon Dec 21, 2009 5:25 pm

zone97 wrote:Try as I might every time I add one of these mods for html email, outlook always gets it as BASE 64 encoded. Where as my iphone shows it correctly? My outlook gets other html email fine why would emails from my cart fail like this?
I will also add support for other languages very shortly.

Zone97, What version of outlook do you use - I receive it just fine in Outlook 2007.

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm

Post by zone97 » Mon Dec 21, 2009 11:06 pm

It's outlook 2007? Could it be in the way PHP is configured? or that is php mail not smtp?

Image
Custom t-shirts, mugs and more!


New member

Posts

Joined
Fri Oct 30, 2009 1:15 am


Post by nzjollyroger » Tue Dec 29, 2009 11:40 am

is it possible to get this to work with version 1.3.2?

New member

Posts

Joined
Mon Nov 16, 2009 5:26 am

Post by max2000 » Wed Jan 06, 2010 9:26 am

I have an unedited version of order.php

can you please send the entire clean file?

best,

max

Newbie

Posts

Joined
Wed Jan 06, 2010 8:48 am

Post by gclass » Fri Jan 15, 2010 6:11 am

hi

will it apply to emails sent when you update the order's status too?

can you please explain what need to be done so use it on 1.3.2?

Thx
G

New member

Posts

Joined
Sat Oct 03, 2009 1:21 am

Post by davey c » Wed Jan 27, 2010 3:06 am

I have a problem where this mail gets screwed up in Outlook 2003 but works everywhere else.

Did anyone figure out the Outlook Issues with this? It does only seem to be an outlook problem because it works fine everywhere else (but my client uses Outlook).

Cheers

New member

Posts

Joined
Fri Aug 07, 2009 10:52 pm

Post by MWYS » Wed Jan 27, 2010 3:30 am

davey c wrote:I have a problem where this mail gets screwed up in Outlook 2003 but works everywhere else.

Did anyone figure out the Outlook Issues with this? It does only seem to be an outlook problem because it works fine everywhere else (but my client uses Outlook).

Cheers
If you are running version 1.3.4 or 1.3.2, Then take the mail class out of version 1.4.0 (system -> libraries -> mail.php) from memory - There are no significant changes so you should be able to simply overwrite the file and it will work.

Its because of issues with base64, but base64_encoding is removed in version 1.4 which should solve the problem.

New member

Posts

Joined
Wed Oct 21, 2009 9:04 pm
Who is online

Users browsing this forum: No registered users and 51 guests