Jump to content

Disable PDF attachment on order confirmation mail


Masteries

Recommended Posts

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

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 by Knowband Plugins (see edit history)
  • Like 1
Link to comment
Share on other sites

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 by Masteries (see edit history)
Link to comment
Share on other sites

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, 

 

 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...