MartinPersson Posted May 31, 2016 Share Posted May 31, 2016 (edited) 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 May 31, 2016 by MartinPersson (see edit history) Link to comment Share on other sites More sharing options...
MartinPersson Posted May 31, 2016 Author Share Posted May 31, 2016 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!! Link to comment Share on other sites More sharing options...
samverdyck Posted February 21, 2018 Share Posted February 21, 2018 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. Link to comment Share on other sites More sharing options...
yay Posted February 22, 2018 Share Posted February 22, 2018 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. 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. 2 Link to comment Share on other sites More sharing options...
Gorm Posted August 3, 2018 Share Posted August 3, 2018 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? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now