Check the complete article in Linkedin
Challenge
The default functionality of PrestaShop allows you to send the following three emails to the customer after he/she has placed an order.
- Payment confirmation mail
- Order confirmation mail (invoice PDF will be attached with this email).
- Delivery mail (Delivery PDF will be attached with details of delivery).
But the customer wanted Only Two emails to be sent instead of Three.
Both Order and Delivery Email has respective Invoice and Voucher attached as PDFs.
Solution
After a brain storming session, we decided to combine the Order and Delivery mail into One email.
The only way out was to integrate the Voucher PDF with Order confirmation mail. So the Order confirmation email had 2 attached pdfs. i.e. Order Invoice and Delivery details pdf(Voucher)
The class “PaymentModule” needed to be extended and the delivery details pdf(Voucher) was attached along with the confirmation mail.
Check how we extended the existing to code to achieve the intended result:
Code of the Default module:
$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';
Modified Code:
-
$attachment = array(); $attachment['content'] = $pdf->render(false); $attachment['name'] = Configuration::get('PS_
INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('% 06d', $order->invoice_number).'.pdf' ; $attachment['mime'] = 'application/pdf'; //integrate Delivery PDF $extra_pdf = array(); $order_invoice_collection = $order-> getDeliverySlipsCollection(); $delivery_pdf = new PDF($order_invoice_collection, PDF::TEMPLATE_DELIVERY_SLIP, $this->context->smarty); $extra_pdf['content'] = $delivery_pdf->render(false); $extra_pdf['name'] = Configuration::get('PS_ DELIVERY_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('% 06d', $order->delivery_number).'. pdf'; $extra_pdf['mime'] = 'application/pdf'; $file_attachement = array($attachment, $extra_pdf);
Output as displayed

