Jump to content

Add attachment when order status changes


Recommended Posts

Hi there,

 

I'd like to know if the following is possible:

 

I created a custom orderstatus and the email that goes with. That part all works fine.

 But what I would really like is to add the invoice (PDF) to the email as an attachment.

 

Is that possible and if so, how? Been look through modules for ages, but no luck finding a suitable one yet.

 

Cheers,

 

Cees

Link to comment
Share on other sites

  • 1 year later...

Hi, I found some solutions...

 

In /classes/order/OrderHistory.php

 

Around line 410, is a function that sends mail with pdf only on "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->id).'.pdf';
					$file_attachement['mime'] = 'application/pdf';
				}

It takes order status by ID.

 

So, under this, add code.

elseif ((int)$result['id_order_state'] === 23 && (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->id).'.pdf';
					$file_attachement['mime'] = 'application/pdf';
				}

And in "elseif ((int)$result['id_order_state'] === 23" -> instead of 23 add your status one ID.

 

So it will look like:  (red is old code and green is new)

                // 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->id).'.pdf';
                    $file_attachement['mime'] = 'application/pdf';
                }

                elseif ((int)$result['id_order_state'] === 23 && (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->id).'.pdf';
                    $file_attachement['mime'] = 'application/pdf';
                }

                else
                    $file_attachement = null;

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

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