I’m using Dolibarr 12.0.4 and testing 13
Getting extra fields on pdf is now provided in these versions and a wiki page is present:
I’m following this wiki step by step to add a module complementary attribute. I even named the extra field/attribute exactly the same as in the wiki. The only difference is that I’m trying to achieve this on a sales order (template einstein is used as source) and not on an invoice.
Given code is copied and pasted as stated. The extra field will not show.
ksar
January 6, 2021, 3:38pm
2
Hello,
Have you tried eratosthene model ?
It normally includes extrafields automatically
Tried it out of the box. No Extra fields shown.
Then I modify the template as stated in the wiki. No results either.
My goal is to add some Product extrafields on Sales Order Line
ksar
January 6, 2021, 10:07pm
4
Hello,
The Extrafields that are automatically displayed is Extrafields of the object.
If you want to display product Extrafields on sales orders you should follow the wiki.
If you would like help you need to describe what you have done
Hi @ksar ,
Thanks for offering some help.
These are the steps (its a staging area so for testing purposes I’m editing source files):
created a complementary attribute on the products and services module with attribute code artiest
used the wiki as guide
modified /core/modules/commande/doc/pdf_eratosthene.modules.php
on line 38 added
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
on line 290+291 added after
$object->fetch_thirdparty();
$extrafieldsline = new ExtraFields($this->db);
$extralabelsline=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
on line 560 added
if ($object->lines[$i]->fk_product)
{
require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
$product = new Product($this->db);
$product->fetch($object->lines[$i]->fk_product);
$extrafields_product = new ExtraFields($this->db);
$extralabels_product = $extrafields_product->fetch_name_optionals_label($product->table_element);
$product->fetch_optionals($product->rowid, $extralabels_product);
}
on line 653 added
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->lines[$i]->array_options['options_artiest']), 0, 'L', 0);
used before $posYAfterDescription = $pdf->GetY();
ksar
January 7, 2021, 10:22am
6
Hi,
This line is wrong :
bvgeleuken:
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->lines[$i]->array_options['options_artiest']), 0, 'L', 0);
Should be something like :
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->array_options['options_artiest']), 0, 'L', 0);
Thanks. That did the trick.
My line is a copy from the wiki. So this has to be changed in the wiki.
ksar
January 7, 2021, 11:02am
8
Sorry but the Wiki is OK :
$outputlangs->convToOutputCharset($product->array_options['options_my_product_extra'])
You’re absolutely right. My bad.
When I look at the wiki it is possible to display the label of a value from a selectlist. But when I paste the code I get a 500 Error.
I replaced the code:
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->array_options['options_formaat']), 0, 'L', 0);
with
$pdf->MultiCell(0, 3, $extrafields->showOutputField('formaat', $object->array_options['options_formaat']), 0, 'L', 0);
ksar
January 8, 2021, 11:17am
10
Hello,
bvgeleuken:
I get a 500 Error.
Could you check the logs to see what is the issue ?
Nothing to see in the logs.
I think it’s a syntax error in the PDF.
ksar
January 11, 2021, 8:57am
12
Hi,
For error 500, you need to check your hosting logs not the Dolibarr logs.
ksar
January 11, 2021, 11:06am
14
Hello,
The error is :
PHP Fatal error: Uncaught Error: Call to a member function showOutputField() on null in…
Meaning that $extrafields
or $object->array_options['options_formaat']
is empty
Check how this two variables are created.
Found the error.
I wanted to display a product attribute/extra field. So I had to replace some code from the example in the wiki. This is the correct code to display the label and not the value:
$extrafields_product->showOutputField('my_extra', $product->array_options['options_my_extra']);
I changed: $extrafields
in $extrafields_product
I changed: $object->array_options
in $product->array_options
@ksar : Thanks for all the help
1 Like