2

I would like to send a custom transactional email automatically to a user when he is assigned to a specific user group.

I think doing that with on observer but do not manage to find which event to trigger…

Thank you for your help,

1 Answer 1

6

Hi you can do this by magento event Observer and find a trigger an observer on customer save after and fire send your custom transactional email automatically.

You can try this Two Event

  1. customer_save_before

  2. customer_save_after

Find details on event and observer here

Model Approach

Step1: trigger an event on basic of customer_save_after

<global>
    <events>
        <customer_save_after>
            <observers>
                <stockalert>
                    <type>singleton</type>
                    <class>magento37890/observer</class>
                    <method>checkDisplay</method>
                </stockalert>
            </observers>
        </customer_save_after>
    </events>
</global>       

Step2: Magento Observer Code is

<?php
class Stackexchange_Magento37890_Model_Observer
{
    public function checkDisplay(Varien_Event_Observer $observer){

        $customer=$observer->getEvent()->getCustomer();
        Mage::log('My log entry'.$customer->getId(), null, 'Magento37890.log');
        /* if customer  is old customer */
        if($customer->getId()){
            if($customer->getOrigData('group_id')!=$customer->getData('group_id')){
            /* here you write your code to send whenever you have change the group */
            }
        }else{
        /* New Customer */

        }
    }

}
2
  • Checking for $customer->getId() under the event customer_save_after to determine if the customer is new would not work. Since the event is AFTER save, there will always be an id. You can determine if the customer is in fact new by checking the state of $customer->getOrigData() - if it is NULL, there was no previous data, so is assumed a new record.
    – ProxiBlue
    Jan 7, 2016 at 2:57
  • Thanks for comment , i am busy on project and will check comment late
    – Amit Bera
    Jan 7, 2016 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.