2013-09-26 33 views
0

在发送邮件给顾客的时候,在这个邮件邮件中,我们从track.phtml获得追踪号码,现在邮件的主题部分就像是订单号码和出货号。我想改变我们作为邮件发送邮件的主题。该主题必须跟踪号码。对于订单号我们可以用“order.increment_id”得到,但我不知道如何获得跟踪号。那么如何在电子邮件主题中显示跟踪号码?在电子邮件主题部分包含追踪号码

回答

3

这不能通过在电子邮件模板中使用像“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}}

+0

我按照所有的步骤,您发货邮件tempate主题。但它没有显示电子邮件主题中的任何跟踪号码。我们是否错过了任何地方? –

+0

@Johngrews确认以下... ** 1 >> **没有其他模块重写类Mage_Sales_Model_Order_Shipment(只需在“code”目录中搜索“order_shipment”)。如果您发现任何的比赛就像下面的代码,让我知道 ' Some_Class_Name_Here ' ** 2 ** >>您刷新Magento缓存。 ** 3 >> **您编辑了正确的模板。可能有机会修改错误的模板。如果您在app/locale/your_locale/template/email/sales/shipment_new.html .. – Nidheesh

+0

@Johngrews继续之前的msg中编辑模板文件... 请确保您没有模板数据库副本..如果您有一个,编辑该模板的主题。 – Nidheesh

相关问题