Page 1 of 2

Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 1:28 am
by felizone
Dear All,

I would appreciated if anyone can let me know what file, and stpes to add SKU code to be displayed on PRODUCT INVOICE.

I have tried and added SKY CODE perfectly to product page, however, i got error "Notice: Undefined index: sku in C:\AppServ\www\upload\admin\controller\sale\order.php on line 1327".

The column SKU displayed OK. THE value SKU CODE does not.

Please let me know if you have any idea what i should do.

Cheers,
Felizone ;D

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 1:33 am
by uksitebuilder
Not so simple because the Invoice gets it's data from the Order_product table which doesn't store the sku only:

order_id
product_id
name
model
quantity
price
total
tax

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 9:31 am
by felizone
uksitebuilder wrote:Not so simple because the Invoice gets it's data from the Order_product table which doesn't store the sku only:

order_id
product_id
name
model
quantity
price
total
tax
Thanks for your reply.
I just want to add the SKU to invoice only , NOT other places.
Any simple coding?

Thanks. ;D

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 10:13 am
by felizone
felizone wrote:
uksitebuilder wrote:Not so simple because the Invoice gets it's data from the Order_product table which doesn't store the sku only:

order_id
product_id
name
model
quantity
price
total
tax
Thanks for your reply.
I just want to add the SKU to invoice only , NOT other places.
Any simple coding?

Thanks. ;D
I see the SKU is not be stored same place as Product code, it only stored in "PRODUCT" table.
How can i get it?

"ECHO" from product table???????

Thanks.

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 10:21 am
by Teyno
Never worked with PHP before, but I looked into the architecture and this isn't hard to do.

Not taking any responsibility and just giving the basics.

in admin/model/sale/order.php find

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;
	}
You need to edit that query with a JOIN to get the SKU from another table.

Then you have to add the sku to the product array

in admin/controller/sale/order.php find

Code: Select all

$product_data[] = array(
						'name'     => $product['name'],
						'model'    => $product['model'],
						'option'   => $option_data,
						'quantity' => $product['quantity'],
						'price'    => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
						'total'    => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value'])
					);
There you insert

Code: Select all

'sku'    => $product['sku'],
Also in the invoice() function on same page you have to insert something like
$this->data['column_sku''] = $this->language->get('sku'); or just
$this->data['column_sku'] = 'SKU'; if you dont want to edit the language files, this is for the column header

Now you can use the variables $column_sku and $product['sku'] in your template

Please have in mind I am not a PHP developer but this is how I would TRY it :D, back-ups are advised.

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 10:23 am
by felizone
Apprecaited Teyno.
I will give a try.

I will post if it works for me.

Thank you.

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 10:45 am
by Teyno
Got you the query, tested in in phpmyadmin and works OK

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;
   }
Let me know if it works :) and also try if it works when a product has no SKU.. thats why I didn't do an INNER JOIN.

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 10:58 am
by nosecret
I am release extension SKU in INVOICE, perhaps that suitable for you. Please check link below:
http://www.opencart.com/index.php?route ... on_id=2646

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 11:01 am
by felizone
Teyno wrote:Got you the query, tested in in phpmyadmin and works OK

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;
   }
Let me know if it works :) and also try if it works when a product has no SKU.. thats why I didn't do an INNER JOIN.
Oops.... :laugh: It works perfect.
Teyno, YOU ARE MY SUPER STAR.

Appreciated your time.

Have a nice day. Cheers... O0

Re: Simple coding SKU ON INVOICE - Solved

Posted: Wed Dec 07, 2011 11:05 am
by felizone
It shows nothing there if product has no SKU.
Will this a bug? I think no...

It works perfect for me.

Thank you. Teyno

Re: Simple coding SKU ON INVOICE

Posted: Wed Dec 07, 2011 11:05 am
by felizone
nosecret wrote:I am release extension SKU in INVOICE, perhaps that suitable for you. Please check link below:
http://www.opencart.com/index.php?route ... on_id=2646
Thanks, but it's not suitable for me to show SKU all around.

Thanks.

Re: Simple coding SKU ON INVOICE - Solved

Posted: Wed Dec 07, 2011 5:40 pm
by Teyno
felizone wrote:It shows nothing there if product has no SKU.
Will this a bug? I think no...

It works perfect for me.

Thank you. Teyno
Your very welcome.. :)

