Jump to content

Why my Invoices are not attached to mails?


Recommended Posts

Hi,

I have 1.5.0.17 (and can not easily upgrade to 1.5.2) and I am not able to attach invoice to mail, which confirms payment (nor to any other mail) to customer. I am not sure, if it is an error or just bad settings, but I have set "send mail to customer" for appropriate statuses and I do not know about any other settings related with it.

Are there any "rules", what and how must be something set to attach invoice?

I have "advanced stock management" switched on, language Czech (but switch to English did not help). I have changed fonts for PDF generation, but PDF invoice generation in backend office works fine, so it is not the reason of the problem.

I use bankwire and cashondelivery payments, both have the same problem.

 

Has somebody a tip? For example - mail "Shipped" is send only if the tracking number is filled (and it is not described in 1.5 manual). Is there something similar with invoices?

Link to comment
Share on other sites

  • 3 weeks later...

i would like a solution to this problem too.

When someones chooses Bankwire payment, and confirms his order he get's the right email.

 

But when in the BackOfffice the state of the order is changend to PaymentAccepted, the customer should get an invoice with his email. I'v been trying but without luck so far

 

--- found it :) ---- bit strange but it works. just check the checkmark for Allow customer ..... PDF ......

Edited by mvanrijnen (see edit history)
Link to comment
Share on other sites

i would like a solution to this problem too.

When someones chooses Bankwire payment, and confirms his order he get's the right email.

 

But when in the BackOfffice the state of the order is changend to PaymentAccepted, the customer should get an invoice with his email. I'v been trying but without luck so far

 

--- found it :) ---- bit strange but it works. just check the checkmark for Allow customer ..... PDF ......

 

Yes the user can then see his invoice in his account on the website. But it doesnt mail the invoice as an attachment to the user alone with the order confirmation.

