Jump to content

PDF attachment in the Merchandise return email


StevenFree

Recommended Posts

Hello

After one week to looking for how to add a the pdf order return for the merchandises, finally i want to share my work here for the others

Process:

Usually, the user have to find into his personal account , and print the doc pdf return , and insert it into his package...very long and boring

With this modification, you'll be able to send directly the pdf doc into the email send by prestashop ( template: order_return_state.html)

 

Find AdminReturnController.php in controllers/admin , and add this code

Don't forget to add in the section " mail " ,  the value  " $file_attachement, "

   $orderReturnState = new OrderReturnState($orderReturn->state);
                        $vars = [
                            '{lastname}' => $customer->lastname,
                            '{firstname}' => $customer->firstname,
                            '{product_details}' => $products,                                                
                            '{order_reference}' => $order->reference,  
                          //'{id_order}' => $this->object->id,
                          '{id_order_return}' => 'RE' . sprintf('%06d', $id_order_return),
                            '{state_order_return}' => (isset($orderReturnState->name[(int) $order->id_lang]) ? $orderReturnState->name[(int)  $order->id_lang] : $orderReturnState->name[(int) Configuration::get('PS_LANG_DEFAULT')]),
                                                
                        ];

                                      // Here the code to send the doc pdf by mail
                                        $pdf = new PDF($orderReturn, PDF::TEMPLATE_ORDER_RETURN, $this->context->smarty);
                                        $file_attachement['content'] = $pdf->render(false);
                                        $file_attachement['name'] = $pdf->filename;
                                        $file_attachement['mime'] = 'application/pdf';
                                        
                                        
                        Mail::Send(
                            (int) $order->id_lang,
                            'order_return_state',
                            $this->trans(
                                'Your order return status has changed',
                                [],
                                'Emails.Subject',
                                $orderLanguage->locale
                            ),
                            $vars,
                            $customer->email,
                            $customer->firstname . ' ' . $customer->lastname,
                            null,
                            null,
                            $file_attachement,
                            null,
                            _PS_MAIL_DIR_,
                            true,
                            (int) $order->id_shop
                        );

 

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