I want to attach invoice pdf to the invoice mail, I followed the link and override the email functions.
First Override the app/code/Mage/core/Model/Email/Template/Mailer.php like,
- Adding
protected $pdftemplate;
Overriding the
send()
function,if($this->pdftemplate){ $pdftemplate = $this->variable; }else{ $pdftemplate = Mage::getModel('core/email_template'); }
Adding attachment function at the end of the class,
/** Add Attachment**/
public function addAttachment(Zend_Pdf $pdf, $filename){ $file = $pdf->render(); $this->pdftemplate = Mage::getModel('core/email_template'); $attachment = $this->pdftemplate->getMail()->createAttachment($file); $attachment->type = 'application/pdf'; $attachment->filename = $filename; }
Second I override the app/code/Mage/Sales/Order/Invoice.php, sendEmail()
function,
$mailer = Mage::getModel('core/email_template_mailer');
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($this));
$mailer->addAttachment($pdf,'invoice.pdf');
But the pdf is not attached. I don't know what to do next. I hope someone will point me the issue.
Thanks!..