Page 1 of 1
Admin Invoice show GTIN
Posted: Wed Aug 10, 2022 2:49 pm
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) {....
Re: Admin Invoice show GTIN
Posted: Wed Aug 10, 2022 3:28 pm
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>';
Re: Admin Invoice show GTIN
Posted: Wed Aug 10, 2022 3:47 pm
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
Re: Admin Invoice show GTIN
Posted: Thu Aug 11, 2022 7:10 am
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

Re: Admin Invoice show GTIN
Posted: Thu Aug 11, 2022 7:33 am
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
Re: Admin Invoice show GTIN
Posted: Thu Aug 11, 2022 12:01 pm
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