将发票电子邮件发送到magento中的自定义邮件地址

时间:2015-10-19 09:22:56

标签: magento

我添加了自定义功能,可以将发票电子邮件发送到其他一些邮件地址(不包括客户和管理员)。为此我在观察者中调用了自定义函数

<sales_order_invoice_save_after>
    <observers>
       <test>
          <type>singleton</type>
          <class>test/observer</class>
          <method>sentMailToothers</method>
       </test>
   </observers>        

观察员代码

  $template_id    =   'sales_email_invoice_template';
  $emailTemplate  =   Mage::getModel('core/email_template')->loadDefault($template_id);
  $storeId =   Mage::app()->getStore()->getStoreId();
  $invoice =   $observer->getEvent()->getInvoice();  
  $order   =   $observer->getEvent()->getInvoice()->getOrder();
if ($order->hasInvoices()) 
            {
                foreach ($order->getInvoiceCollection() as $inv) 
                {
                    $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
                    $paymentBlockHtml = $paymentBlock->toHtml();

                    $email_to = 'test@test.com';//dynamic email address
                    $customer_name = 'Test'
                    $email_template_variables = array(
                                                    'order' => $order,
                                                    'invoice' => $invoice,
                                                    'payment_html' => $paymentBlockHtml
                                                    );

                    $sender_name = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
                    $sender_email = Mage::getStoreConfig('trans_email/ident_general/email');
                    $emailTemplate->setSenderName($sender_name);
                    $emailTemplate->setSenderEmail($sender_email);
                    $processedTemplate = $emailTemplate->getProcessedTemplate($email_template_variables);

                    echo $processedTemplate;die;
                    //Send the email!
                    $emailTemplate->send($email_to, $customer_name, $email_template_variables);
                }
            }

一切正常,但产品信息未显示在模板中。

有人可以弄清楚我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

不需要此代码。在magento中有默认功能,可以将发票电子邮件发送到密件抄送。

转到管理员 - >系统(主要导航) - >配置(子导航) - &gt;销售电子邮件 - &gt;发票(标签) - &gt;字段&#34;发送发票电子邮件复制到&#34;

请查看以下截图。

enter image description here