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.

Dhrumin
  • 861
  • 3
  • 8
  • 24

3 Answers3

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>
Piyush
  • 5,893
  • 9
  • 34
  • 64
  • Any help for observer https://magento.stackexchange.com/q/284297/57334 @Piyush thanks – zus Aug 05 '19 at 12:38
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.

Mohit Kumar Arora
  • 9,951
  • 7
  • 27
  • 55
  • 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 07:19
  • My code : https://www.pastiebin.com/5d48229fda2ad log not generated @Mohit thanks – zus Aug 05 '19 at 12:36
  • @zus, which event are you working on? Can you describe your problem? – Mohit Kumar Arora Aug 05 '19 at 13:49
  • Here is my complete module https://magento.stackexchange.com/q/284297/57334 – zus Aug 05 '19 at 13:54
  • @MohitKumarArora Observer testing failed, $event = $observer->getEvent(); Mage::log($event->getName(),null,'event.log'); my code : https://justpaste.it/7hsyp – zus Aug 06 '19 at 05: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>
...
PЯINCƎ
  • 11,669
  • 3
  • 25
  • 80