Email Notification when a new customer has been added - Magento

后端 未结 7 1081
鱼传尺愫
鱼传尺愫 2021-01-03 06:31

I would like to send an email notification to my store\'s contact email address every time when a new customer has been Registered.

I don\'t want to purchase any kin

7条回答
  •  天涯浪人
    2021-01-03 07:13

    Best practice is to use Magento's event system.

    app/etc/modules/Your_Module.xml

    
    
        
            
                true
                local
            
        
    
    

    app/core/local/Your/Module/etc/config.xml

    
    
        
            
                
                    Your_Module_Model
                
            
        
        
            
                
                    
                        
                            model
                            your_module/observer
                            customerSaveAfter
                        
                    
                
            
        
    
    

    app/code/local/Your/Module/Model/Observer.php

    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 
            }
        }
    }
    

    EDIT: Note the edit in the code - as AlphaCentauri pointed out, the customer_save_after event is fired for both inserts and updates. The _origData conditional logic should allow you to incorporate his mailing logic. _origData will be null.

提交回复
热议问题