Re: Simple coding SKU ON INVOICE

Posted: Mon Feb 20, 2012 10:47 pm
by afonte
I need to get my SKU on my invoices as well but I want to make sure I am understanding these instructions correctly before I start to fiddle.

1. I would edit the files as stated above.
2. Then run the query on my database thru PHPmyAdmin.

Let me know if I got this right so I can give it a go. Thanks! :)

Re: Simple coding SKU ON INVOICE

Posted: Thu Mar 29, 2012 7:16 am
by H2O
A HOW-To has been created 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: Simple coding SKU ON INVOICE

Posted: Sun Jan 12, 2014 1:09 am
by bedo02
Hi Teyno,

perfect :) works like a charm. I have created an very complicated way see post http://forum.opencart.com/viewtopic.php ... 878#p90940

I am no SQL expert, I was thinking about a join function as well, just did not know how to write it, you did it. Big thanks!
I am now migrating from 147 to 156 so had to rewrite all the functions, this saves me a lots of time and it is also future proof! :)

Here my vqmod file to add skus on invoice.

Code: Select all

<modification>
	<id>SKUs on Invoice</id>
	<version>1.0.0</version>
	<vqmver>1.0.8</vqmver>
	<author>Bedo & Teyno :)</author>

<file name="admin/model/sale/order.php">      
        
		<operation>
			<search position="replace"><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");]]></search>
			<add><![CDATA[
            $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 . "'");
          ]]></add>
		</operation>
        
	</file>
    
   	<file name="admin/controller/sale/order.php">
     
		<operation>
			<search position="after"><![CDATA['model'    => $product['model'],]]></search>
			<add><![CDATA[
            'sku'      => $product['sku'],
          ]]></add>
		</operation>
 	</file>       
<file name="admin/view/template/sale/order_invoice.tpl">

        <operation>
			<search position="before"><![CDATA[<td><b><?php echo $column_product; ?></b></td>]]></search>
			<add><![CDATA[
            <td><b><?php echo 'SKU'; ?></b></td>
          ]]></add>
		</operation>

<operation>
			<search position="before"><![CDATA[<td><?php echo $product['name']; ?>]]></search>
			<add><![CDATA[
            <td><?php echo $product['sku']; ?></td>
          ]]></add>
		</operation>

       <operation>
			<search position="replace"><![CDATA[<td align="right" colspan="4"><b><?php echo $total['title']; ?>:</b></td>]]></search>
			<add><![CDATA[
            <td align="right" colspan="5"><b><?php echo $total['title']; ?>:</b></td>
          ]]></add>
		</operation>

	</file>

 </modification>
just save this code as .xml and upload to vqmod/xml folder
... yes for this you need to install vqmod, but better then modify base files...
-- or just search for the above statements in <search></search> and add / replace as stated in the code..

@ Teyno - thanks Mister O0

Re: Simple coding SKU ON INVOICE

Posted: Wed Jan 29, 2014 4:01 am
by andyblackett
Hi there,

I'd love to have this functionality on our admin order invoice page but when I upload the xml file detailed above I just get an error "Warning: VQMod script XML syntax is invalid! Please contact the author for support." and nothing happens.

Are you able to advise on what might be wrong?

Best wishes
Andy

Re: Simple coding SKU ON INVOICE

Posted: Wed Jan 29, 2014 9:26 am
by nvedia
Can you please post your entire XML here?

Re: Simple coding SKU ON INVOICE

Posted: Wed Feb 12, 2014 7:17 am
by hamidg84
Hi

It says Warning: VQMod script XML syntax is invalid!

Can you please help?

Re: Simple coding SKU ON INVOICE

Posted: Thu Feb 20, 2014 9:34 am
by hamidg84
Anyone please??

Re: Teyno - Simple coding SKU ON INVOICE

Posted: Thu Jun 26, 2014 10:06 am
by rajkumar2086
Confirming that the mods tutored by teyno works perfect on 1.5.6.4
Im uploading my files to help others like myself who dont know a zilch on coding but would like to have sku
just upload to your home directory and unzip, the files will go sit in their respective places...
How it works
SKU returned for items with SKU
Blank SKU column for items without SKU

disclaimer - you are responsible for your actions. Kindly back up your admin folder before doing this ... it worked flawless for me but I can no way assure the same for you....(Yet I am sure it will)