customer session is empty in custom module magento -
i have made custom module uses customer session, strange, on live site not returning customer data. 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 print customer session:
mage::getsingleton('customer/session')->getdata();
this returns (exact output):
array( [_session_validator_data] => array ( [remote_addr] => 58.65.183.10 [http_via] => [http_x_forwarded_for] => 58.65.183.10 [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 exhausted here , logged in, can see customer dashboard customer info on not been able use session in custom module, please guide me how fix this.
update:
i have checked in /app/etc/local.xml session type file
<session_save><![cdata[files]]></session_save>
so there different method of extracting session info php ? doing wrong?
update 2:
i have used router make pretty url public function match(zend_controller_request_http $request)
on start of action placed
mage::getsingleton('core/session', array('name' => 'frontend'));
but still not working router without 1 working example directly accessing action :
site.com/module/controller/action
it works not router. thoughts? thanks,
the solution simple:
private function _getcustomersession() { mage::getsingleton('core/session', array('name' => 'frontend')); return mage::getsingleton('customer/session'); }
this initializes session , returns it. call function this:
$this->_getcustomersession()->getcustomer()
and have data available.
update googlers , future reference: had issue again today , own solution didn't work (like question). further investigation revealed have overridden predispatch()
function in custom module check if module enabled in backend , if not redirect homepage error. in case solution -obviously- call parent::predispatch();
Comments
Post a Comment