PDF Invoice product custom fields

  • Posts: 91
  • Thank you received: 5
3 years 4 months ago #327069

-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.23
-- PHP version -- : 7.3.24
-- Browser(s) name and version -- : Chrome latest

Hello,

I have some product custom fields created and I want them to appear on the invoice, e.g. one of them is a statistical number.
They appeared on HTML invoice correctly.

I have bought today PDF invoice plugin and changed PHP code in
/plugins/hikashop/attachinvoice/attachinvoice/invoice.php
to make the invoice look like I want. But I don't see custom fields there.

Questions:
1) How can I add product custom fields to products table in PDF invoice? Can you prepare a new version of the plugin maybe? I didn't expect that it doesn't support CF.
2) Is there a way to show net price and tax on the PDF invoice as well?
3) I addes some data in the footer in the plugin field in Joomla. But the Polish characters don't appear correctly, although I checked the dejavusans font which should support them. Polish characters in product data appear correctly on PDF invoice.

Thanks for your support.

Please Log in or Create an account to join the conversation.

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
3 years 4 months ago #327080

Hi,

1. It does support custom fields, but not of the table "product".
The reason is that with the PDF plugin, the columns need to be spaced manually in pixels based on the available columns and the width available. And if we don't know how many columns there is to display, we can't set the width adequately.
If we were to add support for them, then, the likely result would be some of the columns of the listing of products going out of the page.
So the problem you're raising it quite well known but unfortunately, we couldn't find a suitable solution for it.
If you really want to add an extra column, you can edit the invoice file and add the HTML / PHP / CSS code to display it.
But I don't recommend adding generic "custom product fields" support as additional columns of the listing, even if you're a developer, as you'll end up with the listing going out of the page with more than 1 or 2 columns, even with extra CSS to cope with them.

2. The invoice, be it with the PDF plugin or not, will always display the taxes between the subtotal and the total. And then total will always be NET.
The subtotal, and the price of each product can be either with or without taxes. It depends on how is configured the "show taxed prices" setting in the HikaShop configuration.
And if you want to force it, you can add such code at the beginning of the invoice.php file of the plugin:
<?php $config->set('price_with_tax', 1); ?>

3. Could you provide the text that you added in the footer so that we can try to reproduce the issue ?

The following user(s) said Thank You: bolando

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 5
3 years 4 months ago #327193

Hello,

Thanks for your answer

1) OK, I see the reason.
But still I can try to add the fields under each product name.
So after the code

if ($config->get('show_code')) {
						echo '<br/>'.$product->order_product_code;
					} ?>
in /plugins/hikashop/attachinvoice/attachinvoice/invoice.php:224
I added
<br/>
					<?php
					$itemFields = $fieldsClass->getFields($item_type,$product,'product');
					if(!empty($itemFields)){
						foreach($itemFields as $field){
							echo $namekey = $field->field_namekey;
							echo $fieldsClass->show($field,$product->$namekey);
							echo '<br/>';
						}
					}?>
It displays correct 3 custom field names, but not values. What am I doing wrong?

2) Thanks, that clarifies a bit.

3) Please try with "Prezes Zarządu" (CEO). It displays like "Prezes Zarz?du"

Please Log in or Create an account to join the conversation.

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
3 years 4 months ago #327205

Hi,

1. $product contains the data of the product in the order (from the hikashop_order_product table), not the data of the product (from the hikashop_product table).
So you would need to add such code:
$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
And then you can use $productData->$namekey instead of $product->$namekey

3. I was able to reproduce the issue on my end.
I worked on it the whole afternoon and I can see the issue comes from the HTML2PDF we're using which breaks UTF8 characters (at least some) in the footer. I looked into the HTML2PDF library to try to fix it, but I couldn't find how.
All I can propose is to not use the "footer" option if you want to add this text and instead edit the invoice.php file of the plugin to add your text before the </page> tag at the end.
Or try not to use special characters.
A better solution would be to redo the plugin from scratch to use a more modern solution to generate the PDF but that's a big work.

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 5
3 years 4 months ago #327253

Hello,

1) Many thanks, I updated my code to

<br/>
<?php
$itemFields = $fieldsClass->getFields($item_type,$product,'product');
$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
if(!empty($itemFields)){
	foreach($itemFields as $field){
		$namekey = $field->field_namekey;
		if ($productData->$namekey) {
			echo $namekey . ": ". $productData->$namekey ."<br/>";
		}
	}
}?>
and it works now.

3) Thanks. The problem is that if I add this content to <page> than it's not always at the bottom of the page. I used even HTML entities but it didn't help. OK, if you change the plugin in the future, it will be a big help for many users.

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 5
3 years 4 months ago #327280

That's even a better version of the code, with full field names, in case somebody needs it:

<br/>
<?php
$itemFields = $fieldsClass->getFields($item_type,$product,'product');
$productClass = hikashop_get('class.product');
$productData = $productClass->get($product->product_id);
if(!empty($itemFields)){
	foreach($itemFields as $field){
		$namekey = $field->field_namekey;
		if ($productData->$namekey) {
			echo $fieldsClass->getFieldName($field) . ": ". $productData->$namekey ."<br/>"; 
		}
	}
}?>

The following user(s) said Thank You: deboni

Please Log in or Create an account to join the conversation.

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
3 years 4 months ago #327274

Hi,

2. The only solution I can see with the current PDF plugin is to create an image with the text you want in the footer, upload it to the joomla media manager and add the img tag of that image in the footer setting.
That way, you'll avoid the issue of the UTF8 characters not being rendered properly in the footer.

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds
Powered by Kunena Forum