Jump to content

Attach an extra PDF to order confirmation e-mail


Recommended Posts

Hello,

i'm trying to add a PDF (our law says we have to send Terms and conditions as attachment to the email) to the order confirmation email, but only found this

https://www.prestashop.com/forums/topic/532204-solved-attach-an-extra-pdf-to-order-confirmation-e-mail/

which does not work in version 1.7.4.3 ... i also looked if there were any modules, but the one that has this capability, says is works up to ver 1.7.2.5 ...

pls did I miss something somewhere or am just blind?

Thank you!

Link to comment
Share on other sites

  • 11 months later...

Hello,

for Prestashop 1.7.6  - add Terms to order_confirmation email.

classes/Mail.php

before this code: (line cca 570)

if ($fileAttachment && !empty($fileAttachment)) {
                // Multiple attachments?
                if (!is_array(current($fileAttachment))) {
                    $fileAttachment = array($fileAttachment);
                }

 

add this source:

if ($template == 'order_conf'){
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('terms.pdf'), 'terms.pdf', 'application/pdf'));
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('return_money.pdf'), 'return_money.pdf', 'application/pdf'));
}  

files term.pdf and return_money.pdf are in root directory of Prestashop

 

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Thanks! Work gr8! 

Do you know how to do it with other order status ?? I have changed order_conf to payment but pdf is blank :( 

I even want to make custom email and sent to file_get_contents parameters of order number like: SG3WC5F, is it possible ? :D

 

Link to comment
Share on other sites

  • 7 months later...
  • 5 months later...
On 10/6/2019 at 6:22 PM, JiVi said:

Not working for Presta 1.5 any change? I need please! thanks

 

 

 

Hello,

for Prestashop 1.7.6  - add Terms to order_confirmation email.

classes/Mail.php

before this code: (line cca 570)


if ($fileAttachment && !empty($fileAttachment)) {
                // Multiple attachments?
                if (!is_array(current($fileAttachment))) {
                    $fileAttachment = array($fileAttachment);
                }

 

add this source:


if ($template == 'order_conf'){
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('terms.pdf'), 'terms.pdf', 'application/pdf'));
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('return_money.pdf'), 'return_money.pdf', 'application/pdf'));
}  

files term.pdf and return_money.pdf are in root directory of Prestashop

 

 

Link to comment
Share on other sites

SOLVED for Presta 1.5 with 2 files, thanks

 

if ($template == 'es/order_conf') {
        $file1 = _PS_ROOT_DIR_ . '/TerminosyCondiciones.pdf';
        $file2 = _PS_ROOT_DIR_ . '/FormularioDesistimiento.pdf';
       

             $message->attach(new Swift_Message_Attachment(file_get_contents($file1), 'TerminosyCondiciones.pdf', 'application/pdf'));
               $message->attach(new Swift_Message_Attachment(file_get_contents($file2), 'FormularioDesistimiento.pdf', 'application/pdf'));

        }    
 

Link to comment
Share on other sites

  • 4 months later...

Hello JiVi,

I've tried your solution for PDF attachment, but for some reason it doesn't work for me. The test order ends up in white page on address https://www.yadeal.de/de/module/ps_wirepayment/validation for Firefox or 500 Internal Server Error for Chrome. Maybe you have some hints for me? I'm not a programmer so I'm doing just copyandpaste.

Thanks in advance.

Kind regards

Yulia

Link to comment
Share on other sites

On 4/14/2021 at 12:06 PM, Yulia T. said:

Hello JiVi,

I've tried your solution for PDF attachment, but for some reason it doesn't work for me. The test order ends up in white page on address https://www.yadeal.de/de/module/ps_wirepayment/validation for Firefox or 500 Internal Server Error for Chrome. Maybe you have some hints for me? I'm not a programmer so I'm doing just copyandpaste.

Thanks in advance.

Kind regards

Yulia

use this plugin, in free version you can set 2 actions as you need to send 2 x PDF https://store.getdatakick.com/en/modules/conseqs-free

Link to comment
Share on other sites

Hello Peter32,

thanks a lot for your quick respond and for your idea.

I've just installed module conseqs-ps17-0.7.0.zip on Prestashop 1.7.7.1 and it ended up in HTTP 500 Internal Server Error saying

Compile Error: Cannot declare class MailCore, because the name is already in use

FatalErrorException

Symfony\Component\Debug\Exception\FatalErrorException: Compile Error: Cannot declare class MailCore, because the name is already in use at classes/Mail_NOTWORKING.php:0

Do you maybe have any idea how to fix this?

Just in case I've added screenshot of the logs if it helps.

Kind regards

