添加新客户后的电子邮件通知-Magento [英] Email Notification when a new customer has been added - Magento

查看:43
本文介绍了添加新客户后的电子邮件通知-Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次注册新客户后,我都希望向商店的联系电子邮件地址发送电子邮件通知.

I would like to send an email notification to my store's contact email address every time when a new customer has been Registered.

我不想购买任何扩展程序,所以请帮助我

I don't want to purchase any kind of the extensions, so please help me to do this

预先感谢

推荐答案

最佳做法是使用Magento的事件系统.

Best practice is to use Magento's event system.

app/etc/modules/Your_Module.xml

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

app/core/local/Your/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <models>
            <your_module>
                <class>Your_Module_Model</class>
            </your_module>
        </models>
    </global>
    <frontend>
        <events>
            <customer_save_after>
                <observers>
                    <your_module>
                        <type>model</type>
                        <class>your_module/observer</class>
                        <method>customerSaveAfter</method>
                    </your_module>
                </observers>
            </customer_save_after>
        </events>
    </frontend>
</config>

app/code/local/Your/Module/Model/Observer.php

<?php

class Your_Module_Model_Observer
{
    public function customerSaveAfter(Varien_Event_Observer $o)
    {
        //Array of customer data
        $customerData = $o->getCustomer()->getData();

        //email address from System > Configuration > Contacts
        $contactEmail = Mage::getStoreConfig('contacts/email/recipient_email');

        //Mail sending logic here.
        /*
           EDIT: AlphaCentauri reminded me - Forgot to mention that
           you will want to test that the object is new. I **think**
           that you can do something like:
        */
        if (!$o->getCustomer()->getOrigData()) {
            //customer is new, otherwise it's an edit 
        }
    }
}

编辑:请注意代码中的编辑-正如AlphaCentauri指出的那样,插入和更新都会触发customer_save_after事件. _origData条件逻辑应允许您合并他的邮件逻辑. _origData将为null.

Note the edit in the code - as AlphaCentauri pointed out, the customer_save_after event is fired for both inserts and updates. The _origData conditional logic should allow you to incorporate his mailing logic. _origData will be null.

这篇关于添加新客户后的电子邮件通知-Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