Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Attach invoice PDF with invoice email in magento

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 3.54k
    Comment on it

    Sometime we need to send a invoice pdf in a invoice mail in magento, so here I am explaining how to add invoice pdf in invoice mail.

    1) Override the app/code/core/Mage/Core/Model/Email/Template/Mailer.php file in your module

    2) Add one protected variable $pdftemplate

    3) Edit the send() function

    4) at line around 70 put the following code

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

    5) At the end of the class put

    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;
    }
    

    6) Override app/code/core/Mage/Sales/Model/Order/Invoice.php

    7) Override the function sendEmail()

    after 
            $mailer = Mage::getModel('core/email_template_mailer');
    

    put

    $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($this));
    $mailer->addAttachment($pdf,'invoice.pdf');
    

    That's all you have to do.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: