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?
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.
The configuration for sending new account mails can be found in System -> Configuration -> Then in the left sidebar the group Customers and look for Customer Configuration. There you can find Create new account options.
For what I'm seeing for the customer groups, core Magento allows only to configure that option foreach storeview in the same configuration group.