我在网上搜索了几个小时,但解决方案是针对旧版本的 Magento,我的版本是 1.7.0.2。 Magento 处理电子邮件的方式也发生了变化。以下是我的操作步骤,希望对你有所帮助。
1) 更改 app/code/core/Mage/Core/Model/Email/Template/Mailer.php
Part 1, add protected $emailTemplate; to the top of the class:
class Mage_Core_Model_Email_Template_Mailer extends Varien_Object
{
/**
* List of email infos
* @see Mage_Core_Model_Email_Info
*
* @var array
*/
protected $_emailInfos = array();
// Add the following one line
protected $emailTemplate;
第 2 部分更新函数 send()
public function send()
{
// the original was $emailTemplate = Mage::getModel('core/email_template');
// Change it to the following four lines:
if ($this->emailTemplate)
$emailTemplate = $this->emailTemplate;
else
$emailTemplate = Mage::getModel('core/email_template');
第 3 部分将函数添加到类的末尾:
public function addAttachment(Zend_Pdf $pdf, $filename){
$file = $pdf->render();
$this->emailTemplate = Mage::getModel('core/email_template');
$attachment = $this->emailTemplate->getMail()->createAttachment($file);
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
}
2) 更新 app/code/core/Mage/Sales/Model/Order/Invoice.php
Update sendEmail function
$mailer = Mage::getModel('core/email_template_mailer');
// the next two lines were added
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($this));
$mailer->addAttachment($pdf,'invoice.pdf');
if ($notifyCustomer) {
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($order-
原始网址在这里:
http://www.ericpan.com/2013/02/14/add-pdf-attachment-to-invoice-email/#.USPAKR2t2-0