Most of the steps were taken from posts in two other threads, so the code is courtesy of them:
http://forum.opencart.com/viewtopic.php ... 39#p227588
http://forum.opencart.com/viewtopic.php ... 878#p90940
Disclaimer: These are the Mods I made, and it works great. I'm not even sure ALL these Mods are necessary to accomplish adding the SKUs. Someone who knows this stuff better than me may be able to cut out some of the changes if they weren't needed.
Please read whole tutorial before starting!
If you don't have a php editor, I'd suggest downloading Notepad++. It's free, and makes adding by line number easy.
http://notepad-plus-plus.org/
First we will be adding a column to the database as described. I'm not sure if this is necessary, but the changes we are going to make to some of the files below will pop errors because they refer to this :
We will be modifying five Opencart files:1) add the table row for "order_product"
MySQL edit :
go to phpMyAdmin or whatever you are using, go to "your_opencart_db" and open the "order_product" table (may be called otherwise if you are using prefixes) and execute the following SQL query
Code: Select all
ALTER TABLE order_product ADD sku VARCHAR(60);
the new row named "sku" should appear.
Note : existing orders need to be populated with skus manually. Best way is to export a CSV File
of "order_product" table and "product" table and use vlookup function to match Product IDs
with SKUs and reupload. For troubleshooting see -> SQL Alter Table
http://www.tech-recipes.com/rx/378/add- ... sql-table/
admin/view/templates/sale/order_invoice.tpl
admin/language/english/sale/order.php
admin/model/sale/order.php
admin/controller/sale/order.php
catalog/model/checkout/order.php
You might just have to make the changes to the bold files above to add the SKUs to the invoice. Try making those changes first and test before changing the database and doing the last two.
backup all of the files before you change them!
starting with:
admin/view/templates/sale/order_invoice.tpl
around line 67, look for:
Code: Select all
<td><b><?php echo $column_model; ?></b></td>
Code: Select all
<td><b><?php echo $column_sku; ?></b></td>
Code: Select all
<td><?php echo $product['model']; ?></td>
Code: Select all
<td align="right"><?php echo $product['sku']; ?></td>
Code: Select all
<td align="right" colspan="4"><b><?php echo $total['title']; ?>:</b></td>
Code: Select all
<td align="right" colspan="5"><b><?php echo $total['title']; ?>:</b></td>
Now move onto:
admin/language/english/sale/order.php
around line 125, under the "// Column" section, add:
Code: Select all
$_['column_sku'] = 'SKU';
Now we're going to open:
admin/model/sale/order.php
-------------------------- These may error if you didn't add column to the database -------------------------
Around line 84, look for:
Code: Select all
if (isset($data['order_product'])) {
foreach ($data['order_product'] as $order_product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "'");
Code: Select all
if (isset($data['order_product'])) {
foreach ($data['order_product'] as $order_product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "', sku = '" . (float)$product['sku'] . "'");
Code: Select all
foreach ($data['order_product'] as $order_product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_product_id = '" . (int)$order_product['order_product_id'] . "', order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "'");
Code: Select all
foreach ($data['order_product'] as $order_product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_product_id = '" . (int)$order_product['order_product_id'] . "', order_id = '" . (int)$order_id . "', product_id = '" . (int)$order_product['product_id'] . "', name = '" . $this->db->escape($order_product['name']) . "', model = '" . $this->db->escape($order_product['model']) . "', quantity = '" . (int)$order_product['quantity'] . "', price = '" . (float)$order_product['price'] . "', total = '" . (float)$order_product['total'] . "', tax = '" . (float)$order_product['tax'] . "', reward = '" . (int)$order_product['reward'] . "' , sku = '" . (float)$product['sku'] . "'");
Look around line 468 for:
Code: Select all
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
Code: Select all
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT a.*, b.sku FROM " . DB_PREFIX . "order_product a LEFT JOIN " . DB_PREFIX . "product b ON a.product_id = b.product_id WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
}
This step MAY not be needed. But will pop errors if you didn't add the column to the database as described above. Next we open:
admin/controller/sale/order.php
At line number 1089, look for:
Code: Select all
'reward' => $order_product['reward'],
Code: Select all
'sku' => $order_product['sku']
Code: Select all
$this->data['column_model'] = $this->language->get('column_model');
Code: Select all
$this->data['column_sku'] = $this->language->get('column_sku');
Code: Select all
'option' => $option_data,
Code: Select all
'sku' => $product['sku'],
This step MAY not be needed. But will pop errors if you didn't add the column to the database as described above.Now we are going to modify:
catalog/model/checkout/order.php
Around line 8, look for:
Code: Select all
foreach ($data['products'] as $product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', reward = '" . (int)$product['reward'] . "''");
Code: Select all
foreach ($data['products'] as $product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', reward = '" . (int)$product['reward'] . "', sku = '" . (float)$product['sku'] . "'");
I'm not sure ALL the steps are needed, but can say that if you do all the steps, it WILL work!
You should now have SKU numbers added to the invoice.
Someone please let me know if they were successful in adding the SKUs by just changing the first three files.