kost
kost

Reputation: 325

How can I use my own email template in Magento 1.7.2 email function?

Hi to all out there :)

I am using a php script in order to send to a customers group an email with their new credentials.

The command that I use and sends the email is below:

$customer->sendNewAccountEmail();

This sents an email to a customer and uses the template called "New Account"

The question is that I have created a new custom template called Send password to Resellers template

So how can I run this command $customer->sendNewAccountEmail(); but use my new template?

Upvotes: 0

Views: 369

Answers (2)

MagePal Extensions
MagePal Extensions

Reputation: 17656

If you are tring to have both a 'new order' and 'reseller' template, one way to accomplish this would be :

Create a new module that extend Mage_Customer_Model_Customer

 class MagePal_ResellerCustomer_Model_Customer extends Mage_Customer_Model_Customer
      const XML_PATH_REGISTER_RESELLERS_EMAIL_TEMPLATE = 'customerreseller/create_account/email_template';

    public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
    {
        $types = array(
            'registered'   => self::XML_PATH_REGISTER_RESELLERS_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;
    }

Add a System Configuration to your module so you can select your custom email template (see Custom Magento System Configuration)

in system.xml

<email_template>
    <label>Email Template</label>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <sort_order>5</sort_order>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_email_template</source_model>
</email_template>

Then to send your email do

if(customer group == reseller):
   $customer = Mage::getModel('resellercustomer/customer')->load($customer_id)
   $customer->sendNewAccountEmail();
else
   $customer = Mage::getModel('customer/customer')->load($customer_id)
   $customer->sendNewAccountEmail();

If you just want to use your new template take a look @ Customizing Email Templates

Admin menu > System > Config > Customer Configuration > Create New Account Options.

Upvotes: 1

wesside
wesside

Reputation: 5740

You will need to modify an option in the database to use the new template, here:

http://www.magentocommerce.com/knowledge-base/entry/how-to-send-confirmation-email-to-new-account-subscribers

Upvotes: 1

Related Questions