0

I'm trying to use observers
My goal is to do something after successful login
I wrote this but I think I don't understand something...
What's wrong?

app/etc/modules/Drg_Customeraccess.xml

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

app/code/local/Drg/Customeraccess/etc/config.xml

   <?xml version="1.0"?>
<customer_login>
    <observers>
        <Drg_Customeraccess>
            <type>model</type>
            <class>Drg_Customeraccess/observer</class>
            <method>customerLogin</method>
        </Drg_Customeraccess>
    </observers>
</customer_login>

app/code/local/Drg/Customeraccess/Model/observer.php

<?php
class Drg_Customeraccess_Model_Observer
{
    public function customerLogin($observer)
    {
        $customer = $observer->getCustomer();
        if ($customer){
        echo "nameOBS-".$customer->getFirstname();
        }


    }
}
?>

Thank you

1 Answer 1

0

app/code/local/Drg/Customeraccess/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Drg_Customeraccess>
            <version>0.1.0</version>
        </Drg_Customeraccess>
    </modules>
    <global>
        <models>
            <drg_customeraccess>
                <class>Drg_Customeraccess_Model</class>
            </drg_customeraccess>
        </models>
    </global>
    <frontend>
        <events>
            <customer_login>
                <observers>
                    <drg_customeraccess_login>
                        <type>singleton</type>
                        <class>drg_customeraccess/observer</class>
                        <method>customerLogin</method>
                    </drg_customeraccess_login>
                </observers>
            </customer_login>
        </events>
    </frontend>
</config>

app/code/local/Drg/Customeraccess/Model/Observer.php

<?php
class Drg_Customeraccess_Model_Observer extends Varien_Event_Observer
{
    public function customerLogin($observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        if ($customer)
        {
            echo "nameOBS-".$customer->getFirstname();
        }
    }
}
?>
22
  • thanks @Prince ...can you tell me if the observer is correct to to print customer info like name, mail etc??? if ($customer){ echo "nameOBS-".$customer->getFirstname(); }
    – Claudio
    Commented Sep 11, 2017 at 14:35
  • look my update please
    – PЯINCƎ
    Commented Sep 11, 2017 at 14:42
  • Observer.php is in uppercase
    – PЯINCƎ
    Commented Sep 11, 2017 at 14:52
  • now after login it goes to homepage and not to account page but I can't see "nameOBS" nowhere in code or printed on screen
    – Claudio
    Commented Sep 11, 2017 at 14:54
  • Try this and tell me what you see <?php class Drg_Customeraccess_Model_Observer extends Varien_Event_Observer { public function customerLogin($observer) { die('testttttt'); } } } ?>
    – PЯINCƎ
    Commented Sep 11, 2017 at 14:56

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.