添加新客户时的电子邮件通知-Magento
每次新客户注册后,我都会向我的店铺的联系人电子邮件地址发送电子邮件通知 我不想购买任何类型的扩展,所以请帮助我这样做添加新客户时的电子邮件通知-Magento,magento,Magento,每次新客户注册后,我都会向我的店铺的联系人电子邮件地址发送电子邮件通知 我不想购买任何类型的扩展,所以请帮助我这样做 提前感谢您可以在保存(变量对象$Customer)之前扩展Mage/Customer/Resource/Customer.php-受保护的函数\u 最佳实践是使用Magento的事件系统 app/etc/modules/Your_Module.xml <?xml version="1.0" encoding="UTF-8"?> <config> &
提前感谢您可以在保存(变量对象$Customer)之前扩展
Mage/Customer/Resource/Customer.php
-受保护的函数\u
最佳实践是使用Magento的事件系统
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>
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Namespace_Modulename>
<active>true</active>
<codePool>local</codePool>
</Namespace_Modulename>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Modulename>
<version>0.0.1</version>
</Namespace_Modulename>
</modules>
<frontend>
<events>
<customer_register_success>
<observers>
<unic_observer_name>
<type>model</type>
<class>unic_class_group_name/observer</class>
<method>customerRegisterSuccess</method>
</unic_observer_name>
</observers>
</customer_register_success>
</events>
<helpers>
<unic_class_group_name>
<class>Namespace_Modulename_Helper</class>
</unic_class_group_name>
</helpers>
</frontend>
<global>
<models>
<unic_class_group_name>
<class>Namespace_Modulename_Model</class>
</unic_class_group_name>
</models>
<template>
<email>
<notify_new_customer module="Namespace_Modulename">
<label>Template to notify administrator that new customer is registered</label>
<file>notify_new_customer.html</file>
<type>html</type>
</notify_new_customer>
</email>
</template>
</global>
</config>
Congratulations, a new customer has been registered:<br />
Name: {{var name}}<br />
Email: {{var email}}<br />
...<br />
真的
地方的
app/core/local/Your/Module/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Your_Module>
<active>true</active>
<codePool>local</codePool>
</Your_Module>
</modules>
</config>
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Namespace_Modulename>
<active>true</active>
<codePool>local</codePool>
</Namespace_Modulename>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Modulename>
<version>0.0.1</version>
</Namespace_Modulename>
</modules>
<frontend>
<events>
<customer_register_success>
<observers>
<unic_observer_name>
<type>model</type>
<class>unic_class_group_name/observer</class>
<method>customerRegisterSuccess</method>
</unic_observer_name>
</observers>
</customer_register_success>
</events>
<helpers>
<unic_class_group_name>
<class>Namespace_Modulename_Helper</class>
</unic_class_group_name>
</helpers>
</frontend>
<global>
<models>
<unic_class_group_name>
<class>Namespace_Modulename_Model</class>
</unic_class_group_name>
</models>
<template>
<email>
<notify_new_customer module="Namespace_Modulename">
<label>Template to notify administrator that new customer is registered</label>
<file>notify_new_customer.html</file>
<type>html</type>
</notify_new_customer>
</email>
</template>
</global>
</config>
Congratulations, a new customer has been registered:<br />
Name: {{var name}}<br />
Email: {{var email}}<br />
...<br />
您的_模块_模型
模型
您的_模块/观察员
顾客储蓄
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
}
}
}
使用Magento事件/观察者系统可以完美地完成此操作。
首先,注册你的模块
app/etc/modules/Namespace_Modulename.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Your_Module>
<active>true</active>
<codePool>local</codePool>
</Your_Module>
</modules>
</config>
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Namespace_Modulename>
<active>true</active>
<codePool>local</codePool>
</Namespace_Modulename>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Modulename>
<version>0.0.1</version>
</Namespace_Modulename>
</modules>
<frontend>
<events>
<customer_register_success>
<observers>
<unic_observer_name>
<type>model</type>
<class>unic_class_group_name/observer</class>
<method>customerRegisterSuccess</method>
</unic_observer_name>
</observers>
</customer_register_success>
</events>
<helpers>
<unic_class_group_name>
<class>Namespace_Modulename_Helper</class>
</unic_class_group_name>
</helpers>
</frontend>
<global>
<models>
<unic_class_group_name>
<class>Namespace_Modulename_Model</class>
</unic_class_group_name>
</models>
<template>
<email>
<notify_new_customer module="Namespace_Modulename">
<label>Template to notify administrator that new customer is registered</label>
<file>notify_new_customer.html</file>
<type>html</type>
</notify_new_customer>
</email>
</template>
</global>
</config>
Congratulations, a new customer has been registered:<br />
Name: {{var name}}<br />
Email: {{var email}}<br />
...<br />
然后定义一个观察者方法
app/code/local/Namespace/Modulename/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
}
}
}
编辑:正如@benmarks指出的,如果客户在结账时注册,此解决方案将不起作用。描述了此行为的解决方案。但是,我认为,最好使用@benmarks建议的\u origData
功能。所以,用他的指导来实现你的需求
有用的链接:
作为基于事件的方法的替代方法,您可以运行单独的基于API的脚本来获取新客户(或更新的客户)并通过电子邮件发送给您,您可能希望也可能不希望获得每天一次的列表,而不是每个客户的电子邮件
好处:
- 您的Magento商店中未安装任何内容
- 不会向新的/更新的客户操作添加任何额外的处理或网络延迟
- 有机会将一天的所有电子邮件批处理为一封电子邮件
这是我最近使用的一个例子,它几乎正是你想要的,这就是为什么这引起了我的注意。代码是
您可以尝试此扩展,它会收到每个新客户注册的通知电子邮件,包括可自定义的电子邮件模板。
您可以尝试此扩展,它会收到每个新客户注册的通知电子邮件,包括可自定义的电子邮件模板 这也是向管理员发送新客户电子邮件的代码
将文件
\app\code\core\Mage\Customer\Model\Customer.php
重写为本地
\app\code\local\Mage\Customer\Model\Customer.php
替换以下功能
protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null)
{
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getEmail(), $this->getName());
$mailer->addEmailInfo($emailInfo);
// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
$mailer->setTemplateParams($templateParams);
$mailer->send();
return $this;
}
到
这不会接收在结账时注册的客户。这对我不起作用。没有管理员的邮件,我已经按照您的建议进行了所有必要的更改,但无法获得成功。请将您的电子邮件地址发送给我,以便我可以向您发送模块。请帮我处理一下这件急事。我的电子邮件地址是pawankr2010@gmail.comThis给我一个错误。。。无法发送标题;头已经发送到/../../../../../app/code/local/../../../../Model/Observer.php第14行,您找到解决方案了吗?这些答案有用吗?看起来事件/观察者模块就是一张票。是的,这里提供的解决方案是有用的,只是您需要对代码进行一些修改,无论如何,我有一个扩展,它提供了与@AlphaCentauri和benmarks指出的相同的功能,这个事件被触发了两次。下面的解决方案设置了一个标志,以防止两次发送电子邮件。