0

I need to send order email in this shipping_arrival_time how to send this

observer.php

class Bc_Deliverydate_Model_Observer
    {               

        public function checkout_controller_onepage_save_shipping_method($observer)
        {
            if (Mage::getStoreConfig('deliverydate/deliverydate_general/on_which_page')==1){
                $request = $observer->getEvent()->getRequest();
     //           $quote =  $observer->getEvent()->getQuote();

        $quotes = Mage::getModel('sales/quote')->getCollection();

                $desiredArrivalDate = Mage::helper('deliverydate')->getFormatedDeliveryDateToSave($request->getPost('shipping_arrival_date', ''));
                if (isset($desiredArrivalDate) && !empty($desiredArrivalDate)){
                    $quotes->setShippingArrivalDate($desiredArrivalDate);
                    $quotes->setShippingArrivalComments($request->getPost('shipping_arrival_comments'));
                    $quotes->setShippingArrivalTime($request->getPost('shipping_arrival_time'));
                    $quotes->save();
                }
            }

            return $this;
        }


}

2 Answers 2

1

copy app/code/local/Mage/Sales/Model/Order.php or or rewrite core files. better is to rewrite:

<?php
class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract
{
  public function queueNewOrderEmail($forceMode = false)
  {
    $storeId = $this->getStore()->getId();

    if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
        return $this;
    }

    // Get the destination email addresses to send copies to
    $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
    $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);

    // Start store emulation process
    /** @var $appEmulation Mage_Core_Model_App_Emulation */
    $appEmulation = Mage::getSingleton('core/app_emulation');
    $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

    try {
        // Retrieve specified view block from appropriate design package (depends on emulated store)
        $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
            ->setIsSecureMode(true);
        $paymentBlock->getMethod()->setStore($storeId);
        $paymentBlockHtml = $paymentBlock->toHtml();
    } catch (Exception $exception) {
        // Stop store emulation process
        $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
        throw $exception;
    }

    // Stop store emulation process
    $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

    // Retrieve corresponding email template id and customer name
    if ($this->getCustomerIsGuest()) {
        $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
        $customerName = $this->getBillingAddress()->getName();
    } else {
        $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
        $customerName = $this->getCustomerName();
    }

    /** @var $mailer Mage_Core_Model_Email_Template_Mailer */
    $mailer = Mage::getModel('core/email_template_mailer');
    /** @var $emailInfo Mage_Core_Model_Email_Info */
    $emailInfo = Mage::getModel('core/email_info');
    $emailInfo->addTo($this->getCustomerEmail(), $customerName);
    if ($copyTo && $copyMethod == 'bcc') {
        // Add bcc to customer email
        foreach ($copyTo as $email) {
            $emailInfo->addBcc($email);
        }
    }
    $mailer->addEmailInfo($emailInfo);

    // Email copies are sent as separated emails if their copy method is 'copy'
    if ($copyTo && $copyMethod == 'copy') {
        foreach ($copyTo as $email) {
            $emailInfo = Mage::getModel('core/email_info');
            $emailInfo->addTo($email);
            $mailer->addEmailInfo($emailInfo);
        }
    }

    // Set all required params and send emails
    $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
    $mailer->setStoreId($storeId);
    $mailer->setTemplateId($templateId);
    $mailer->setTemplateParams(array(
        'order'        => $this,
        'billing'      => $this->getBillingAddress(),
        'payment_html' => $paymentBlockHtml,
        'shippingarrivaltime' => $this->getShippingArrivalTime()
    ));

    /** @var $emailQueue Mage_Core_Model_Email_Queue */
    $emailQueue = Mage::getModel('core/email_queue');
    $emailQueue->setEntityId($this->getId())
        ->setEntityType(self::ENTITY)
        ->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
        ->setIsForceCheck(!$forceMode);

    $mailer->setQueue($emailQueue)->send();

    $this->setEmailSent(true);
    $this->_getResource()->saveAttribute($this, 'email_sent');

    return $this;
}
}

After that edit transaction email on below path in admin: System > Transnational Emails > New Order Email

and in template access variable like below

{{ var shippingarrivaltime}}
1
  • @kothari I already update the file that you want please check. If you don;t know that how to use above variable on template then please let me know Commented Jun 16, 2016 at 9:51
1

For adding variable follow below step:

copy app/code/local/Mage/Sales/Model/Order.php or or rewrite core files. better is to rewrite:

in queueNewOrderEmail() function you need set you variable in template params like other parameters you will find below snippet around at line no 1341:

$mailer->setTemplateParams(array(
  'order'        =>  $this,
  'billing'      =>  $this->getBillingAddress(),
  'payment_html' => $paymentBlockHtml,
  'ShippingArrivalTime'  => "YOUR_VALUE FROM QUOTE"
));

After that edit transaction email on below path in admin: System > Transnational Emails > New Order Email

and in template access variable like below

{{ var ShippingArrivalTime}}

I hope it will help you.

For saving it after selecting shipping method it should be like this. And field name should be shipping_arrival_time in sales_flat_quote table.

class Bc_Deliverydate_Model_Observer
{               

    public function checkout_controller_onepage_save_shipping_method($observer)
    {
        if (Mage::getStoreConfig('deliverydate/deliverydate_general/on_which_page')==1){
            $request = $observer->getEvent()->getRequest();
            $quote =  $observer->getEvent()->getQuote();
            $quote->setShippingArrivalTime($request->getPost('shipping_arrival_time'));
            $quote->save();
        }

        return $this;
    }
}
15
  • How to get 'ShippingArrivalTime' => "YOUR_VALUE FROM QUOTE" value here
    – Magento 2
    Commented Jun 15, 2016 at 6:44
  • try this one. $qouteojb = Mage::getSingleton('checkout/session')->getQuote(); 'ShippingArrivalTime' => "$qouteojb->getShippingArrivalTime()" Commented Jun 15, 2016 at 6:55
  • No luck i am not getting
    – Magento 2
    Commented Jun 15, 2016 at 7:01
  • i think you need to store arrival time in quote table and need to fetch it from quote table at the time of sending order email . atwix.com/magento/custom-product-attribute-quote-order-item link help you Commented Jun 15, 2016 at 7:36
  • I already tried no luck
    – Magento 2
    Commented Jun 15, 2016 at 7:57

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.