0

I am using Custom order status While changing it send a mail. It's working fine

public function shipementorderAction(){
                $id = $this->getRequest()->getParam('id');

                $order = Mage::getModel('sales/order')->load($id);
                $order->setData('state', 'shipement');
                $order->setStatus('shipement');
                $history = $order->addStatusHistoryComment('', false);
                $history->setIsCustomerNotified(false);
                $order->save(); 

                $order->sendOrderUpdateEmail(true, null);

                $this->_getSession()->addSuccess(
                    $this->__('The order state has been changed.')
                );
                //$this->_redirect('mpshippingmanager/shipping/index');
                Mage::getSingleton('core/session') ->addSuccess('Order Updated Successfully'); $this->_redirectReferer();


                }

I used this to send a mail

**$order->sendOrderUpdateEmail(true, null);**

How to send custom email template(New Template) per status

0

You can use this method as starting point:

app/code/core/Mage/Sales/Model/Order.php::queueNewOrderEmail()

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
    ));

    /** @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;
}

Obviously you have to implement some methods to retrieve configuration like $storeId and $templateId that in the example are already there (since is declared inside the order model).

I think that the best approach could be hook the order status change and implement all the email send logic in a helper in order be reused in the future and even better split that method and abstract all the order logic, so you will have a good base to send any kind of emails.

I assume that you already know how to save and load configuration but i recommend you to use some method (like getEmailTemplateByStatus($status)) with a default return value to avoid errors just if someone add a custom status and it hasn't any template mapped.

Hope it help

  • @ MauroNigrele Hi, Do you know about html to magento conversion? – Teja Bhagavan Kollepara Dec 26 '15 at 11:57
  • @TejabhagavanKollepara sorry i don't catch your point – MauroNigrele Dec 26 '15 at 11:59
  • Okay i'll tell you. – Teja Bhagavan Kollepara Dec 26 '15 at 12:00
  • i want to convert html to magento . I have html pages, from that i want to make magento website. I think you got .Please tell me – Teja Bhagavan Kollepara Dec 26 '15 at 12:00
  • 1
    The question you linked it's closed, anyway it's an biz question you can't just translform html files into magento you must create a theme declare layouts and edit templates to achieve it. sorry – MauroNigrele Dec 26 '15 at 13:09
0

You have to use custom email send, see answer of this question

http://magento.stackexchange.com/questions/122837/custom-email-template-not-working

instead of

**$order->sendOrderUpdateEmail(true, null);**

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.