I had the same request asked a while back. I used you question and your findings to solve our problem. I am posting in case someone else is in need of a solution.
I am using magento CE 1.9.1
The leg work:
"You never want to edit the core files always create an overwrite" and if you are really good create modules.
move "app/code/core/Mage/Core/Model/Email/Template/Mailer.php"
to "app/code/**local**/Mage/Core/Model/Email/Template/Mailer.php"
move "/app/code/core/Mage/Sales/Model/Order/Shipment.php"
to
"/app/code/**local**/Mage/Sales/Model/Order/Shipment.php"
Coding:
Mailer.php
add a protected variable before the first function declaration
protected $emailTemplate;
Modify the Send function
.
*// comment out this line:*
// $emailTemplate = Mage::getModel('core/email_template');
*// add these lines:*
if ($this->emailTemplate)
$emailTemplate = $this->emailTemplate;
else
$emailTemplate = Mage::getModel('core/email_template');
- Add a function at the bottom of the file before closing the class
.
public function addAttachment($template, Zend_Pdf $pdf, $filename){
$file = $pdf->render();
$attachment = $template->getMail()->createAttachment($file);
if(!is_object($attachment)) return $this;
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
return $this;
}
Shipment.php
- below
$storeId = $order->getStore()->getId();
add:
.
/* get invoice PDF */
$invoices = $order->getInvoiceCollection();
$pdfInvoice = Mage::getModel('sales/order_pdf_invoice');
$pdf = $pdfInvoice->getPdf($invoices);
- below
$mailer = Mage::getModel('core/email_template_mailer')
;
add:
.
$mailer->addAttachment($pdf,'invoice.pdf');
I found my answer in Add PDF attachment to invoice email