Page 1 of 1

How to show SKU on the cart?

Posted: Wed Jul 07, 2010 7:36 am
by Melanie
Hi,

I have the SKU showing on my products page, but how can I show it on the cart?
Thanks for any help.


Kind regards,
Melanie

Re: How to show SKU on the cart?

Posted: Wed Jul 07, 2010 10:12 am
by JAY6390
Which cart do you mean? The one on the sidebar or the checkout cart (basket) page?

Re: How to show SKU on the cart?

Posted: Wed Jul 07, 2010 10:55 am
by Melanie
JAY6390 wrote:Which cart do you mean? The one on the sidebar or the checkout cart (basket) page?
Hi Jay!

The checkout cart (basket) page.


Thanks,
Melanie

Re: How to show SKU on the cart?

Posted: Wed Jul 07, 2010 7:15 pm
by JAY6390
In that case you should be able to echo out $product['model'] in the catalog/view/theme/default/template/checkout/cart.tpl within the foreach loop of the $products

Re: How to show SKU on the cart?

Posted: Wed Jul 07, 2010 9:31 pm
by Qphoria
model is set but sku isn't.
For that one you need to make 2 edits.

1 to the cart controller
and
1 to the cart library

1. EDIT: system/library/cart.php
2. FIND:

Code: Select all

'model'        => $product_query->row['model'], 
3. AFTER, ADD:

Code: Select all

'sku'           => $product_query->row['sku'], 
4 EDIT: catalog/controller/checkout/cart.php
5. FIND:

Code: Select all

'model'    => $result['model'], 
6. AFTER, ADD:

Code: Select all

'sku'        => $result['sku'], 

Re: How to show SKU on the cart?

Posted: Wed Jul 07, 2010 9:54 pm
by JAY6390
ah my bad :)

Re: How to show SKU on the cart?

Posted: Thu Jul 08, 2010 9:21 am
by Melanie
All done, perfect, thanks!!!
Mel

Re: How to show SKU on the cart?

Posted: Wed Jul 14, 2010 9:17 am
by Melanie
Hi guys!

Another quick one.

How can I show the SKU on the admin and the INVOICE?

Thanks,
Mel

Re: How to show SKU on the cart?

Posted: Wed Jul 14, 2010 9:35 pm
by Qphoria
that is a lot more difficult. columns will need to be added to the order_product table

Re: How to show SKU on the cart?

Posted: Wed Aug 11, 2010 7:20 pm
by bedo02
Hey Guys,

I would need such feature as well and as far I can see, it was dropped from the 1.4.8 to do list and I don`t know if this will come in the 1.4.9 release as there are mostly only fixes. Anyway I can not wait so long ;) So I am trying to add this feature by myself.

I managed to alter the order_product table and files so the SKU is pulled on the invoice, so far I have to add the sku to the table manually, but I would like, that it would be added to the table row automatically at the time of purchase.

Does anyone know which file is responsible for the processing of the final order? Meaning -> pulling data from the cart and placing them to the tables? I am reading through the code, but have no luck to find the right functions.

As soon I will finish this, I will post a how to in this topic.

Thank you all!

Re: How to show SKU on the cart?

Posted: Thu Aug 12, 2010 12:58 am
by bedo02
you know what forget my question, who can read has an advantage :)

Folks got it working.

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/

2) Now the Opencart alterations :

\admin\controller\sale\order.php

Add :

on line 1199

Code: Select all

'sku'      => $product['sku'],


in

admin\view\template\sale\order_invoice.tpl // so it will be printed out on the invoice

add

on line 59

Code: Select all

<td><b><?php echo 'SKU'; ?></b></td>

on line 67

Code: Select all

<td><?php echo $product['model']; ?></td>
edit line 82

from

Code: Select all

      <td align="right" colspan="4"><b><?php echo $total['title']; ?></b></td>
to

Code: Select all

      <td align="right" colspan="5"><b><?php echo $total['title']; ?></b></td>

Change :

\catalog\model\checkout\order.php line 75 // so the SKU is automatically added to the Database

from

Code: Select all

			$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']) . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product

['total']. "', tax = '" . (float)$product['tax'] . "', quantity = '" . (int)$product

['quantity'] . "'");
to

Code: Select all

			$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']) . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product

['total']. "', sku = '" . (float)$product['sku'] . "', tax = '" . (float)$product['tax'] . "', 

quantity = '" . (int)$product['quantity'] . "'");
Add

catalog\controller\checkout\confirm.php // this will pull and show the SKUs to the shopping cart confirmation page and then they can be pulled to DB

on line 171

Code: Select all

        		'sku'        => $product['sku'],
and on line 387

Code: Select all

        		'sku'        => $product['sku'],
Add

catalog\controller\checkout\guest_step_3.php // this will pull and show the SKUs to the shopping cart confirmation page and then they can be pulled to DB

on line 164

Code: Select all

        		'sku'        => $product['sku'],
and on line 384

Code: Select all

        		'sku'        => $product['sku'],
in catalog\view\theme\your_theme\template\checkout\confirm.tpl // this will display the SKUs at the order confirmation page

add

on line 43

Code: Select all

<th align="left"><?php echo 'SKU'; ?></th>
and on line 52

Code: Select all

<td align="left" valign="top"><?php echo $product['sku']; ?></td>
Note : Tested with opencart 1.4.8, tested with paypal sandbox and pre-paid order payments. Let me know if it is working with other payment types as well.
Note : currently not working with manually adding parts through admin. Maybe somebody can play with it :)
Note : I give no warranty or any support on it, should something break, you are on your own, as I was ;) But I can try..
Note : feel free to copy, alter or redistribute. For god sick just don´t sell it, it is opensource :)

Have fun with it.

Re: How to show SKU on the cart?

Posted: Mon Aug 22, 2011 8:11 am
by Hashishim
Do you know how to configure this for 1.5.1? I require this well not the SKU, another custom field i made to be pulled. I did follow it accordingly but it is not populating the Order ID Db with the new field

Re: How to show SKU on the cart?

Posted: Thu Mar 29, 2012 7:17 am
by H2O
A HOW-TO has been created on how to add SKU numbers to the Invoice. It was done to version 1.5.2.1.

It can be found here:
http://forum.opencart.com/viewtopic.php?f=121&t=57412

Re: How to show SKU on the cart?

Posted: Sat May 30, 2015 6:37 am
by aljawaid
Does anyone know if this would work for 2.0.2.0?

Re: How to show SKU on the cart?

Posted: Sat May 30, 2015 6:39 am
by aljawaid
Qphoria wrote:model is set but sku isn't.
For that one you need to make 2 edits.

1 to the cart controller
and
1 to the cart library

1. EDIT: system/library/cart.php
2. FIND:

Code: Select all

'model'        => $product_query->row['model'],
3. AFTER, ADD:

Code: Select all

'sku'           => $product_query->row['sku'],
4 EDIT: catalog/controller/checkout/cart.php
5. FIND:

Code: Select all

'model'    => $result['model'],
6. AFTER, ADD:

Code: Select all

'sku'        => $result['sku'],
Hello, do you think this would work for both cart.php and checkout.php in both folders on OC v2.0.2.0?