Jump to content
MartinPersson

[Solved] Attach an extra PDF to order confirmation e-mail

Recommended Posts

Hi

 

I'm currently trying to add an extra PDF-file to the order confirmation mail. At the moment it already contains the invoice (by default), but I need to add a static PDF-file (according to danish law), so the order confirmation contains both PDF-files.

 

I tried to look around for previous answers, but it seems like the code has changed a bit through times, so at the moment, I'm not sure if I should change anything in /classes/mail.php, /pdf/ or anywhere else.

 

If somebody knows, could you kindly share the information?

 

(ressources I've already read about adding an extra file to e-mail templates:

https://www.prestashop.com/forums/topic/456725-attachment-pdf-on-email-is-empty/

https://www.prestashop.com/forums/topic/309979-solvedadd-a-fix-pdf-to-outgoing-e-mail/)

Edited by MartinPersson (see edit history)

Share this post


Link to post
Share on other sites

Oh my god - Thank you so much!

I've been looking at classes/PaymentModule.php for so long and trying a lot of different changes (all kinds of combination of things found in this forum) - all resulting in server error 500 (either when loading website or when completing payment).

 

Your code just solved it right away - THANK YOU!!  :)

Share this post


Link to post
Share on other sites

Does this solution works the same way in Prestashop 1.7?

I did exa

On 31-5-2016 at 10:28 PM, mdekker said:

It is possible to change the attachment in the file /classes/PaymentModule.php. This is an array with the current invoice (can be accessed with $params['order_invoice_list']). You should turn this into a 2D array and add another array with the data.
 
That would be probably look like this:
From:


// Join PDF invoice
if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) {
    $order_invoice_list = $order->getInvoicesCollection();
    Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list));
    $pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty);
    $file_attachement['content'] = $pdf->render(false);
    $file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf';
    $file_attachement['mime'] = 'application/pdf';
} else {
    $file_attachement = null;
}

To


// Join PDF invoice
if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) {
    $order_invoice_list = $order->getInvoicesCollection();
    Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list));
    $pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty);
    $attachment = array();
    $attachment['content'] = $pdf->render(false);
    $attachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf';
    $attachment['mime'] = 'application/pdf';
    
    $extra_pdf = array();
    $extra_pdf['content'] = Tools::file_get_contents(_PS_ROOT_DIR_.'extradocs/extrainfo.pdf');
    $extra_pdf['name'] = 'some_annoying_information_from_the_Danish_government__please_ignore_it.pdf';
    $extra_pdf['mime'] = 'application/pdf';

    $file_attachement = array($attachment, $extra_pdf);
} else {
    $file_attachement = null;
}

 

Does this solutions works the same way in Prestashop 1.7?

I did exactly what you explained, and I'm getting a file in my mail, but it seems the file can't be found, see screenshot. 
It stays at "downloading", can't open it. 

Schermafbeelding 2018-02-21 om 16.48.19.png

Share this post


Link to post
Share on other sites
17 hours ago, samverdyck said:

Does this solution works the same way in Prestashop 1.7?

I did exa

 

Does this solutions works the same way in Prestashop 1.7?

I did exactly what you explained, and I'm getting a file in my mail, but it seems the file can't be found, see screenshot. 
It stays at "downloading", can't open it. 

Schermafbeelding 2018-02-21 om 16.48.19.png

 

Make sure that the path is correct to the file, if your root category doesn't have an ending slash, it probably won't find the file. So try adding a / before extradocs.

  • Like 2

Share this post


Link to post
Share on other sites
On 5/31/2016 at 9:06 PM, mdekker said:

Interesting. Let me see if I can sort that out for you.

 

The procedure has indeed changed a lot.

 

It is now:

Customer pays => payment module redirects to payment page => customer returns to validation page => validation page (usually generated by the payment module) calls Order::validateOrder() to verify whether everything is correct => Mail should be sent => Customer sees confirmation page

 

So, I think that Order::validateOrder is the best place to attach a PDF.

I am using Prestashop 1.7.3.0

The solution doesn't seem to be working for me. 

It seems that Order::validateOrder is called from somewhere else than /classes/PaymentModule.php: as a test, I have commented out the whole section dedicated to attachments, so normally I should not get any file attached to the order confirmation email. 

However, I still receive the normal bill attached to the email.

For testing purpose, I'm using the wire transfer module and then change the status of the order in the back-office in order to simulate a real payment. 

Does anybody have an idea?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More