$order_info = $this->getOrder($order_id);
if ($order_info && $order_info['order_status_id']) {
// Fraud Detection
if ($this->config->get('config_fraud_detection')) {
$this->load->model('checkout/fraud');
$risk_score = $this->model_checkout_fraud->getFraudScore($order_info);
if ($risk_score > $this->config->get('config_fraud_score')) {
$order_status_id = $this->config->get('config_fraud_status_id');
}
}
// Ban IP
$status = false;
$this->load->model('account/customer');
if ($order_info['customer_id']) {
$results = $this->model_account_customer->getIps($order_info['customer_id']);
foreach ($results as $result) {
if ($this->model_account_customer->isBanIp($result['ip'])) {
$status = true;
break;
}
}
} else {
$status = $this->model_account_customer->isBanIp($order_info['ip']);
}
if ($status) {
$order_status_id = $this->config->get('config_order_status_id');
}
$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)$notify . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
// Send out any gift voucher mails
if ($this->config->get('config_complete_status_id') == $order_status_id) {
$this->load->model('checkout/voucher');
$this->model_checkout_voucher->confirm($order_id);
}
if ($notify) {
$language = new Language($order_info['language_directory']);
$language->load($order_info['language_filename']);
$language->load('mail/order');
$subject = sprintf($language->get('text_update_subject'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
$message = $language->get('text_update_order') . ' ' . $order_id . "\n";
$message .= $language->get('text_update_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\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_info['language_id'] . "'");
if ($order_status_query->num_rows) {
$message .= $language->get('text_update_order_status') . "\n\n";
$message .= $order_status_query->row['name'] . "\n\n";
}
if ($order_info['customer_id']) {
$message .= $language->get('text_update_link') . "\n";
$message .= $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id . "\n\n";
}
if ($comment) {
$message .= $language->get('text_update_comment') . "\n\n";
$message .= $comment . "\n\n";
}
$message .= $language->get('text_update_footer');
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($order_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($order_info['store_name']);
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
$mail->send();
}
}