Showing posts with label How to make custom email template in magento. Show all posts
Showing posts with label How to make custom email template in magento. Show all posts

Monday 8 August 2016

How to send cancel order email to customer magento


How to send cancel order email to customer magento

(1) First create template html file order_cancel.html like below and put it at app/locale/en_US/template/email/sales/


    <!--@subject {{var store.getFrontendName()}}: Your Order # {{var order.increment_id}} was received, but failed @-->
    <!--@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>Dear {{var customer_name}}, Thank you for choosing {{var store.getFrontendName()}}.</h1>
                            <p class="new-order-tag">Greetings from {{var store.getFrontendName()}},
    We saw that you were about to shop for some products from our store and you didn't get a chance to finish your order (Order ID : # {{var order.increment_id}}) for some reason. </p>
                        </td>
                        <td class="store-info">
                            <h4>Order Questions?</h4>
                            <p>
                                {{depend store_phone}}
                                <b>Call Us:</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>Your order <span class="no-link">#{{var order.increment_id}}</span></h3>
                <p>Placed on {{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>Bill to:</h6>
                            <p><span class="no-link">{{var order.getBillingAddress().format('html')}}</span></p>
                        </td>
                        {{depend order.getIsNotVirtual()}}
                        <td class="address-details">
                            <h6>Ship to:</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>Shipping method:</h6>
                            <p>{{var order.shipping_description}}</p>
                        </td>
                        {{/depend}}
                        <td class="method-info">
                            <h6>Payment method:</h6>
                            {{var payment_html}}
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td class="order-details">
                If you have any question or require assistance with this order, do not hesitate to contact us and you can enjoy your shopping with us in the near future as well.
            </td>
        </tr>
    </table>
 
    {{template config_path="design/email/footer"}}

(2) Now open your custom module config.xml. if you have not any custom module then create it. Paste below code.

    <template>
        <email>
            <cancel_order_template translate="label">
                <label>Cancel Order</label>
                <file>sales/order_cancel.html</file>
                <type>html</type>
            </cancel_order_template>
        </email>
    </template>

   After this you can see your template in transaction email menu in magento admin panel.
 
(3) Now paste below code where you want to send the mail to customer. For example if you want mail after order cancel, then make observer for that and call below code in it.

    <?php
    /* Cancel order email to customer */
    $template = 'cancel_order_template';
    $sender = array('name' => Mage::getStoreConfig('trans_email/ident_sales/name'),
        'email' => Mage::getStoreConfig('trans_email/ident_sales/email'));
     
    //recepient
    $email = $order->getCustomerEmail();  // Customer Email
    $emaiName = $order->getCustomerName(); // Customer Name
    $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
    $paymentBlock->getMethod()->setStore($order->getStore()->getId());

    // Your dynamic variable
    $vars = array(
        'customer_name' => $order->getCustomerName(),
        'order_id' => $orderId,
        'order' => $order,
        'payment_html' => $paymentBlock->toHtml()
     );
 
    $order = Mage::app()->getLayout()->createBlock('sales/email_order_items');
    $storeId = Mage::app()->getStore()->getId();
    $translate = Mage::getSingleton('core/translate');
    Mage::getModel('core/email_template')->sendTransactional($template, $sender, $email, $emailName, $vars, $storeId);
    $translate->setTranslateInline(true);
    /* Cancel order email to customer */
   ?>

That's it... Enjoy Chandresh Rana Coding..