Auto Generate Invoice Number in Opencart - 100% working

There are a couple of plugins out there stealing money from the poor, so I thought Id give you some really quick code for auto generating the invoice number in opencart:
The file you want to edit is located at: catalog/model/checkout/order.php
Grab this file and make the following changes:
1. Remove the line containing the following:
 
$this->db->query(“UPDATE `” . DB_PREFIX . “order` SET order_status_id = ‘” . (int)$order_status_id . “‘, date_modified = NOW() WHERE order_id = ‘” . (int)$order_id . “‘”);
 
2. Add the following code in the same place where you just removed the code from step 1:
               $query = $this->db->query(“SELECT MAX(invoice_no) AS invoice_no FROM `” . DB_PREFIX . “order` WHERE invoice_prefix = ‘” . $this->db->escape($order_info[‘invoice_prefix’]) . “‘”);                        if ($query->row[‘invoice_no’]) {                        $invoice_no = (int)$query->row[‘invoice_no’] + 1;                        } else {                                $invoice_no = 1;                        }                                                $this->db->query(“UPDATE `” . DB_PREFIX . “order` SET invoice_no = ‘” . (int)$invoice_no . “‘, invoice_prefix = ‘” . $this->db->escape($order_info[‘invoice_prefix’]) . “‘, order_status_id = ‘” . (int)$order_status_id . “‘, date_modified = NOW() WHERE order_id = ‘” . (int)$order_id . “‘”);
 
 
3. Find the following code:
 
$template->data[‘text_order_id’]=$language->get(‘text_new_order_id’);
4. Add the following two lines above the code found in step 3:
 
$template->data[‘invoice_no’] =$invoice_no;
$template->data[‘text_invoice_no’] =$language->get(‘text_invoice_no’);
 
Tested and working with Opencart v1.5.1.3, should work with others
Hope this helps!! Have fun and please don’t hesitate to give me a shout if you have any questions.
[box type=”bio”] [paypal-donation][/box]