基于所选客户组的成功注册

时间:2012-12-15 19:06:21

标签: magento registration

我正在建立一个Magento网站。目前在我已经建立的帐户注册表上,所以有一个下拉框,允许客户选择他们的“客户组”。

如果有四个不同的客户群,则有四个不同的成功电子邮件,默认的Magento,以及我要创建的3个。我需要的是根据选择的客户群发送适当的电子邮件。

我找到了在AccountController.php中发送新电子邮件的函数:

$customer->sendNewAccountEmail(
        $isJustConfirmed ? 'confirmed' : 'registered',
        '',
        Mage::app()->getStore()->getId()
    );

我最初的想法是在app / locale / en_US / template / email中创建其他电子邮件文件

但我不知道哪个文件/功能选择'account_new.html'作为默认电子邮件文件,因此我可以根据客户组ID实施一些检查。

我不确定接下来要采取的步骤,例如如何编辑此文件以及在何处创建不同的成功电子邮件。

1 个答案:

答案 0 :(得分:1)

您可能需要覆盖Mage_Customer_Model_Customer类来控制函数sendNewAccountEmail()。此功能是系统决定发送哪个电子邮件的理论,理论上您可以覆盖此功能。

您可能知道如何进行覆盖,但以防万一:

<models>
    <customer>
        <rewrite>
            <customer>Namespace_Module_Model_Customer</customer>
        </rewrite>
    </customer>
</models>

接下来,您需要创建系统配置值System.xml,您需要为每个“组”创建一个新条目。这不是最优雅的解决方案,因为这是一个静态列表,您的组可能是动态的。但是要分配模板,您需要一个全新的模块或更新此文件。但是,现在您可以创建事务性电子邮件并将其分配给此system.xml文件中的每个组。

<?xml version="1.0"?>
<config>
    <sections>
        <yourmodule translate="label" module="yourmodule">
            <class>separator-top</class>
            <label>your module</label>
            <tab>general</tab>
            <frontend_type>text</frontend_type>
            <sort_order>30</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
            <groups>
                <email translate="label">
                    <label>Email Templates</label>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <fields>
                        <group1_template translate="label comment">
                            <label>Group 1 Template</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </group1_template>
                        <group2_template translate="label comment">
                            <label>Group 2 Template</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </group2_template>
                    </fields>
                </email>
            </groups>
        </yourmodule>
    </sections>
</config>

最后,你的sendNewAccountEmail()的覆盖:

class Namespace_Module_Model_Customer {
    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
            'group1' => 'yourmodule/email/group1_template',
            'group2' => 'yourmodule/email/group2_template',
        );
        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;
    }
}

显然还有很大的改进空间,即想出一种动态拉动客户群并从中创建配置的方法,并另外将相同的动态检查添加到此功能,但这是一个简单的静态解决方案。

相关问题