包括电子邮件主题部分中的跟踪号码

时间:2013-09-26 08:19:08

标签: magento magento-1.7 magento-1.4 magento-1.5 magento-1.6

当我们向客户发送发送电子邮件时,在此发件人电子邮件中,我们从track.phtml获取跟踪号码,现在电子邮件的主题部分就像是订单号和发货号。我想更改我们作为发送电子邮件的电子邮件的主题。主题必须与跟踪号码。对于订单号,我们可以使用“order.increment_id”,但我不知道如何获得跟踪号码。那么如何在电子邮件主题中显示跟踪号码?

1 个答案:

答案 0 :(得分:3)

这不能仅通过在电子邮件模板中使用类似“order.increment_id”的变量名来完成。您必须通过4个步骤的示例将跟踪数据发送到电子邮件模板处理器以实现此目的。

<强>步骤1&GT;&GT;添加模块配置 在app / etc / modules / Eglobe_Sales.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Eglobe_Sales>
            <active>true</active>
            <codePool>local</codePool>
        </Eglobe_Sales>
    </modules>
</config>

<强>第二步&GT;&GT;添加config.xml(app / code / local / Eglobe / Sales / etc / config.xml)

<?xml version="1.0"?>
<config>
    <modules>
        <Eglobe_Sales>
            <version>0.1.0</version>
        </Eglobe_Sales>
    </modules>
    <global>
        <models>
            <sales>
                <rewrite>
            <order_shipment>Eglobe_Sales_Model_Order_Shipment</order_shipment>
        </rewrite>
            </sales>
        </models>
    </global>
</config>

<强>步骤3&GT;&GT;覆盖Mage_Sales_Model_Order_Shipment :: sendEmail()

     <?php

class Eglobe_Sales_Model_Order_Shipment extends Mage_Sales_Model_Order_Shipment {

    /**
     * Send email with shipment data
     *
     * @param boolean $notifyCustomer
     * @param string $comment
     * @return Mage_Sales_Model_Order_Shipment
     */
    public function sendEmail($notifyCustomer = true, $comment = '')
    {
        $order = $this->getOrder();
        $storeId = $order->getStore()->getId();

        if (!Mage::helper('sales')->canSendNewShipmentEmail($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);
        // Check if at least one recepient is found
        if (!$notifyCustomer && !$copyTo) {
            return $this;
        }

        // Start store emulation process
        $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($order->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 ($order->getCustomerIsGuest()) {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
            $customerName = $order->getBillingAddress()->getName();
        } else {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
            $customerName = $order->getCustomerName();
        }

        $mailer = Mage::getModel('core/email_template_mailer');
        if ($notifyCustomer) {
            $emailInfo = Mage::getModel('core/email_info');
            $emailInfo->addTo($order->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' or a customer should not be notified
        if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
            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' => $order,
            'shipment' => $this,
            'comment' => $comment,
            'billing' => $order->getBillingAddress(),
            'payment_html' => $paymentBlockHtml,
//setting the `track number here, A shihpment can have more than one track numbers so seperating by comma`
            'tracks' => new Varien_Object(array('tracking_number' => implode(',', $this->getTrackingNumbers())))
                )
        );
        $mailer->send();

        return $this;
    }

    //Creating track number array
    public function getTrackingNumbers()
    {
        $tracks = $this->getAllTracks();
        $trackingNumbers = array();
        if (count($tracks)) {
            foreach ($tracks as $track) {
                $trackingNumbers[] = $track->getNumber();
            }
        }
        return $trackingNumbers;
    }

}

<强>步骤4&GT;&GT;通过添加{{var tracks.track_number}}

修改您的货件电子邮件tempate主题