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
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> </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> </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 /> <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'");
}
}
}
}
}