1

I have made a custom module which uses the customer session, but its strange, on live site its not returning customer data.

I have tried following methods:

$sessCustomer = Mage::getSingleton('customer/session', array('name' => 'frontend'));
echo '<pre>';print_r($sessCustomer->getCustomer()->getData()); echo '</pre>';exit;

It returns:

Array
(
    [website_id] => 1
)

If I print the customer session:

Mage::getSingleton('customer/session')->getData();

This returns:

array(
    [_session_validator_data] => Array
        (
            [remote_addr] => <MY IP>
            [http_via] => 
            [http_x_forwarded_for] => <MY IP>
            [http_user_agent] => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
        )

    [session_hosts] => Array
            (
                [bestevalue.info] => 1
            )
    [messages] => Mage_Core_Model_Message_Collection Object
            (
                [_messages:protected] => Array
                    (
                    )

                [_lastAddedMessage:protected] => 
            )
    [id] => 
)

I am logged in, can see the customer dashboard with customer info on it but not able to use that session in my custom module.

Please guide me how to fix this.

Update:

I have checked in /app/etc/local.xml that session type is file

<session_save><![CDATA[files]]></session_save>

So is there different method of extracting session info with PHP? What am I doing wrong?

Update 2:

i have used router as well to make pretty url

public function match(Zend_Controller_Request_Http $request)

on start of this action i placed

Mage::getSingleton('core/session', array('name' => 'frontend'));

but still not working with router without one it is working for example directly accessing the action :

site.com/module/controller/action

it works but not with router. any thoughts? thanks,

9
  • I assume that the general user login is working (i.e. your customer can access the personal user page?) - then it can not be a problem with the session storage.
    – Alex
    Commented May 10, 2013 at 9:33
  • yes its working i can see my dashboard with info
    – R T
    Commented May 10, 2013 at 9:34
  • What class are you extending in your module? It could be that you are extending an admin area class and thats where the issue stems from Commented May 10, 2013 at 9:41
  • my controllers extends this class Mage_Core_Controller_Front_Action
    – R T
    Commented May 10, 2013 at 9:47
  • In which place / file are you making the above calls?
    – Alex
    Commented May 10, 2013 at 9:49

2 Answers 2

1

What is the point of the second parameter in Mage::getSingleton()? This info would be passed to the constructor of the Mage_Customer_Model_Session class, but this constructor does not take arguments:

Replacing this by

$sessCustomer = Mage::getSingleton('customer/session');

should work.

I assume, that you added your

var_dump(Mage::getSingleton('customer/session')->getData());

after this error-nous call which could have destroyed the session in your module.

1
  • replaced but still the same result. acutaly it was all part of what i tried so far. i have tried em separately.
    – R T
    Commented May 10, 2013 at 9:46
0

I suffered by not getting the customer session inside my custom module. It was working in my localhost fine but in server i couldn't able to get the customer session.

I have found the solution by replacing the frontname in config.xml,

i have just changed <frontName>votingsytem</frontName> to <frontName>vote</frontName>

i got the customer session it work fine in live server.

I hope this will be useful.

Before:

<frontend>
  <routers>
     <votingsytem>
        <use>standard</use>
        <args>
           <module>Vgs_Votingsytem</module>
           <frontName>votingsytem</frontName>
        </args>
     </votingsytem>        
  </routers>
  <layout>
     <updates>
        <votingsytem>
           <file>votingsytem.xml</file>
        </votingsytem>
     </updates>
  </layout>

After:

<frontend>
  <routers>
     <votingsytem>
        <use>standard</use>
        <args>
           <module>Vgs_Votingsytem</module>
           <frontName>vote</frontName>
        </args>
     </votingsytem>        
  </routers>
  <layout>
     <updates>
        <votingsytem>
           <file>votingsytem.xml</file>
        </votingsytem>
     </updates>
  </layout>

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.