Magento Observer for Multi Shipping电子邮件

时间:2014-05-22 14:37:16

标签: magento events checkout observers

我在Magento下订单后发送电子邮件有些困难。我需要将自定义电子邮件发送到自定义地址。我为sales_order_place_after创建了Observer,它运行得很完美,但是当我使用checkout进行多个地址时,我有错误。 这是我的观察员:

public function sendMail($observer)
{
    /* Get Order ID by Observer */
    $_orderID = $observer->getOrder()->getID();

    /* Load $order by Order ID */
    $_order = Mage::getModel('sales/order')->load($_orderID);

    try {
        /* Load Email Template by template name */
        $emailTemplate = Mage::getModel('core/email_template');
        $emailTemplate->loadDefault('send_mail');
        $emailTemplate->setTemplateSubject('SITE.COM: You Have New Order');

        $salesData['email'] = 'example@site.com';
        $salesData['name'] = Mage::getStoreConfig('trans_email/ident_general/name');

        /* Set Sender name and email by General email */
        $emailTemplate->setSenderName($salesData['name']);
        $emailTemplate->setSenderEmail($salesData['email']);

        /* Create email template by Order data */
        $emailTemplateVariables['username'] = $_order->getCustomerName();
        $emailTemplateVariables['shipping_address'] = $_order->getShippingAddress()->format('html');
        $emailTemplateVariables['shipping_description'] = $_order->getShippingDescription();
        $emailTemplateVariables['order_id'] = $_order->getIncrementId();
        $emailTemplateVariables['creating_time'] = $_order->getCreatedAtFormated('long');
        $emailTemplateVariables['is_not_virtual'] = $_order->getIsNotVirtual();
        $emailTemplateVariables['store_name'] = $_order->getStoreName();
        $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
        $emailTemplateVariables['order'] = $_order;

        /* Send email, when order was placed */
        $emailTemplate->setType('html');
        $emailTemplate->send($salesData['email'], $_order->getStoreName(), $emailTemplateVariables);

        /* Add  Success Message to system.log if email was sent */
        Mage::log('Success! Email was sent.');

    } catch (Exception $e) {
        /* Add error message to system.log if email wasn't sent */
        Mage::logException($e);
    }
    return $this;
}

config.xml

<events>
        <sales_order_place_after>
            <observers>
                <sendmail>
                    <type>singleton</type>
                    <class>Custom_SendMail_Model_Order_Observer</class>
                    <method>sendMail</method>
                </sendmail>
            </observers>
        </sales_order_place_after>
    </events>
    <template>
        <email>
            <send_mail translate="label">
                <label>New Order for Dropshippers</label>
                <file>sales/order_dropship.html</file>
                <type>html</type>
            </send_mail>
        </email>
    </template>

谢谢!

1 个答案:

答案 0 :(得分:1)

我找到了解决这个问题的方法。需要使用checkout_submit_all_after事件代替sales_order_place_after