Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Need some help with a simple custom module
 
greenie2600
Jr. Member
 
Total Posts:  1
Joined:  2009-05-06
 

Hi all -

I need a little guidance with my first custom Magento module. Hope someone can help.

I’ve successfully installed a third-party module which requires administrative approval of new customers before they can log in.

I want customers to receive an email whenever their account is activated. Since nothing in the CustomerActivation module gets invoked when the customer edit screen is saved in the admin, I think I need to write another module to observe the Customer object and send the email when the customer_activated property is changed (please correct me if I’m wrong).

Since there are no customer-specific events which are useful for this purpose, I’m using the model_save_before event. Of course, this means that my Observer.php will be triggered whenever a model of any kind is saved, so my Observer.php will need to confirm that the model_save_before event was triggered on a customer, and not some other object, before it does anything.

I’ve tested the basic skeleton of my module with some dummy code; it is being invoked (as expected) whenever any model is saved.

My questions:

1. Is this a completely wrongheaded way to do this? It seems kludgey and inefficient to attach my observer to EVERY model_save_before event, but I don’t see another way to do it without editing the Magento core to add a custom customer_approved event.

2. If this is a viable approach, how can my Observer.php get the class name of the triggering object? I’ve traced through the relevant inheritance trees, and don’t see anything helpful.

The code for my Observer.php is below. Any advice will be appreciated. Thanks!

<?php

class ElectrumDigital_ActivationEmail_Model_Observer {

    
public function __construct() {}

    
public function email_customer_if_activated$observer {

        $event 
$observer->getEvent();

        
$model = ??? // how do I determine the type of the triggering object?
        
if ( is_a$model'Mage_Customer_Model_Customer' ) ) {
            
if ( $model->dataHasChangedFor'customer_activated' ) && $model->getData'customer_activated' ) == {
                
// ... send email to customer ...
            
}
        }
        
        
return $this;
            
    
}

}

?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top