Product extrafield in PDF invoice

Hello i serched the forum but dident find an answer. I am traying to put product extra field in PDF invoice and i tried all solution that are on https://wiki.dolibarr.org/index.php/Add_Extrafields_on_PDF_Models

I would like to put in seperate lines like
Ford Mustang
Serial: xxxxxxxx
Mileage: xxxxxx

Can someone please help.
Thanks in advance

Hi,

What is your question ?.

Hi

How do i put extrafields of product in invoice

is this the right way
$outputlangs->convToOutputCharset($product->array_options[‘options_my_product_extra’]) or do i have to rename options_my_product_extra to options_my_product_mileage

Hi,

You need to use options_my_product_**********
Where ********** is equal to the Attribute code of the Extrafield

Hi,

Just tried and dident work.

Can you tell me if my code is corect

				// Loop on each lines
				for ($i = 0; $i < $nblines; $i++)
				{
					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);
					}
					$outputlangs->convToOutputCharset($product->array_options['options_my_product_letnik']);
					$object->lines[$i]->fetch_optionals($object->lines[$i]->rowid,$extralabelsline);
					$curY = $nexY;
					$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
					$pdf->SetTextColor(0, 0, 0);

					// Define size of image if we need it

Hi i made the atribut title to load but not the atribute.

					$pdf->MultiCell(0, 3, $outputlangs->transnoentities("Prevozeni",":")." ".$outputlangs->convToOutputCharset($product->array_options['options_product_prevozeni'],"km"), 0, 'L', 0);
					$pdf->MultiCell(0, 3, $outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($product->array_options['options_my_product_letnik']), 0, 'L', 0);
					$posYAfterDescription = $pdf->GetY();

Hi,

Sorry I was too quick,
You need to use options_**********
Where ********** is equal to the Attribute code of the Extrafield

1 Like

One more thing what about pick field so it wont show 1 for first item

Hi,

What is a “pick field” ?

I ment select list

my appologies :slight_smile:

https://wiki.dolibarr.org/index.php/Add_Extrafields_on_PDF_Models#Special_Case_for_Extrafields_type_.22Select_list.22

I done that and on creatig PDF i get 500 error

Made it like that

$pdf->MultiCell(0, 3, $outputlangs->transnoentities("Številka šasije")."".(":")." ".$extrafields->showOutputField('my_extra', $object->array_options['options_stevilka_sasije']), 0, 'L', 0);

Hi,

Need to replace

$pdf->MultiCell(0, 3, $outputlangs->transnoentities("Številka šasije")."".(":")." ".$extrafields->showOutputField('my_extra', $object->array_options['options_stevilka_sasije']), 0, 'L', 0);

by

$pdf->MultiCell(0, 3, $outputlangs->transnoentities("Številka šasije")."".(":")." ".$extrafields->showOutputField('stevilka_sasije', $object->array_options['options_stevilka_sasije']), 0, 'L', 0);

Still get 500 error

dose have to be $object->array_options or $product->array_options

Tried bouth and dont work

Hi,

Depends where you have created the “stevilka_sasije” extrafield

  • if it is created on product then $product->array_options
  • if it is created on invoice then $object->array_options

Tried and still get 500 error

What Error ?
Give details please

Hi,

Thanks for the solutions but i decidet to do with text field insted of select list field

https://wiki.dolibarr.org/index.php/Add_Extrafields_on_PDF_Models

Is good for extrafield in PDF ok.
But for select list, PROBLEM.
I have had to comment momentarily, the line that gives me error (PDF crash)

        $object->fetch($rowid);
        $object->fetch_optionals($rowid,$extralabels);
        $extrafields = new ExtraFields($db);
//      $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);

Special Case for Extrafields type “Select list” NOT WORKING

        $pdf->MultiCell(0, 3, 'LISTA: '.$outputlangs->convToOutputCharset($object->array_options['options_lista']), 0, 'L', 0);

LISTA: 2

AND

    $pdf->MultiCell(0, 3, 'LISTA: '.$extrafields->showOutputField('lista', $object->array_options['options_lista']), 0, 'L', 0);

not possible with the ($extralabels=$extrafields->fetch_…) // commented

Please HELP!

Hi,

What error ?

What is the extra field configuration ?

Can you share the full model ?