0
在發送郵件給顧客的時候,在這個郵件郵件中,我們從track.phtml獲得追蹤號碼,現在郵件的主題部分就像是訂單號碼和出貨號。我想改變我們作爲郵件發送郵件的主題。該主題必須跟蹤號碼。對於訂單號我們可以用「order.increment_id」得到,但我不知道如何獲得跟蹤號。那麼如何在電子郵件主題中顯示跟蹤號碼?在電子郵件主題部分包含追蹤號碼
在發送郵件給顧客的時候,在這個郵件郵件中,我們從track.phtml獲得追蹤號碼,現在郵件的主題部分就像是訂單號碼和出貨號。我想改變我們作爲郵件發送郵件的主題。該主題必須跟蹤號碼。對於訂單號我們可以用「order.increment_id」得到,但我不知道如何獲得跟蹤號。那麼如何在電子郵件主題中顯示跟蹤號碼?在電子郵件主題部分包含追蹤號碼
這不能通過在電子郵件模板中使用像「order.increment_id」這樣的變量名來完成。您必須將跟蹤數據發送到電子郵件模板處理器,以4個步驟爲例來實現此目的。
步驟1 >>添加模塊配置 在應用程序的/ etc /模塊/ Eglobe_Sales.xml
<?xml version="1.0"?>
<config>
<modules>
<Eglobe_Sales>
<active>true</active>
<codePool>local</codePool>
</Eglobe_Sales>
</modules>
</config>
第二步>>添加config.xml中(應用程序/代碼/本地/環球商業網/銷售/等/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>
第三步>>重寫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;
}
}
第四步:>>修改通過添加{{VAR tracks.track_number}}
我按照所有的步驟,您發貨郵件tempate主題。但它沒有顯示電子郵件主題中的任何跟蹤號碼。我們是否錯過了任何地方? –
@Johngrews確認以下... ** 1 >> **沒有其他模塊重寫類Mage_Sales_Model_Order_Shipment(只需在「code」目錄中搜索「order_shipment」)。如果您發現任何的比賽就像下面的代碼,讓我知道 ' Some_Class_Name_Here order_shipment> ' ** 2 ** >>您刷新Magento緩存。 ** 3 >> **您編輯了正確的模板。可能有機會修改錯誤的模板。如果您在app/locale/your_locale/template/email/sales/shipment_new.html .. –
Nidheesh
@Johngrews繼續之前的msg中編輯模板文件... 請確保您沒有模板數據庫副本..如果您有一個,編輯該模板的主題。 – Nidheesh