2

I've created a notification email for new order to my supplier directly after the invoice is created. I receive the email but it is empty for information to grab from magento like order id and other. Can you help me pls to understand why. This Are my 2 file, the observer:

<?php
class Electricjesus_Notifyowner_Model_Observer
{
    public function notifyOwnerEvent($observer)
    {

        // parameters you can get from the $observer parameter:
        // array(’payment’ ? $this, ‘invoice’ ? $invoice)

        $payment = $observer->getPayment();
        $invoice = $observer->getInvoice();


        // derivative data
        $order = $invoice->getOrder(); // Mage_Sales_Model_Order



        $ownerEmail = 'test@gmail.com';
        $Subject = 'Oggetto :';
        $emailTemplate  = Mage::getModel('core/email_template')
            ->loadDefault('order_copy_for_supplier');
        $emailTemplate->setTemplateSubject('Prova di Ordine Confermato dopo pagamento');
        $emailTemplate->setToName($senderName);
        $emailTemplate->setToEmail($ownerEmail);
        $emailTemplate->setBody($processedTemplate);
        $emailTemplate->setSubject($Subject);
        $emailTemplate->setFromEmail($senderEmail);
        $emailTemplate->setFromName($senderName);
         $emailTemplate->setType('html');

        // Get General email address (Admin->Configuration->General->Store Email Addresses)
        $salesData['email'] = Mage::getStoreConfig('trans_email/ident_general/email');
        $salesData['name'] = Mage::getStoreConfig('trans_email/ident_general/name');

        $emailTemplate->setSenderName($salesData['name']);
        $emailTemplate->setSenderEmail($salesData['email']);

       //Getting the Store E-Mail Sender Name.
        $senderName = Mage::getStoreConfig('trans_email/ident_general/name');



        //Getting the Store General E-Mail.
        $senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
        $emailTemplateVariables['username']  = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname();
        $emailTemplateVariables['order_id'] = $order->getIncrementId();
        $emailTemplateVariables['store_name'] = $order->getStoreName();
        $emailTemplateVariables['order_data'] = $order->getCreatedAtFormated();
        $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);   
        $emailTemplate->send($ownerEmail, $order->getStoreName(), $emailTemplateVariables);

        //$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
        //$mailTemplate = Mage::getModel('core/email')
        //->setToName($senderName)
        //->setToEmail($ownerEmail)
        //->setBody($processedTemplate)
        //->setSubject($Subject)
         //->setFromEmail($senderEmail)
         //->setFromName($senderName)
         //->setType('html');
         //try{
         //Confimation E-Mail Send
         //$mail->send();
         //}
         //catch(Exception $error)
         //{
         //Mage::getSingleton('core/session')->addError($error->getMessage());
         //return false;
         //}


        return $this;  // always return $this.
    }

and the html file:

<!--@subject {{var store.getFrontendName()}}: Nuovo Ordine Per Fornitore # {{var order.increment_id}} @--><!--@vars
    {"store url=\"\"":"Store Url",
    "var logo_url":"Email Logo Image Url",
    "var logo_alt":"Email Logo Image Alt",
    "htmlescape var=$order.getCustomerName()":"Customer Name",
    "var store.getFrontendName()":"Store Name",
    "store url=\"customer/account/\"":"Customer Account Url",
    "var order.increment_id":"Order Id",
    "var order.getCreatedAtFormated('long')":"Order Created At (datetime)",
    "var order.getBillingAddress().format('html')":"Billing Address",
    "var payment_html":"Payment Details",
    "var order.getShippingAddress().format('html')":"Shipping Address",
    "var order.getShippingDescription()":"Shipping Description",
    "layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid",
    "var order.getEmailCustomerNote()":"Email Order Note"}
    @--><!--@styles@-->{{template config_path="design/email/header"}}
    {{inlinecss file="email-inline.css"}}

    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td>
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td class="email-heading">
                        <h1>Nuovo ordine da produrre {{var store.getFrontendName()}}.</h1>
                        <p>Gentile Fornitore, vi preghiamo di mettere in produzione il seguente ordine. Abbiamo già effettuato bonifico per la corrispondente somma a voi dovuta secondo la scontistica del 60+10 sul vostro listino. Vi preghiamo, effettuata la spedizione di inviarci il codice di tracking. Grazie.</p>
                    </td>
                    <td class="store-info">
                        <h4>Info da inviare a </h4>
                        <p>
                            {{depend store_phone}}
                            <b>Chiamaci:</b>
                            <a href="tel:{{var phone}}">{{var store_phone}}</a><br>
                            {{/depend}}
                            {{depend store_hours}}
                            <span class="no-link">{{var store_hours}}</span><br>
                            {{/depend}}
                            {{depend store_email}}
                            <b>Email:</b> <a href="mailto:{{var store_email}}">{{var store_email}}</a>
                            {{/depend}}
                        </p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="order-details">
            <h3>Ns. Ordine N. <span class="no-link">#{{var order.increment_id}}</span></h3>
            <p>Effettuato il {{var order.getCreatedAtFormated('long')}}</p>
        </td>
    </tr>
    <tr class="order-information">
        <td>
            {{if order.getEmailCustomerNote()}}
            <table cellspacing="0" cellpadding="0" class="message-container">
                <tr>
                    <td>{{var order.getEmailCustomerNote()}}</td>
                </tr>
            </table>
            {{/if}}
            {{layout handle="sales_email_order_items" order=$order}}
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td class="address-details">
                        <h6>Fattura a:</h6>
                        <p><span class="no-link">{{var order.getBillingAddress().format('html')}}</span></p>
                    </td>
                    {{depend order.getIsNotVirtual()}}
                    <td class="address-details">
                        <h6>Spedizione a:</h6>
                        <p><span class="no-link">{{var order.getShippingAddress().format('html')}}</span></p>
                    </td>
                    {{/depend}}
                </tr>
                <tr>
                    {{depend order.getIsNotVirtual()}}
                    <td class="method-info">
                        <h6>Metodo di spedizione:</h6>
                        <p>{{var order.shipping_description}}</p>
                    </td>
                    {{/depend}}
                    <td class="method-info">
                        <h6>Metodo di pagamento:</h6>
                        {{var payment_html}}
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>{{template config_path="design/email/footer"}}
}
2

you need to pass the order array so he can get the values. so in TemplateVariables add $emailTemplateVariables['order'] = $order;

        $emailTemplateVariables['order'] = $order;
        $emailTemplateVariables['username']  = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname();
        $emailTemplateVariables['order_id'] = $order->getIncrementId();
        $emailTemplateVariables['store_name'] = $order->getStoreName();
        $emailTemplateVariables['order_data'] = $order->getCreatedAtFormated();
        $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);   
        $emailTemplate->send($ownerEmail, $order->getStoreName(), $emailTemplateVariables);
  • OK now I've information, but I Need to understand how to insert also Items. I need some other variables? Where can i see a list of all possible variables? – BigBlack Feb 4 '17 at 21:20
  • If you want to add order item copy code sale order new email template copy that code in your template it will work – Qaisar Satti Feb 4 '17 at 22:12
  • I've yet copied the template from new order template. – BigBlack Feb 4 '17 at 23:18
  • @BigBlack go to Mage/Sales/Model/Order.php and check method queueNewOrderEmail – Qaisar Satti Feb 6 '17 at 5:13
  • I'm sorry man but I don't understand. I have searched the method you say, but it seems not to have an item call inside.. If I try to set the template standard, the new order one, instead of a new one html, I've a blank email result. – BigBlack Feb 7 '17 at 22:18

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.