Magento需要向特定客户群发送自定义帐户确认电子邮件

时间:2013-02-05 21:07:26

标签: php magento

我一直在浏览文件并摸不着头脑。发送新帐户创建电子邮件的功能在哪里?一旦我发现它将使用什么变量来引用特定的客户群?

编辑2/18 根据下面的建议,我正在查看Customer.php文件并查看以下函数:

 public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
    {
        $types = array(
            'registered'   => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,  // welcome email, when confirmation is disabled
            'confirmed'    => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, // welcome email, when confirmation is enabled
            'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,   // email with confirmation link
        );
        if (!isset($types[$type])) {
            Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type'));
        }

        if (!$storeId) {
            $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
        }

        $this->_sendEmailTemplate($types[$type], self::XML_PATH_REGISTER_EMAIL_IDENTITY,
            array('customer' => $this, 'back_url' => $backUrl), $storeId);

        return $this;
    }

我假设我可以在$ types数组中设置不同的类型但是如何访问常量 const XML_PATH_REGISTER_EMAIL_IDENTITY ='customer / create_account / email_identity'来设置新的类型条件?我还没弄明白如何找到xml路径。


编辑2/21

我复制了整个模块文件并将其重命名并将其创建为我自己的模块。我在配置文件中更改了以下内容:

<customer_create_account_email_template_dvm translate="label" module="customer">
                    <label>New account DVM</label>
                    <file>account_new_dvm.html</file>
                    <type>html</type>
                </customer_create_account_email_template_dvm>

添加我的模板,然后从底部开始。

<create_account>
                <confirm>0</confirm>
                <default_group>1</default_group>
                <tax_calculation_address_type>billing</tax_calculation_address_type>
                <email_domain>example.com</email_domain>
                <email_identity>general</email_identity>
                <email_template>customer_create_account_email_template</email_template>
                <email_confirmation_template>customer_create_account_email_confirmation_template</email_confirmation_template>
                <email_register_template_dvm>customer_create_account_email_register_template_dvm</email_register_template_dvm>
                <email_confirmed_template>customer_create_account_email_confirmed_template</email_confirmed_template>
                <vat_frontend_visibility>0</vat_frontend_visibility>
            </create_account>

然后将常量添加到Customer.php

const XML_PATH_CONFIRM_EMAIL_TEMPLATE_DVM       = 'customer/create_account/email_confirmation_template_dvm';

和修改功能:

public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
    {

        Mage::getSingleton('core/session', array('name'=>'frontend')); 
        $session = Mage::getSingleton('customer/session');

        //Caitlin Havener
        //What Group do you belong to?
        if($session->isLoggedIn()) {
            $customerGroupID = $session->getCustomerGroupId();
            print("Customer Group ID is ". $customerID);
        } else {
            echo 'Not logged In';
        }

        //If you are DVM set your type
        if ($customerGroupID==5)
        {
            $type = 'dvm';
        }

        $types = array(
            'registered'   => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,  // welcome email, when confirmation is disabled
            'confirmed'    => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, // welcome email, when confirmation is enabled
            'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,   // email with confirmation link
            'dvm' => self::XML_PATH_REGISTER_EMAIL_TEMPLATE_DVM,   // dvm new account email
        );
        if (!isset($types[$type])) {
            Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type'));
        }

        if (!$storeId) {
            $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
        }

        $this->_sendEmailTemplate($types[$type], self::XML_PATH_REGISTER_EMAIL_IDENTITY,
            array('customer' => $this, 'back_url' => $backUrl), $storeId);

        return $this;
    }

我测试了它并且它不起作用。正如您所看到的,我有一些回声跟踪,但我不确定如何直接调试它。我有Firebug但无法弄清楚如何使用它。任何建议都会非常感激。 $ session-&gt; isLoggedIn()会评估错误吗?

更新2/27 / 13_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ @Meabed 我正在尝试复制您在博文中所做的事情。我创建了一个名为CaitlinHavener的文件夹,将DVMCustomer目录放在其中,并在其中放置一个etc文件夹。我里面有config.xml:

<template>
            <email>
                <CaitlinHavener_DVMCustomer translate="label" module="mymodule">
                    <label>DVMCustomer Template</label>
                    <file>custom/mytemplate.html</file>
                    <type>html</type>
                </CaitlinHavener_DVMCustomer>
            </email>
</template>

在system.xml里面我有:

<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <customer translate="label" module="mymodule">
            <groups>
                <custom_email translate="label">
                    <label>DVM Custom Template</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>5</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>0</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                            <exist_user_template translate="label">
                                <label>DVM Custom Template</label>
                                <frontend_type>select</frontend_type>
                                <source_model>adminhtml/system_config_source_email_template</source_model>
                                <sort_order>3</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>1</show_in_store>
                            </exist_user_template>
                    </fields>
                </custom_email>
            </groups>
        </customer>
    </sections>
</config>

我创建了一个名为CaitlinHavener_DVMCustomer.xml的模块xml并将其放在modules文件夹中:

<?xml version="1.0" encoding="UTF-8"?>
<config>    
    <modules>
        <CaitlinHavener_DVMCustomer>
            <active>true</active>
            <codePool>local</codePool>
        </CaitlinHavener_DVMCustomer>
    </modules>
</config>

当我进入系统&gt; config&gt;高级时,我可以看到系统注册模块,但是当我进入系统&gt;事务性电子邮件时,我没有看到它或者当我创建新模板并选择“加载模板”时。

你看到我做错了吗?

2 个答案:

答案 0 :(得分:0)

发送新帐户邮件的配置可在系统 - &gt;中找到。配置 - &gt;然后在左侧边栏中找到客户组并查找客户配置。在那里,您可以找到创建新帐户选项。

对于我所看到的客户群,核心Magento只允许在同一配置组中配置该选项foreach storeview。

答案 1 :(得分:0)

您需要制作另一个模块并扩展客户模型

class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract

模型具有与发送电子邮件相关的所有方法,因此您需要检查客户组并设置要发送的模板。