2012-08-09 91 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

相關問題