2

I can successfully send email with Transaction Email Template but i am not able to convert Transaction Email Template into pdf and send it as attachment in the same email.

Any one can help to convert Transaction Email Template into pdf and send as attachment.

Here is complete code.

<?php require_once('app/Mage.php'); Mage::app();

    $senderName = Mage::getStoreConfig('trans_email/ident_support/name');
    $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
    $mail = Mage::getModel('core/email');
    $emailTemplate = Mage::getModel('core/email_template')->loadByCode('Shipment-Alert');       


                     $orders = Mage::getModel('sales/order')->getCollection()
                    ->addFieldToFilter('status', array('in' => array('pending', 'processing')))
                    ->addAttributeToSelect('*');

                    foreach ($orders as $order) {

                    echo $order->getId();

                    echo $order->getIncrementId();
                    echo $order->getBillingAddress()->getName();
                    echo $order -> getShippingAddress()->getTelephone();
                    echo $order -> getShippingAddress()->getStreetFull();
                    echo $order -> getShippingAddress()->getPostcode();
                    echo $order -> getShippingAddress()->getCity();
                    echo $order -> getCreatedAt();


                    $orderdetails = Mage::getmodel('sales/order_item')->getCollection()
                            ->addFieldToFilter('order_id', array('in' => array($order -> getId())));

                        foreach ($orderdetails as $orderdetail) {

                        echo $orderdetail -> getProductId();
                        echo $orderdetail->getName();
                        echo $orderdetail->getQtyOrdered();

                        $productmodel = Mage::getmodel('catalog/product')
                                                ->load($orderdetail -> getProductId());
                        echo $productmodel -> getData('creator_id');
                        echo "<br>";

                        $customers = Mage::getmodel('customer/customer')->getCollection()
                            ->addFieldToFilter('entity_id', array('in' => array($productmodel -> getData('creator_id'))));


                            foreach ($customers as $customer) {

                            echo $customer -> getData('entity_id');

                            echo $customer -> getEmail();                               
                            echo "<br>";

                            $emailTemplateVariables = array();
                            $emailTemplateVariables['myvar1'] = $order->getIncrementId();
                            $emailTemplateVariables['myvar2'] = $orderdetail->getProductId();
                            $emailTemplateVariables['myvar3'] = $orderdetail->getName();    
                            $emailTemplateVariables['myvar4'] = $orderdetail->getQtyOrdered();  
                            $emailTemplateVariables['myvar5'] = $productmodel->getData('creator_id');   
                            $emailTemplateVariables['myvar6'] = $order->getBillingAddress()->getName(); 
                            $emailTemplateVariables['myvar7'] = $order->getShippingAddress()->getTelephone();   
                            $emailTemplateVariables['myvar8'] = $order->getShippingAddress()->getStreetFull();  
                            $emailTemplateVariables['myvar9'] = $order -> getShippingAddress()->getPostcode();  
                            $emailTemplateVariables['myvar10'] = $order -> getShippingAddress()->getCity(); 
                            $emailTemplateVariables['myvar11'] = $order -> getCreatedAt();

                            $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

                            $emailTemplate->setSenderName('Shipment');
                            $emailTemplate->setSenderEmail($senderEmail);
                            $emailTemplate->setTemplateSubject("Shipment Alert");

            // ---------------This below part is not working ---------------

                        if (!empty($pdf_attachment) && file_exists($pdf_attachment)) {
                                $emailTemplate
                                    ->getMail()
                                    ->createAttachment(
                                        file_get_contents(Mage::getModel('core/email_template')->loadByCode('Shipment-Alert')),
                                        Zend_Mime::TYPE_HTML,
                                        Zend_Mime::DISPOSITION_ATTACHMENT,
                                        Zend_Mime::ENCODING_BASE64,
                                        basename($emailTemplateVariables)
                                    );
                            } 
            //-----------------------------------------------------------------------------
                            $emailTemplate->send('test@test', 'Shipment', $emailTemplateVariables);

                            }   
                    }
                }


    ?>

Your Answer

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

Browse other questions tagged or ask your own question.