0

I am adding a PDF to all my sales emails at the moment, but I only want these PDFs to be added if the order contains at least one virtual product. How can I implent this in the following if statement?

    if (Mage::getStoreConfig('sales_email/' . $configPath . '/attachpdf', $storeId)) {

        //Create Pdf and attach to email - play nicely with PdfCustomiser

        $pdf = Mage::getModel('emailattachments/order_pdf_order')->getPdf(array($order));
        Mage::helper('emailattachments')->addAttachment(
            $pdf, $mailTemplate, $this->getOrderAttachmentName($order)
        );
    }
1
    $isVirtual = false;
    foreach ($order->getAllItems() as $items) {            
        if ($items->getProductType() == 'virtual') {
            $isVirtual = true; 
            break;
        }
    }

    if (Mage::getStoreConfig('sales_email/' . $configPath . '/attachpdf', $storeId) && $isVirtual) {

        //Create Pdf and attach to email - play nicely with PdfCustomiser

        $pdf = Mage::getModel('emailattachments/order_pdf_order')->getPdf(array($order));
        Mage::helper('emailattachments')->addAttachment(
            $pdf, $mailTemplate, $this->getOrderAttachmentName($order)
        );
    }
|improve this answer|||||
  • Thank you very much @eetzen. It is now adding a PDF if the order only contains virtual products, however I would like to add the PDF also if it contains both virtual and another type of products. Normal products = false, virtual + normal products = true, virtual products = true. Is this possible to add? – McKeene Apr 4 '15 at 13:37
  • I only use configurable, virtual and simple products if that makes a difference :) – McKeene Apr 4 '15 at 13:52
  • the code should work as long as there's a virtual product in the order. – eetzen Apr 4 '15 at 14:36
  • Sadly the PDF is not being added if I purchase both a simple and a virtual product. – McKeene Apr 4 '15 at 17:50
  • I found out that I simply had to remove the break; and then it works. Thank you very much for your help :) – McKeene Apr 4 '15 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.