Masteries Posted August 7, 2018 Share Posted August 7, 2018 I use SMTP mailing on my shop since the regular PHP version was causing problems with mails sometimes not sending and a lot of the times going to the junk folder. However, this is causing the email storage to be filled very quickly. I noticed that when a customer gets order confirmation e-mail, they also get a PDF invoice (or order summary). Meaning, outgoing emails is attaching these PDFs & causing storage to be depleted quickly. Here's what I tried: The order confirmation status already has "Attach PDF invoice" unchecked on Orders > Statuses so I tried disabling the "Allow customer to view and download PDF" option on that status. This caused few other problems, now the customers didn't even receive confirmation emails and they were also not able to view PDFs on their account on the shop. Is it possible to stop attaching PDFs in outgoing emails without causing the problems stated above? Link to comment Share on other sites More sharing options...
Masteries Posted August 12, 2018 Author Share Posted August 12, 2018 Bumping topic. Still looking for a solution. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted August 13, 2018 Share Posted August 13, 2018 (edited) Hi, Ideally, It should be fixed from the admin but if it's not working, Try the following solution (As you haven't mentioned the PS version so providing the solution for PS1.6) Edit the classes/PaymentModule.php & find the validateOrder function & search the following line inside the function. // 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; } & Replace with same with // 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'; $file_attachement = null; } else { $file_attachement = null; } I hope it will help. Edited August 13, 2018 by Knowband Plugins (see edit history) 1 Link to comment Share on other sites More sharing options...
Masteries Posted August 15, 2018 Author Share Posted August 15, 2018 (edited) On 8/13/2018 at 2:46 PM, Knowband Plugins said: Hi, Ideally, It should be fixed from the admin but if it's not working, Try the following solution (As you haven't mentioned the PS version so providing the solution for PS1.6) Edit the classes/PaymentModule.php & find the validateOrder function & search the following line inside the function. // 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; } & Replace with same with // 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'; $file_attachement = null; } else { $file_attachement = null; } I hope it will help. Bollocks, I knew I forgot to mention the version, it's Prestashop 1.6.1.17. Anyhow, your method did the trick. I made an override for it instead of editing the core file using <?php class PaymentModule extends PaymentModuleCore { } PaymentModule originally has an abstract class, so I wasn't sure whether to use just the regular class or abstract class when naming the override, but I just went with the one above and it seems to work. Also, I think a more simpler solution would be to just not include $file_attachment on Mail::Send for the order_conf status. The code is directly below the one you showed me: if (Validate::isEmail($this->context->customer->email)) { Mail::Send( (int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $this->context->customer->email, $this->context->customer->firstname.' '.$this->context->customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop ); } } to: if (Validate::isEmail($this->context->customer->email)) { Mail::Send( (int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $this->context->customer->email, $this->context->customer->firstname.' '.$this->context->customer->lastname, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop ); } } My concern for my version of the fix is, can it break something? Edited August 15, 2018 by Masteries (see edit history) Link to comment Share on other sites More sharing options...
Knowband Plugins Posted August 15, 2018 Share Posted August 15, 2018 Hi, Great:) Yes, You can do it through override as well. The solution which you have used is similar to the one which I had specified. Instead of the passing null value in the Mail function, I had suggested to set the null value for $file_attachement variable Anyway, I don't think it will break anything, 1 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