Admin Invoice show GTIN

Open to all! Ask other shopowners for help.
Post Reply
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Admin Invoice show GTIN

Post by Pierre_P »

Any help to get the GTIN number to display on invoice?
From DB table products - products_gtin

In invoice.php i have created a new table heading Gtin and then to insert it where:
foreach ($order->products as $product) {....


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Admin Invoice show GTIN

Post by burt »

You add it in the same column as you added the heading, so if you added the GTIN heading after the "products model", then you would do similar;

echo '<td>' . $product['model'] . '</td>';
echo '<td>' . $product['gtin'] . '</td>';
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Admin Invoice show GTIN

Post by Kofod95 »

I don't think, however, that the gtin is added to the order, so you may need a catalog-hook to add it to the order_builder (I have an old post about adding a phone-number to the address, that may help). Alternatively, you could fetch the gtin from the products table directly, as I do with the location. The argument there was, that the location could potentially be changed between the time of the order and the time of picking the items for it, but the gtin should be stable, I guess?

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: Admin Invoice show GTIN

Post by Pierre_P »

The $product['gtin'] is not stored into orders so no go
error: Undefined index: gtin
Rather getting gtin straight from table products seems like solution

I had a look @Kofod95 at those options, yeah I don't know.
You know, my brain is fried after covid thing, i just cannot think anymore like i used to or getting too old :?
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Admin Invoice show GTIN

Post by Kofod95 »

@Pierre_P

Maybe:

Code: Select all

class hook_shop_siteWide_insertGtin {
  
  function listen_insertOrder($parameters) {
	  
	$order =& $GLOBALS['order'];

	$parameters['sql_data']['orders_products']['products_gtin'] = $GLOBALS['product']->get('gtin'), $order->products);
  }
  
}
You would have to add the field to orders_products in the database first.
I haven't tested and I'm quite unsure about $order->products in the end, as this is written purely from my head.

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: Admin Invoice show GTIN

Post by Pierre_P »

I have done this:
Below
foreach ($order->products as $product) {
added:
$product_gtin = product_by_id::build(Product::build_prid($product['id']));
$gtin = $product_gtin->get('gtin');

then only to echo $gtin

My invoice.php page is custom so i did not go and create a hook


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply