1

I know this has been asked before although the code to do this was not so clear and so I have the below code setup however no email is being sent and wondering what step I might of missed. Basically I want to when an admin inside Magento changes a customer to a different customer group and clicks save I then want to send the customer an email.

app/etc/modules/groupidemailnotice.xml

<?xml version="1.0"?>
  <config>
      <modules>
          <groupidemailnotice>
             <codePool>local</codePool>
             <active>true</active>
             <depends>
               <Mage_Catalog />
             </depends>
          </groupidemailnotice>
      </modules>
   </config>

app/code/local/groupidemailnotice/etc/config.xml

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

app/code/local/groupidemailnotice/Model/Observer.php

    <?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 */
                     mail("$customer->getEmail","approved","Yay your approved");
                     }
                 }else{
                 /* New Customer */

             }
         }

        }

?>

When I look at the system.log I see the below error

Notice: Undefined index: customer_group_id in /var/www/magento/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php on line 1780

But why would the observer not be able to get the customer group id??

1

Replace your code with this :

<adminhtml>
        <events>
            <adminhtml_customer_save_after>
               <observers>
                     <groupidemailnotice>
                         <type>singleton</type>
                         <class>Stackexchange_Magento37890_Model_Observer</class>
                         <method>checkDisplay</method>
                     </groupidemailnotice>
              </observers>
            </adminhtml_customer_save_after>
        </events>
 </adminhtml>
1

There are many things you are doing wrong here.
First your Module naming is incorrect. You cannot use groupidemailnotice as your module name.
You module is related to Customer so it should depend on Mage_Customer.
You can create a new module with name Groupid_Emailnotice and create a file app/etc/modules/Groupid_Emailnotice.xml with below code

<?xml version="1.0"?>
<config>
  <modules>
    <Groupid_Emailnotice>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
      <depends>
        <Mage_Customer />
      </depends>
    </Groupid_Emailnotice>
  </modules>
</config>

The config.xml file you created is also not at correct location. It should be on app/code/local/NAMESPACE/MODULENAME/etc/config.xml. So, Now add a config file in app/code/local/Groupid/Emailnotice/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Groupid_Emailnotice>
      <version>0.1.0</version>
    </Groupid_Emailnotice>
  </modules>
  <global>
    <events>
      <adminhtml_customer_save_after>
        <observers>
          <send_email_to_customer>
            <type>model</type>
            <class>Groupid_Emailnotice_Model_Observer</class>
            <method>sendMailNotice</method>
          </send_email_to_customer>
        </observers>
      </adminhtml_customer_save_after>
    </events>
  </global>
</config> 

Now create an observer in app/code/local/Groupid/Emailnotice/Model/Observer.php

<?php
class Groupid_Emailnotice_Model_Observer
{
    public function sendMailNotice(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 */
                mail("$customer->getEmail","approved","Yay your approved");
            }
        }else{
         /* New Customer */
        }
    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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