2012-08-09 90 views
2

我一直在寻找最后几天的例子,并一直试图自己做,但我坚持以下。Magento:添加pdf发票发票电子邮件

我使用的是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的),但我更喜欢自己更改文件(我想尽可能保持我的安装清理扩展)。

+0

您可以发布您的解决方案? – Guus 2013-02-19 09:59:18

+0

嗨,古斯,最后我没有做到这一点。我转向prestashop,magento对我的目的有点困难。祝你好运! – 2013-02-19 12:51:32

回答

0

你可能想看看

Mage_Adminhtml_Controller_Sales_Invoice 

要查看正在生成销售发票PDF的例子:

$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice)); 
$this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s'). 
    '.pdf', $pdf->render(), 'application/pdf'); 

现在,这实际上是渲染PDF将其包含在HTTP响应,而不是将其作为文件保存出去,但是在发票模型或抽象pdf模型中应该有一个方法来保存pdf。

然后,添加附件,你可能想看看:

Zend_Mail::addAttachment() 

我没有一个例子得心应手,而实际上搜索Magento的1.7凡提述addAttachment()并没有发现任何!有趣。

但希望这给你一点点方向。

+0

感谢您的回复。新的信息可以帮助我。今晚我会再试一次你的信息。如果我成功了,我会在这里发布!再次感谢,如果有人有其他有用的信息,让我知道! – 2012-08-09 22:02:50

1

我在网上搜索了几个小时,但解决方案是针对老版本的Magento,我的版本是1.7.0.2。 Magento处理电子邮件的方式发生了变化。以下是我如何做到这一点的步骤,希望对您有所帮助。

1)改变应用程序/代码/核心/法师/核心/型号/电子邮件/模板/ 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)更新应用程序/代码/核心/法师/销售/型号/订单/ 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- 

个原始URL是在这里: http://www.ericpan.com/2013/02/14/add-pdf-attachment-to-invoice-email/#.USPAKR2t2-0

+1

Thx为解决方案。然而,我会建议扩展核心文件,而不是修改它们。 – 2013-09-16 09:16:48

+0

https://www.atwix.com/magento/pdf-invoice-email/ – 2017-03-02 05:11:33

相关问题