At least not in my shop. :(

 

So I would like to know how this is solved as well, so my customers can get the invoice as an attachment.

Link to comment
Share on other sites

  • 2 months later...

Hi guys,

 

I have the same problem: I can see the invoices in the back office of the shop, but the pdf is not attached to the order confirmation mails which are sent to customers. I have checked the status page, send invoice is marked, but It doesn't matter. Also with other statusses like Payment Accepted, an email is sent to the customer but no invoice is attached, while the option is marked in the back-office.

I tried all configuration options in the back office, but no change: The invoice-pdf is not attached to any mail. The normal mailing works perfect.

Can you please help me with this? Thanks!

 

I am using PrestaShop 1.5.3.1 by the way.

Edited by mister006 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hello, same problem here!

With that code i can attach the invoice on mail after order is paid>>>>i mean payment accepted

 

i added these lines on Mail.php

 

if(strpos($template,'payment')) {
$message->attach(new Swift_Message_Attachment(file_get_contents("/pdf-invoice.php?id_order=" . $template_vars['{id_order}']), "invoice.pdf", "application/pdf"));}

 

 

The problem now is that i m attaching a blank mail!

Any way to fix blank mails? I think something is wrong with my "path" of generated pdfs.

 

 

Result i m getting in payment mails is an attached blank file with name "invoice.pdf" 0kb

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Dans paymentModule.php j'ai trouvé ça. Est- ce qu'on ne peut pas mixer tout ça ? :D

 

// Join PDF invoice
 if ((int)(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number)
 {
  $fileAttachment['content'] = PDF::invoice($order, 'S');
  $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf';
  $fileAttachment['mime'] = 'application/pdf';
 }
 else
  $fileAttachment = NULL;
 if (Validate::isEmail($customer->email))
  Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I've solved this issue on Prestashop 1.4.9 You have to add the following on /classes/Mail.php on the function Send() just before the line with the comment: /* Send mail */ (in my file line 201):

 

if (strpos($template, 'payment')){
   $id_factura = $templateVars['{id_order}'];
   $orden = new Order($id_factura);
   $factura['content'] = PDF::invoice($orden, 'S');
   $factura['name'] = $id_factura.'.pdf';
   $factura['mime'] = 'application/pdf';
   $message->attach(new Swift_Message_Attachment($factura['content'], $factura['name'], $factura['mime']));
  }

 

This code attaches the invoice to 'Payment accepted' emails. If you want to attach the invoice to other emails just find the name of the template's mail and add it to the condition on the if statement. For example, if you want to attach the invoice too on the Shipped emails your code should look like this:

 

if (strpos($template, 'payment' || strpos($template, 'shipped')){
   $id_factura = $templateVars['{id_order}'];
   $orden = new Order($id_factura);
   $factura['content'] = PDF::invoice($orden, 'S');
   $factura['name'] = $id_factura.'.pdf';
   $factura['mime'] = 'application/pdf';
   $message->attach(new Swift_Message_Attachment($factura['content'], $factura['name'], $factura['mime']));
  }

 

I hope this help somebody, I googled around but I've found a lot of questions about this but no answer.

 

Ivan.

  • Like 2
Link to comment
Share on other sites

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

Hi isoler,

 

i have read your instruction and include your code.

 

It runs perfect. It's now possible. Realy nice!

 

But I have installed the module: M4 PDF Extensions v1.7.1

 

This module generate my invoices with a selfmade template.

 

In the attachement is actually the "original/old" invoice. Is it possible to attache the new invoice from M4?

 

If you need more details, please say me...

 

Thank you for answere.

 

Cheers

Link to comment
Share on other sites

Hi isoler,

 

i have read your instruction and include your code.

 

It runs perfect. It's now possible. Realy nice!

 

But I have installed the module: M4 PDF Extensions v1.7.1

 

This module generate my invoices with a selfmade template.

 

In the attachement is actually the "original/old" invoice. Is it possible to attache the new invoice from M4?

 

If you need more details, please say me...

 

Thank you for answere.

 

Cheers

 

Hi Dognose,

 

If you want to change the invoice that it's sending now for the one that generates the module you have told, you have to change this line at the code that I've provided:

$factura['content'] = PDF::invoice($orden, 'S');

 

In this line we are calling the function invoice() that is defined in the file /classes/PDF.php so we are generating an invoice Prestashop's like. If you want to send the invoice that your module generates we have to call the function that do this in the file usually located at /modules/yourmodule/yourmodule.php.

 

I didn't worked with that module so I don't know wich is that function. You have to look at the *.php file of the module and search for the function that generates the invoice, if you need help, upload the file and I will take a look at that and I'll try to guide you ;)

Link to comment
Share on other sites

Hi,

 

thank you for fast answere. I understand what you mean. It sounds god.

 

I just do me hard to find the right file in this module. I hope it's the right.

 

I have send you parallel a PN with a link from me, to download the complete module.

 

Thank you for looking.

 

Cheers

pdf.php

Link to comment
Share on other sites

Hi,

 

thank you for fast answere. I understand what you mean. It sounds god.

 

I just do me hard to find the right file in this module. I hope it's the right.

 

I have send you parallel a PN with a link from me, to download the complete module.

 

Thank you for looking.

 

Cheers

 

Hi Dognose,

 

Replace the whole code that I've told you for this one on the file /classes/Mail.php:

if (strpos($template, 'payment')){
require_once(dirname(__FILE__).'/../modules/m4pdf/M4OrderDetail.php');
$id_factura = $templateVars['{id_order}'];
$generator = new M4OrderDetail();
$invoice_content = $generator->generatePDF('invoice'.sprintf('%06d', $id_factura).'.pdf', 'S', Configuration::get('M4TPL_PDF_INVOICE'));
$factura['content'] = $invoice_content;
$factura['name'] = $id_factura.'.pdf';
$factura['mime'] = 'application/pdf';
$message->attach(new Swift_Message_Attachment($factura['content'], $factura['name'], $factura['mime']));
  }

 

Test it and told me if it worked ;)

Edited by isoler (see edit history)
Link to comment
Share on other sites

  • 3 months later...

:angry: Anyone made it work with 1.5?

I have found that solution for PS 1.5.5:

https://github.com/PrestaShop/PrestaShop/commit/9ff0d601589fdf791a8bd895de187bb45eb7939f

 

It works in my PS 1.5.4.1 making theese changes in classes\order\OrderHistory.php file:

 

Arround line 370, replace this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`

by this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`

And arround line 403, replace this:

            if (Validate::isLoadedObject($order))
                Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
                    null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop);

by this:

            if (Validate::isLoadedObject($order))
            {
                // Join PDF invoice if order state is "payment accepted"
                if ((int)$result['id_order_state'] === 2 && (int)Configuration::get('PS_INVOICE') && $order->invoice_number)
                {
                    $context = Context::getContext();
                    $pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $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;

                Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
                    null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop);
            }

I guess it will not be difficult to adapt these changes to other sub-versions of PS 1.5.

Edited by pepitofgg (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 months later...

I have found that solution for PS 1.5.5:

https://github.com/PrestaShop/PrestaShop/commit/9ff0d601589fdf791a8bd895de187bb45eb7939f

 

It works in my PS 1.5.4.1 making theese changes in classes\order\OrderHistory.php file:

 

Arround line 370, replace this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`

by this:

SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`

And arround line 403, replace this:

            if (Validate::isLoadedObject($order))
                Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
                    null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop);

by this:

            if (Validate::isLoadedObject($order))
            {
                // Join PDF invoice if order state is "payment accepted"
                if ((int)$result['id_order_state'] === 2 && (int)Configuration::get('PS_INVOICE') && $order->invoice_number)
                {
                    $context = Context::getContext();
                    $pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $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;

                Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
                    null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop);
            }

I guess it will not be difficult to adapt these changes to other sub-versions of PS 1.5.

 

These changes are already in 1.5.6.1 but not works for me

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

The addWithemail function in OrderHistory.php is limiting the invoice annexing to the order state "payment accepted".

 

So in case you changed the status for invoice creation, you have to modify the following code :

                // Join PDF invoice if order state is "payment accepted"
                if ((int)$result['id_order_state'] === 2 && (int)Configuration::get('PS_INVOICE') && $order->invoice_number)

Example for status "shipped" (ID = 4) :

                // Join PDF invoice if order state is "shipped"
                if ((int)$result['id_order_state'] === 4 && (int)Configuration::get('PS_INVOICE') && $order->invoice_number)
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Bloody hell, why there is checkmark for sending PDF invoice or all statuses - even custom ones - when there is no way to attach invoice to other status than payment and bankwire awaiting payment without PHP hack?

 

I'm not good at PHP - but if you change the line above to 

if (((int)$result['id_order_state'] === 2 || (int)$result['id_order_state'] === 16) && (int)Configuration::get('PS_INVOICE') && $order->invoice_number)

You can enable sending PDF invoice for multiple statuses (in this case - 2 and 16 - where 16 is my manually created status)

It wors in 1.6.0.14

 

...But I hope that one day develeopers will fix it.... But may you can simply throw away condition about order state - and it will be up to you and checkboxes ;)

Edited by pixelofficer (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Hi,

 

Simple hack for 1.6.0.9

 

Go to Location -> translations -> translate email template  

core translations ! and select language. Then, go to shipping template, you'll find edit html where you have source code : copy all that code and paste it to payment email template !

 

Then, go to Orders->status->payment and check mark as shipped, mark as paid etc.

 

And now when you have a new order, just change the status to payment accepted and they will recive the shipped email template and the pdf invoice.

 

Do not forget to edit the loiality module if installed ! Change the loiality points validate to payment status instead of shipped.

Link to comment
Share on other sites

×
×
  • Create New...