1

How to get Checkout Information in custom mail

   /* Get Information For Un support Email to Admin */
        $customer = Mage::getSingleton('customer/session')->getCustomer();        
        //$name = $customer->getName();
        $email = $customer->getEmail();

        $cart = Mage::getSingleton('checkout/cart')->getQuote();
        $productName = array();
        /*$skus = array();*/
            foreach ($cart->getAllItems() as $item) {
                $productName[] = $item->getProduct()->getName();
                /*$skus[] = $item->getProduct()->getSku();*/
            }       
        $productNames = implode(', ', $productName);
        /*$productSkus = implode(', ', $skus);*/
        $quote = Mage::getModel('checkout/session')->getQuote();
        $grandTotal = 0;
        foreach ($quote->getAllItems() as $item) {
            $total += $item->getPriceInclTax() * $item->getQty();
        }

        $checkout = Mage::getSingleton('checkout/session')->getQuote();
         $billAddress = $checkout->getBillingAddress();

         Mage::log($billAddress->getData());
          //you can get contact number in that
         $tele = $billAddress->getTelephone();
         $add = $billAddress->getCity();
         $street = $billAddress->getStreet1();
         $state = $billAddress->getRegion();
        $name = $billAddress->getName();

 $template_id = 'my_custom_email';
    // Who were sending to...
       $email_to = '[email protected]';
    //$email_to = Mage::getStoreConfig('trans_email/ident_general/email');
    //$email_to = Mage::getStoreConfig('trans_email/ident_support/email');
    $customer_name   = $name;
    // Load our template by template_id
    $email_template  = Mage::getModel('core/email_template')->loadDefault($template_id);

    $custom_variable = $name;
    $custom_variable1 = $email;
    $custom_variable2 = $postCode;
    $custom_variable3 = $productNames;
    $custom_variable4 = $tele;
    $custom_variable5 = $total;
    $custom_variable6 = $add;
    $custom_variable7 = $street;
    $custom_variable8 = $state;



    $email_template_variables = array(
        'custom_variable' => $custom_variable,
        'custom_variable1' => $custom_variable1,
        'custom_variable2' => $custom_variable2,
        'custom_variable3' => $custom_variable3,
        'custom_variable4' => $custom_variable4,
        'custom_variable5' => $custom_variable5,
        'custom_variable6' => $custom_variable6,
        'custom_variable7' => $custom_variable7,
        'custom_variable8' => $custom_variable8,


    );
    $sender_name = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
    $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
    $email_template->setSenderName($sender_name);
    $email_template->setSenderEmail($sender_email);    
    $email_template->send($email_to, $customer_name, $email_template_variables);
2
  • Can you please tel l me when you want to fire this email?
    – Amit Bera
    Jun 26, 2016 at 15:43
  • After Place order
    – Magento 2
    Jun 27, 2016 at 4:06

1 Answer 1

0

Kothari,for your can use Magento Event/observer.

Call observer at event checkout_submit_all_after

At this observer ,you can get Order Object from $observer->getEvent()->getOrder().

config.xml code:

<global>
<events>
        <checkout_submit_all_after>
            <observers>
                <myaction_save_order>
                    <class>[ModuleNameSpace]_[ModuleName]_Model_Observer</class>
                    <method>SendCustomOrderEmail</method>
                </myaction_save_order>
            </observers>
        </checkout_submit_all_after>
    </events>
</global>

Observer code:

<?php 

class [ModuleNameSpace]_[ModuleName]_Model_Observer{
    public function SendCustomOrderEmail($observer){

        $order=$observer->getEvent()->getOrder();

        $name = $order->getCustomerFirstname();
        $email = $order->getCustomerEmail();


        $productName = array();
        /*$skus = array();*/
            foreach ($order->getAllVisibleItems() as $item) {
                $productName[] = $item->getName();
                /*$skus[] = $item->getProduct()->getSku();*/
            }       
        $productNames = implode(', ', $productName);
        /*$productSkus = implode(', ', $skus);*/

        $total = 0;
        foreach ($quote->getAllItems() as $item) {
            $total += $item->getPriceInclTax() * $item->getQty();
        }


         $billAddress = $order->getBillingAddress();

         //Mage::log($billAddress->getData());
          //you can get contact number in that
         $tele = $billAddress->getTelephone();
         $add = $billAddress->getCity();
         $street = $billAddress->getStreet1();
         $state = $billAddress->getRegion();
        $name = $billAddress->getName();

        $template_id = 'my_custom_email';
        // Who were sending to...
           $email_to = '[email protected]';
        //$email_to = Mage::getStoreConfig('trans_email/ident_general/email');
        //$email_to = Mage::getStoreConfig('trans_email/ident_support/email');
        $customer_name   = $name;
        // Load our template by template_id
        $email_template  = Mage::getModel('core/email_template')->loadDefault($template_id);

        $custom_variable = $name;
        $custom_variable1 = $email;
        $custom_variable2 = $postCode;
        $custom_variable3 = $productNames;
        $custom_variable4 = $tele;
        $custom_variable5 = $total;
        $custom_variable6 = $add;
        $custom_variable7 = $street;
        $custom_variable8 = $state;



        $email_template_variables = array(
            'custom_variable' => $custom_variable,
            'custom_variable1' => $custom_variable1,
            'custom_variable2' => $custom_variable2,
            'custom_variable3' => $custom_variable3,
            'custom_variable4' => $custom_variable4,
            'custom_variable5' => $custom_variable5,
            'custom_variable6' => $custom_variable6,
            'custom_variable7' => $custom_variable7,
            'custom_variable8' => $custom_variable8,


        );
        $sender_name = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
        $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
        /* add by AB */
        $email_template->getProcessedTemplate($emailTempVariables);
        $email_template->setSenderName($adminUsername);
        $email_template->setSenderEmail($adminEmail);
        $email_template->send($customer->getEmail(),$Username,$emailTempVariables);    
        /* add by AB */


    }

}

NOte that code is not test.I have put this code basic of idea

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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