I’ve been at this for 5 days and thirty thousand and two different ways and nothing seems to work. I’m trying to attach a packing slip PDF to a packing slip email that is send to the store admin when a new order is placed. I don’t know if the problem is with me (probably) or with Zend_Pdf or with Zend_Mail or with Magento.
I have customized a couple of methods and saved them in my code/local directory…
Mage/Sales/Model/Order.php
I tweaked the method to add the packing slip template, guest packing slip template and admin email. I also added a couple of parameters to the Template->sendTransactional method, which I’ve shown below. This is just background in case you were wondering where the next method gets its values. This all seems to work fine. I can send the packing slip email to the store admin. I just can’t attach anything to it.
Mage/Core/Model/Email/Template.php
It’s the last method that does the heavy lifting, specifically between the /*** ATTACH PDF ***/ tags. There are a couple of things happening (or not) here.
1. I’ve tried to create a Zend_Pdf document based on the text of the packing slip email (which I am able to generate if I don’t attempt the attachment)
2. I’ve tried to attach it to the Zend_Mail message.
What happens is that when I attempt an order without the attachment code, I get the order confirmation email and packing slip email with no problems, and the onepage checkout goes on to the success page. All good.
However, if I attempt to do anything else to this method, my checkout attempt returns an alert dialog that either says ‘undefined’ or ‘There was a problem with your order...try again (or words to that effect),’ and only the order confirmation email comes through BUT the checkout page remains. The order IS processed by both Magento and Authorize.net, but the success page isn’t displayed. It’s as if either the PDF or attachment called a die() but there are no error messages so I can’t tell what’s happening.
My functions are below. The third post by me in this thread has the relevant code I’m having problems with. The other two are so you can follow along at home. They seem to work fine.
My questions are:
1. What is the relationship between the order confirmation email and the success page? If the order is successfully processed why wouldn’t the success page be displayed? I think this might be a bug, or at least bad logic.
2. Am I doing something wrong in my usage of the PDF or Mail classes?
/** * Sending email with order data * * @return Mage_Sales_Model_Order */ public function sendNewOrderEmail() { $itemsBlock = Mage::getBlockSingleton('sales/order_email_items')->setOrder($this); $shipItemsBlock = Mage::getBlockSingleton('sales/order_email_shipitems')->setOrder($this);
Not directly releated, but I stumbled on this post and wondered if this could help me with an issue I have. I would like to add a line of text to the email invoice sent to the customer after checkout that would include a discount link/coupon for a free PDF version of the book they bought. So I’d like to know how to tell when a specific product is sold and how to add to that invoice template.
After days of working on this, I’ve discovered that Zend_Pdf doesn’t work with HTML. You have to build the PDF from scratch, which is more work than it’s worth and not easy to edit if you want to change the design.
I’ve had a tease from one of the forum people who said they’ve been able to create a PDF using the third-party DOMPDF library with Magento, which I’ve used before, and which is really easy to use. I tried calling it directly from the /lib directory but I couldn’t load the class, and unfortunately I think the person is full of it because they haven’t posted any code to back up their claim.
I’ve not found a solution to this yet but if you do, please post it here so we can benefit. I’ll help out where I can, as I do have some experience with DOMPDF itself (not that it’s very hard to figure out).
I am trying to add a custom pdf to the email classes
in the latest version today did u ever get this all working or did you stoped trying
i am hoping to use your code examples for creating the custom pdf
I managed to attach invoice, creditmemo and shipments to outgoing mail using the pdf models in the Sales module
For order attachment I created a custom model for pdf (not present in magento)
If someone is still interested in this please reply and I’ll post my work here.
PS: I couldn’t test yet for checkout because of a problem with my magento installation(checkout didn’t work from the beginning) but it works well for notifications from the back office
I created a new module for this but you can overwrite directly in the magento files just to test if it works
1. In mage/core/model/email/template.php add this method at the end of the file:
public function addAttachment(Zend_Pdf $pdf){ $file = $pdf->render(); $attachment = $this->getMail()->createAttachment($file); $attachment->type = 'application/pdf'; $attachment->filename = 'test.pdf'; }
2 In sales/model/order/Invoice.php add the code between comments(2 lines of code) to the function sendEmail like this:
public function sendEmail($notifyCustomer=true, $comment='') { if (!Mage::helper('sales')->canSendNewInvoiceEmail($this->getOrder()->getStore()->getId())) { return $this; }