1

I am doing this in Magento 1.9 CE, and my objective is to log out the user as soon as the password is changed.

  1. I registered my extension.

    app/etc/modules/Bmg_Golo.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <Bmg_Golo>local</Bmg_Golo>
            <active>true</active>
        </modules>
    </config>
    
  2. My config.xml

app/code/local/Bmg/Golo/etc/config.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <config>
        <modules>
            <Bmg_Golo>
                <version>0.0.1</version>
            </Bmg_Golo>
        </modules>
        <global>
            <models>
                <bmg_golo>
                    <class>Bmg_Golo_Model</class>
                </bmg_golo>
            </models>
        </global>
        <frontend>
            <events>
                <controller_action_postdispatch_customer_account_resetpasswordpost> 
                    <observers>
                        <bmg_golo>
                            <type>singleton</type>
                            <class>Bmg_Golo_Model_Observer</class>
                            <method>logout</method>
                        </bmg_golo>
                    </observers>
                </controller_action_postdispatch_customer_account_resetpasswordpost>
            </events>
        </frontend>
    </config>
  1. I created an observer.

app/code/local/Bmg/Golo/module/Observer.php

    <?php
    /**
    * 
    */
    class Bmg_Golo_Model_Observer
    {
        public function logout($observer) {
            $session = Mage::getSingleton('customer/session');
                if ($session->isLoggedIn()) {
                    Mage::getSingleton('customer/session')->logout();
                }
        }

    }
    ?>

My customer logged out after changing the password. I doubt the event/observer in config is wrong and my method in the observer is not getting called. Please help me as I am new to Magento.

  • which event are use. – Ravindrasinh Zala Nov 15 '17 at 3:54
  • check your updated question. – Dhrumin Nov 15 '17 at 5:04
  • Thank you. can you tell me the event for when the customer changes password – Abhilash Narayan Nov 15 '17 at 7:38
  • @AbhilashNarayan let me know if you have any issue – Piyush Nov 15 '17 at 8:43
2

Change your app/etc/modules/Bmg_Golo.xml to below code

<config>
  <modules>
    <Bmg_Golo>
      <active>true</active>
      <codePool>local</codePool>
    </Bmg_Golo>
  </modules>
</config>
1

To check that your observer is being called, you can put below code in the observer function.

$event = $observer->getEvent();
Mage::log($event->getName(),null,'event.log');

It will print the event name in the /var/log/event.log file.

In this way, you can know whether your observer function is getting called on the event specified by you or not.

Update: Just noticed that your code in app/etc/modules/Bmg_Golo.xml file is not correct.

Please change it to:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <[Package]_[Module]>
      <active>true</active>
      <codePool>local</codePool>
    </[Package]_[Module]>
  </modules>
</config>

Please let me know if it helped.

  • No the observer is not getting called? what could be wrong can you tell me. I doubt the config.xml file where i am using the event controller_action_postdispatch_customer_account_resetpasswordpost might be wrong. – Abhilash Narayan Nov 15 '17 at 7:19
  • My code : pastiebin.com/5d48229fda2ad log not generated @Mohit thanks – zus Aug 5 at 12:36
  • @zus, which event are you working on? Can you describe your problem? – Mohit Kumar Arora Aug 5 at 13:49
  • Here is my complete module magento.stackexchange.com/q/284297/57334 – zus Aug 5 at 13:54
  • @MohitKumarArora Observer testing failed, $event = $observer->getEvent(); Mage::log($event->getName(),null,'event.log'); my code : justpaste.it/7hsyp – zus Aug 6 at 5:29
0

app/etc/modules/Bmg_Golo.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Bmg_Golo>
            <codePool>local</codePool>
            <active>true</active>
        </Bmg_Golo>
    </modules>
</config>

app/code/local/Bmg/Golo/etc/config.xml

...
<frontend>
    <events>
        <controller_action_postdispatch_customer_account_resetpasswordpost> 
            <observers>
                <bmg_golo_resetpassword>
                    <class>bmg_golo/observer</class>
                    <method>logout</method>
                </bmg_golo_resetpassword>
            </observers>
        </controller_action_postdispatch_customer_account_resetpasswordpost>
    </events>
</frontend>
...

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.