简体   繁体   中英

Send admin email on registration success in Magento

I'm trying to get this example working to send on an email to admin upon successful registration. 'I think' i have it set up correctly ... but exactly notta is happening:

config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <WACI_CustomerExt>
            <version>0.1.0</version>
        </WACI_CustomerExt>
    </modules>
    <global>
        <models>
            <WACI_CustomerExt>
                <class>WACI_CustomerExt_Model</class>
            </WACI_CustomerExt>
        </models>
        <template>
            <email>
                <!-- regisration success -->
                <notify_new_customer module="WACI_CustomerExt">
                    <label>Admin notification on registration success</label>
                    <file>notify_new_customer.html</file>
                    <type>html</type>
                </notify_new_customer>
            </email>
        </template>
    </global>
    <frontend>
        <events>
            <!-- regisration success -->
            <customer_register_success>
                <observers>
                    <WACI_CustomerExt>
                        <type>model</type>
                        <class>waci_customerext/observer</class>
                        <method>customer_register_success</method>
                    </WACI_CustomerExt>
                </observers>
            </customer_register_success>
        </events>
    </frontend>
</config>

namespace/module/group/Observer.php

<?php 

require_once('../../../../../Mage.php');

class WACI_CustomerExt_Model_Observer 
{

    public function __construct()
    {

    }

    public function customer_register_success( Varien_Event_Observer $observer )
    {

        $emailTemplate  = Mage::getModel('core/email_template')
            ->loadDefault('notify_new_customer');
        $emailTemplate
            ->setSenderName(Mage::getStoreConfig('trans_email/ident_support/name'))
            ->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email'))
            ->setTemplateSubject('New customer registered');
        $result = $emailTemplate->send(Mage::getStoreConfig('trans_email/ident_general/email'),(Mage::getStoreConfig('trans_email/ident_general/name'), $observer->getCustomer()->getData());

    }

}

local/en_us/template/notify_new_customer.html

New customer registration:<br />
Name: {{var name}}<br />
Email: {{var email}}<br />
... you win a pickle.

Two things that seem suspect: I doubt i have my observer set up correctly in my config. I expect that I need to include app/mage.php (but it does no do this in the example).

I'm not getting any errors, per se, in the logs, so I'm assuming the event isn't getting either registered or properly handled.

Whatever the case, in typical Magento form, my attempt at this isn't working.

I'd appreciate some advice ;D

Cheers

Logging definitely produced an include error

Failed opening 'Mage/Waci/Customerext/Model/Observer.php'

obviously, my class reference needed the correct case.

<events>
            <!-- regisration success -->
            <customer_register_success>
                <observers>
                    <WACI_CustomerExt>
                        <type>model</type>
                        <class>WACI_CustomerExt/Observer</class>
                        <method>customer_register_success</method>
                    </WACI_CustomerExt>
                </observers>
            </customer_register_success>
        </events>

Also, slight syntax error came up in the send() call right about here : /email'),(Mage::getSt .

Anyway, as per usual, config was my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM