1

I am trying to hook a session variable to customer login event with the help of this tutorial http://mattmcalear.net/magento-event-observers-user-login/

I have created the module but it is not showing the custom session variable value in the frontend. What am I doing wrong?

/app/etc/modules/Designota_Savepasscode.xml

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

/app/code/local/Designota/Savepasscode/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Designota_Savepasscode>
            <version>0.0.1</version>
        </Designota_Savepasscode>
    </modules>
    <global>
        <models>
            <designota_savepasscode>
                <class>Designota_Savepasscode_Model</class>
            </designota_savepasscode>
        </models>
        <events>
            <customer_login>
              <observers>
                  <designota_savepasscode>
                      <class>designota_savepasscode/observer</class>
                      <method>customerLogin</method>
                      <type>singleton</type>
                  </designota_savepasscode>
              </observers>
            </customer_login>
        </events>
    </global>
</config>

/app/code/local/Designota/Savepasscode/Model/Observer.php

<?php
class Designota_Savepasscode_Model_Observer
{
    public function customerLogin(Varien_Event_Observer $observer)
    {
        $session = Mage::getSingleton('customer/session');
        $session->setPasscode($login['passcode']);
    }
}

In the frontend I use the below code for getting the session variable

$session = Mage::getSingleton('customer/session');
if($session) {
    $session->getPasscode();
}
2
  • Isn't $login['passcode'] an undefined variable here ?
    – Prateek
    Dec 7, 2015 at 13:45
  • $login['passcode'] is an extra required field in login form where customer will enter. @Prateek
    – zeusukdm
    Dec 7, 2015 at 13:53

1 Answer 1

2

As per as your comment in order to check passcode variable.you need to use

Mage::app()->getRequest()->getParam('variable');

So,for this case you need to use

$login=Mage::app()->getRequest()->getParam(('login');

$passcode=$login['passcode'];

2
  • thank you for your answer however it didn't work. the input field in the login.phtml is <input type="passcode" name="login[passcode]" class="input-text required-entry" id="passcode" title="<?php echo $this->__('Passcode') ?>" /> I just want to save the value of this input field as a session variable and use it in the frontend. @Amit Bera
    – zeusukdm
    Dec 7, 2015 at 14:13
  • pleasew ckd now
    – Amit Bera
    Dec 7, 2015 at 14:30

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.