Community Forums

Simple coding SKU ON INVOICE

General support for technical problems with OpenCart v1.x

Simple coding SKU ON INVOICE

Postby felizone » Tue Dec 06, 2011 5:28 pm

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
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE

Postby uksitebuilder » Tue Dec 06, 2011 5:33 pm

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
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: Simple coding SKU ON INVOICE

Postby felizone » Wed Dec 07, 2011 1:31 am

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
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE

Postby felizone » Wed Dec 07, 2011 2:13 am

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.
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE

Postby Teyno » Wed Dec 07, 2011 2:21 am

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.
Teyno
 
Posts: 31
Joined: Tue Dec 06, 2011 9:37 am

Re: Simple coding SKU ON INVOICE

Postby felizone » Wed Dec 07, 2011 2:23 am

Apprecaited Teyno.
I will give a try.

I will post if it works for me.

Thank you.
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE

Postby Teyno » Wed Dec 07, 2011 2:45 am

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.
Teyno
 
Posts: 31
Joined: Tue Dec 06, 2011 9:37 am

Re: Simple coding SKU ON INVOICE

Postby nosecret » Wed Dec 07, 2011 2:58 am

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
nosecret
 
Posts: 219
Joined: Tue Dec 28, 2010 4:28 am

Re: Simple coding SKU ON INVOICE

Postby felizone » Wed Dec 07, 2011 3:01 am

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
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE - Solved

Postby felizone » Wed Dec 07, 2011 3:05 am

It shows nothing there if product has no SKU.
Will this a bug? I think no...

It works perfect for me.

Thank you. Teyno
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE

Postby felizone » Wed Dec 07, 2011 3:05 am

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.
felizone
 
Posts: 59
Joined: Thu Apr 08, 2010 7:28 am

Re: Simple coding SKU ON INVOICE - Solved

Postby Teyno » Wed Dec 07, 2011 9:40 am

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.. :)
Teyno
 
Posts: 31
Joined: Tue Dec 06, 2011 9:37 am

Re: Simple coding SKU ON INVOICE

Postby afonte » Mon Feb 20, 2012 2:47 pm

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! :)
afonte
 
Posts: 20
Joined: Thu Feb 09, 2012 2:50 pm

Re: Simple coding SKU ON INVOICE

Postby H2O » Wed Mar 28, 2012 11:16 pm

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:
viewtopic.php?f=121&t=57412
A good site for e-commerce advice.
H2O
 
Posts: 26
Joined: Tue Feb 28, 2012 11:36 pm


Return to General Support

Who is online

Users browsing this forum: hashmat, SimplyToyz and 78 guests

Hosted by Arvixe Web Hosting