2

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,

  1. Adding protected $pdftemplate;
  2. Overriding the send() function,

    if($this->pdftemplate){ $pdftemplate = $this->variable; }else{ $pdftemplate = Mage::getModel('core/email_template'); }

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

1 Answer 1

2

you have to try extension first, then if you like you can customize it: https://marketplace.magento.com/fooman-fooman-emailattachments.html

Feature List

  • Automatically attach a copy of Order/Invoice/Shipment/Credit Memo pdf documents (with or without comments) to Order/Invoice/Shipment/Credit Memo emails
  • Automatically attach your Terms and Conditions (as html/text file) to Order/Invoice/Shipment/Credit Memo emails
  • Automatically attach any pdf document to Order/Invoice/Shipment/Credit Memo emails (for example, your return policy, a coupon or voucher, or your latest newsletter)
  • Create an Order Confirmation pdf document from the Order Overview screen or individual Order View page
  • Print Order Confirmation pdf documents for multiple orders in bulk from the the Order Overview screen
  • Developer bonus - if you write your own extensions, you can hook into the email sending process into the events added by this extension

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.