DEV Community

loading...

How to generate Prestashop Invoice by Customer name

franken profile image PrestaSOO Originally published at prestasoo.com on ・2 min read

Want to generate the invoice by customer name instead of the boring numbers?

It's so easy - on this Prestashop Tutorial, i will show you how to do it.

  • Step I: Modify function getFilename() in your-website/classes/pdf/HTMLTemplateInvoice.php.
  • Step II: Get the customer object by adding this line: $customer = new Customer((int)$this->order->id_customer);
  • Step III: Return with the name and the number.

Are you ready? Follow me.

Before you do anything else, please make sure backup your website / your file first. When you done, let's go.

I - Modify function getFilename()

Open and edit function getFilename() in your-website/classes/pdf/HTMLTemplateInvoice.php by using your favourite editor.

II - Get the customer object.

Find getFilename() function (line 500):

public function getFilename()
{
$id_lang = Context::getContext()->language->id;
$id_shop = (int)$this->order->id_shop;
$format = '%1$s%2$06d';

Change it to:

public function getFilename()
{
$id_lang = Context::getContext()->language->id;
$id_shop = (int)$this->order->id_shop;
$format = '%1$s%2$06d';
$customer = new Customer((int)$this->order->id_customer);

III - Return with the name and the number.

Look into this code:

return sprintf(
$format,
Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop),
$this->order_invoice->number,
date('Y', strtotime($this->order_invoice->date_add))
).'.pdf';

Change it to:

return sprintf(
$format,
Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop),
$this->order_invoice->number,
date('Y', strtotime($this->order_invoice->date_add))
).''.$customer->firstname.''.$customer->lastname.'.pdf';

Final - Enjoy your result

The invoice name will be IN_number_customername.pdf. For example : IN000001_Natalia_Eva.pdf.

Is it cool, huh? Don't forget our blog to find the useful Prestashop tutorials.

Have a nice weekend!

Discussion (0)

pic
Editor guide