php - Magento:将 pdf 发票添加到发票电子邮件中

标签 php email magento invoice magento-1.7

过去几天我一直在寻找示例,并尝试自己做,但我陷入了以下困境。

我正在使用 Magento 1.7.0.2。 我想在生成发票时将发票 PDF 作为附件添加到交易电子邮件中。

我尝试了几件事,包括更改/Mage/Sales/Model/Order/Invoice.php、/Mage/Core/Model/Email/Template.php 和/Mage/Core/Model/Email/Template/Mailer.php .

我知道该过程涉及哪些文件,我知道在哪里添加附件,我只是不知道如何实际生成 PDF 并将其附加到电子邮件中。

magento 1.7.0.0 似乎还改变了生成电子邮件的方式,所有解释均针对 1.6.x

我还知道有多个扩展(即 FOOMAN 的),但我更喜欢自己更改文件(我希望尽可能保持安装中没有扩展)。

最佳答案

我在网上搜索了几个小时,但解决方案是针对旧版本的 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

关于php - Magento:将 pdf 发票添加到发票电子邮件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11888153/

相关文章:

php - ZipArchive 文件无效

php - 计算父子查询中的 sibling 数量

php - 通过 php 邮件发送电子邮件时,内联 css 不在电子邮件中打印

php - 如何使用邮件功能使用 php 表单脚本将邮件从我的网站电子邮件发送到 gmail?

php mysql 检查连接是否已经建立

php - 随机字符串是不是很好的验证码

java - 压缩多个 jasper 报告并通过电子邮件发送此 zip

php - magento中有没有办法检测地址是否已经存在

mysql - magento 无法重新索引产品属性

magento - 我无法在 Magento 产品页面上找到可配置选项?