Skip to main content

Dateiname Rechnung PDF mit Kundenname

11 months 4 weeks ago #369503 by metzlermedia
-- HikaShop version -- : 6.1.1
-- Joomla version -- : 5.4.0
-- PHP version -- : 8.4.12

Hallo,

Das neue Plugin enthält ja jetzt im Dateinamen auch die Bestellnummer. Jedoch wünscht mein Kunde, dass im Dateiname auch der Kundenname mit steht. Leider kenn ich mich mit PHP nicht so gut aus. Könnten Sie mir dazu bitte den Code ergänzend generieren?

$invoice_name = JText::sprintf('PDF_INVOICE', $data->data->order_invoice_number);
if($invoice_name == 'PDF_INVOICE')
$invoice_name = JText::_('INVOICE');
$mailer->addAttachment($invoiceFolder.DS.$invoiceFile,$invoice_name.'.pdf');

Vielen Dank.
Mit freundlichen Grüße
Kristina

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

11 months 4 weeks ago #369508 by nicolas
Hi,

You can do something like that:
Code:
$invoice_name = JText::sprintf('PDF_INVOICE', $data->data->billing_address->address_firstname.' '.$data->data->billing_address->address_lastname); if($invoice_name == 'PDF_INVOICE') $invoice_name = JText::_('INVOICE'); $mailer->addAttachment($invoiceFolder.DS.$invoiceFile,$invoice_name.'.pdf');

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

11 months 4 weeks ago - 11 months 4 weeks ago #369514 by metzlermedia
Thanks.
Unfortunately, the code doesn't work. The filename doesn't change.
Can you please help me again?
Last edit: 11 months 4 weeks ago by metzlermedia.

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

11 months 4 weeks ago #369517 by nicolas
Hi,

Well, the invoice file name is generated in 2 places in the code of the plugin.

The code you asked us about is the one used when the plugin generates the PDF invoice and adds it to the email sent to the customer.
However, there is another code:
Code:
$fileName = JText::_('INVOICE'); if($this->shipping_invoice){ $fileName = JText::_('SHIPPING_INVOICE'); } if(count($orderIds) == 1){ if(empty( $order->order_invoice_number)) $order->order_invoice_number = $order->order_number; if($this->shipping_invoice){ $fileName = JText::sprintf('PDF_SHIPPING_INVOICE', $order->order_invoice_number); if($fileName == 'PDF_SHIPPING_INVOICE') $fileName = JText::_('SHIPPING_INVOICE').'_'.$order->order_invoice_number; }else{ $fileName = JText::sprintf('PDF_INVOICE', $order->order_invoice_number); if($fileName == 'PDF_INVOICE') $fileName = JText::_('INVOICE').'_'.$order->order_invoice_number; } } ob_clean(); $html2pdf->Output(str_replace('/','',$fileName).'.pdf','D');
which is used to generate the invoice file when you click on the buttons of the interface to retrieve the invoice file.

So, if you're testing the change by using the buttons, it's normal that you don't see any change.
You would have to also change that second piece of code in a similar manner if you want it to affect the buttons.

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

11 months 4 weeks ago - 11 months 4 weeks ago #369531 by metzlermedia
Thank you very mutch.
That was the problem.

The new Code is:
Code:
$fileName = JText::_('INVOICE'); if($this->shipping_invoice){ $fileName = JText::_('SHIPPING_INVOICE'); } if(count($orderIds) == 1){ // Sicherstellen, dass die Rechnungsnummer (oder Bestellnummer) gesetzt ist if(empty( $order->order_invoice_number)) $order->order_invoice_number = $order->order_number; // Kunden-Nachnamen abrufen und NULL/Existenz prüfen $customerLastName = ''; if (isset($order->billing_address) && !empty($order->billing_address->address_lastname)) { $customerLastName = $order->billing_address->address_lastname; } else { $customerLastName = JText::_('CUSTOMER'); // Fallback Name } // Nachnamen bereinigen: Alle problematischen Zeichen (Leerzeichen, Punkte, Schrägstriche) durch Unterstrich ersetzen $search_chars = array('/', ' ', '.', ','); $sanitizedCustomerName = str_replace($search_chars, '_', $customerLastName); // BASIS DES DATEINAMENS: KUNDENNACHNAME-RECHNUNGSNUMMER // Enthält den Bindestrich zwischen Name und Nummer. $dynamicPart = $sanitizedCustomerName . '-' . $order->order_invoice_number; if($this->shipping_invoice){ $fileName = JText::sprintf('PDF_SHIPPING_INVOICE', $dynamicPart); if($fileName == 'PDF_SHIPPING_INVOICE') // Fallback: BEZEICHNUNG_KUNDENNAME-RECHNUNGSNUMMER $fileName = JText::_('SHIPPING_INVOICE').'_'.$dynamicPart; } else{ $fileName = JText::sprintf('PDF_INVOICE', $dynamicPart); if($fileName == 'PDF_INVOICE') // Fallback: BEZEICHNUNG_KUNDENNAME-RECHNUNGSNUMMER $fileName = JText::_('INVOICE').'_'.$dynamicPart; } } ob_clean(); // FINALE BEREINIGUNG: NUR Schrägstriche entfernen. // Da wir alle Leerzeichen vorher in Unterstriche umgewandelt haben, ist das sicherer. $outputFileName = str_replace('/', '', $fileName); $html2pdf->Output($outputFileName.'.pdf','D');
Last edit: 11 months 4 weeks ago by nicolas.
The following user(s) said Thank You: nicolas

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

Time to create page: 0.053 seconds
Powered by Kunena Forum