Dateiname Rechnung PDF mit Kundenname

  • Posts: 29
  • Thank you received: 2
  • Hikashop Business
2 days 15 hours ago #369503

-- 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.

  • Posts: 84727
  • Thank you received: 13792
  • MODERATOR
2 days 10 hours ago #369508

Hi,

You can do something like that:

$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.

  • Posts: 29
  • Thank you received: 2
  • Hikashop Business
1 day 17 hours ago #369514

Thanks.
Unfortunately, the code doesn't work. The filename doesn't change.
Can you please help me again?

Last edit: 1 day 14 hours ago by metzlermedia.

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

  • Posts: 84727
  • Thank you received: 13792
  • MODERATOR
1 day 16 hours ago #369517

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:

			$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.

  • Posts: 29
  • Thank you received: 2
  • Hikashop Business
15 hours 46 minutes ago #369531

Thank you very mutch.
That was the problem.

The new Code is:

$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 hours 16 minutes 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.067 seconds
Powered by Kunena Forum