Yulia

 

Logs_Screenshot.PNG

Edited by Yulia T. (see edit history)
Link to comment
Share on other sites

29 minutes ago, Yulia T. said:

Hello Peter32,

thanks a lot for your quick respond and for your idea.

I've just installed module conseqs-ps17-0.7.0.zip on Prestashop 1.7.7.1 and it ended up in HTTP 500 Internal Server Error saying

Compile Error: Cannot declare class MailCore, because the name is already in use

FatalErrorException

Symfony\Component\Debug\Exception\FatalErrorException: Compile Error: Cannot declare class MailCore, because the name is already in use at classes/Mail_NOTWORKING.php:0

Do you maybe have any idea how to fix this?

Just in case I've added screenshot of the logs if it helps.

Kind regards

Yulia

 

Logs_Screenshot.PNG

As I have the plugin and it is working try this:

1. If you can upgrade prestashop to 1.7.7.3, use '1-Click Upgrade' plugin for that

2. check Module manager if you have plugin 'MailAlert' installed multiple times

3. check Module manager if you have plugin 'Consequences' installed multiple times

vbr

Link to comment
Share on other sites

Hi Peter32,

thanks a lot for your help and for advises.

I've checked both modules (plugins) MailAlert and Consequences for double installation, it wasn't.

Just in case I deinstalled Consequences for now and will try with upgrade to PS1.7.7.3. However I think I'll continue tomorrow as I need time to play with all this changes.

Once again thanks a lot for turbo-fast help 🙂

Kind regards and good night!

Yulia

 

Link to comment
Share on other sites

Hi Peter32,

I've received answer from Datakick with solution. I post it here maybe it can help somebody to fix the bug as I had:

"Hi,

you have to delete file /classes/Mail_NOTWORKING.php, or at least rename it to not have .php extension, for example to /classes/Mail_NOTWORKING.back

Then the module will work just fine"

In my case it helped.

So I didn't have to upgrade to PS1.7.7.3 yet.

Once again thank you very much for your help.

Kind regards

Yulia

Link to comment
Share on other sites

  • 4 months later...
On 10/6/2019 at 5:22 PM, JiVi said:

Hello,

for Prestashop 1.7.6  - add Terms to order_confirmation email.

classes/Mail.php

before this code: (line cca 570)

if ($fileAttachment && !empty($fileAttachment)) {
                // Multiple attachments?
                if (!is_array(current($fileAttachment))) {
                    $fileAttachment = array($fileAttachment);
                }

 

add this source:

if ($template == 'order_conf'){
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('terms.pdf'), 'terms.pdf', 'application/pdf'));
	$message->attach(\Swift_Attachment::newInstance(file_get_contents('return_money.pdf'), 'return_money.pdf', 'application/pdf'));
}  

files term.pdf and return_money.pdf are in root directory of Prestashop

 

Hello ! 

I tried this solution, but i got an error in the step of sending the meila !

may be the name of the file can cause this ? thank you 

Link to comment
Share on other sites

  • 1 year later...

I know this is a rather old post, but in case anyone is looking for an updated answer; here is my solution...

I made a solution for PrestaShop 8.1.0

I have overridden classes/Mail.php and essentially these are the lines that does the trick (where the PDF-file "TermsAndConditions.pdf" is located in the root of the site):

        if ($template == 'order_conf'){                        
            $message->attach(Swift_Attachment::fromPath('TermsAndConditions.pdf'));
        } 

Basically it just says that if we are about to send an email-order-confirmation ($template == 'order_conf'), then attach the PDF-file "TermsAndConditions.pdf" (which must be placed in the root-folder of the site).

To make it easy for you, I have attached my complete override-file, which should simply be uploaded to the folder: \override\classes of your PrestaShop-installation.

So, in essence:

1) Upload a PDF-file called TermsAndConditions.pdf to the root-folder of your site, containing your terms and conditions.

2) Upload the attached override-file to the folder \override\classes of your PrestaShop-installation.

Again, I developed this for PrestaShop 8.1.0 and I do not know whether it also works for other versions of PrestaShop.

 

Edit: There was a server-error when I tried to upload the attached file, and then I tried pasting it into this answer and marking it as 'code', but it kept responding with an error. And then when I tried to post my answer, the Cloudflare-implementation of this forum suddenly told me that I was now blocked from the forum ... under normal circumstances I could see why I would be flagged as trying to do something illegal when trying to post code to at website, but this forum is about helping each other out by SHARING CODE!!! ...so the Cloudflare-implementation of this site is clearly a problem - and probably a major part of why there are seldomly any NEW solutions found here. Sad. Just sad.

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...