Question

Looking to change the 1.9.3.4 email system to allow for adding attachments.

Due to the nature of the attachment (dynamically generated PDF based on a variety of things, from customers/orders/3rd party) I would like to attach the PDF in this function:

queueNewOrderEmail

in this file:

/app/code/local/Mage/Sales/Model/Order.php

The changes to the email system in recent versions make finding info online extremely difficult.

It looks as though I should be creating the Zend attachment function in here:

/app/code/local/Mage/Core/Model/Email/Template.php

However, it looks as though the email queue system will ignore that.

This seems like it should be a quick and easy task, but I'm absolutely stumped at this point.

Was it helpful?

Solution

Not great, but I've got a workaround for now.

I've added the Zend file attachment stuff in this file,

/app/code/local/Mage/Core/Model/Email/Template.php

inside the send($email, $name = null, array $variables = array()) function.

$filename = $variables['filename']; 
$content = file_get_contents("/var/www/webroot/".$filename); 
//some additional work is done here to verify the file is legitimate/safe/etc.
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = $filename;

This allows me to pass the file name from this file: /app/code/local/Mage/Sales/Model/Order.php

Inside queueNewOrderEmail($forceMode = false)

$mailer->setTemplateParams(array(
                  'order'        => $this,
                  'billing'      => $this->getBillingAddress(),
                  'payment_html' => $paymentBlockHtml,
                  'customMessage' => $message,
                  'filename' => $filename
              )
          );
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top