I need to attach a file to the email Magento sends when a client places an order.
This attachment can be either a PDF, a HTML or a simple TXT, and it must have the summary of the order (SKU, Quantity, Unit Price, Total Price).
How can I go about making this happen?
Thanks in advance!
Solution is not very complex, although you’ll need some time to implement it. I’ll give there brief explanation of all the steps required.
The main steps are:
1) You need to rewrite the
Mage_Sales_Model_Orderclass. Overwrite the `sendNewOrderEmail()’ method in that class.There you need to compose the attachment, that you want to send to the customer. Copy the original
sendNewOrderEmail()method source code to your overwriting method and put the following lines just before$mailer->send()(for our example we will take the easy case – we will send a text file, that will contain only Grand Total of an order, attachment will be named ‘summary.txt’)2) Rewrite
Mage_Core_Model_Email_Template_Mailer– add there methodaddAttachment($fileContents, $fileName), that will add passed attachments to protected variable, that stores array of attachments.Overwrite
send()method in this class. In that method you will need to pass array of attachments to every email template sent. E.g. add lines likeright before line
$emailTemplate->setDesignConfig...3) Rewrite
Mage_Core_Model_Email_Template.Add there method
setAttachments($attachments), that must set incoming attachments to some protected variable.Overwrite
send()method in this class. In that method you will need to add attachments to the sent letter. Put the lines likeright before
$mail->send()line there.That’s all. It is really not very hard to do this task for a Magento developer. It just requires some time to compose contents, rewrite classes and complete interfaces.