添加附件以订购电子邮件+ Magento

ped*_*oto 4 email attachment magento

我需要在客户下订单时将文件附加到Magento发送的电子邮件中.

此附件可以是PDF,HTML或简单的TXT,并且必须包含订单摘要(SKU,数量,单价,总价).

我怎样才能实现这一目标?

提前致谢!

And*_*kus 12

解决方案并不复杂,尽管您需要一些时间来实现它.我将简要解释所需的所有步骤.

主要步骤是:

  1. 在订单邮件中撰写附件并将其传递给邮件程序
  2. 将其转换为电子邮件模板
  3. 将其添加到作为附件发送的实际信件中

1)你需要重写Mage_Sales_Model_Order课程.覆盖该类中的`sendNewOrderEmail()'方法.

在那里,您需要撰写要发送给客户的附件.将原始sendNewOrderEmail()方法源代码复制到您的覆盖方法并在之前添加以下行$mailer->send()(对于我们的示例,我们将采用简单的情况 - 我们将发送一个文本文件,其中仅包含订单的总计,附件将被命名为'的summary.txt")

$fileContents = "Hello, here is the copy of your invoice:\n";
$fileContents .= sprintf("Grand total: %.2f", $this->getGrandTotal()) . "\n";
$fileContents .= "Thank you for your visit!";
$fileName = 'summary.txt';
$mailer->addAttachment($fileContents, $fileName);
Run Code Online (Sandbox Code Playgroud)

2)重写Mage_Core_Model_Email_Template_Mailer- 添加方法addAttachment($fileContents, $fileName),将传递的附件添加到受保护变量,存储附件数组.

send()在这个类中覆盖方法.在该方法中,您需要将附件数组传递给发送的每个电子邮件模板.例如,添加像

$emailTemplate->setAttachments($this->getAttachments());
Run Code Online (Sandbox Code Playgroud)

就行前 $emailTemplate->setDesignConfig...

3)重写Mage_Core_Model_Email_Template.

添加那里setAttachments($attachments)必须将传入附件设置为某个受保护变量的方法.

send()在这个类中覆盖方法.在该方法中,您需要向已发送的信件添加附件.把线条像

foreach ($this->getAttachments() as $atInfo) {
    $attachment = $mail->createAttachment($atInfo['fileContents']);
    $attachment->filename = $atInfo['fileName'];
}
Run Code Online (Sandbox Code Playgroud)

就在那之前$mail->send().

就这样.对于Magento开发人员来说,完成这项任务真的不是很难.它只需要一些时间来编写内容,重写类和完成接口.