doumouyi4039 2013-02-05 21:07
浏览 37
已采纳

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

I've been looking through files and scratching my head. Where is the function to send new account creation emails? And once I find it what variable would I use to refer to a particular customer group?

EDIT 2/18 Per the suggestion below I am looking at the Customer.php file and see the following function:

 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;
    }

I assume I can set a different type in the $types array but how do I access the constant const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity' to set a new type condition? I haven't yet figured out how to find xml paths.


Edit 2/21

I've copied the whole module file and renamed it and created it as my own module. I changed the following in the config file:

<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>

To add my template and also here second from bottom.

<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>

Then added the constant to Customer.php

const XML_PATH_CONFIRM_EMAIL_TEMPLATE_DVM       = 'customer/create_account/email_confirmation_template_dvm';

and modified function:

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;
    }

I tested it out and it does not work. As you can see I have some echos to trace, but I'm not sure how to directly debug this. I have Firebug but can't figure out how to use it. Any suggestions would be more than greatly appreciated. Would $session->isLoggedIn() evaluate false?

UPDATE 2/27/13___________________________________________ @Meabed I'm trying to replicate what you are doing in blog post. I made a folder called CaitlinHavener, put DVMCustomer directory in it and an etc folder within that. I have config.xml inside of it:

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

and inside system.xml I have:

<?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>

I created a modules xml called CaitlinHavener_DVMCustomer.xml and put it in the modules folder:

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

When I go to system>config>advanced I can see that the system registers the module but when I go to system>transactional emails I do not see it there or when I create new template and select "load template".

Do you see what I am doing wrong?

  • 写回答

2条回答 默认 最新

  • duangengruan2144 2013-02-06 13:45
    关注

    You need to make another module and Extend the customer Model

    class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract
    

    the model has all the method related to send emails, so you need to check for the customer group and set the template the you want to send.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据