I've written a magento controller which stores some filter information inside the customer session.
According to the magento 2 documentation I use dependency injection to let magento generate the session object for me:
/**
* @var \Magento\Catalog\Model\Session
*/
protected $_filterSession;
/**
* @param \Magento\Customer\Model\Session $filterSession
*/
public function __construct( \Magento\Customer\Model\Session $filterSession)
{
$this->_filterSession = $filterSession;
}
The injection process is working quite well. I'm able to access the session, store a variable in it and return it on a further invocation.
But magento seems to discard the whole session information from time to time. I cannot exactly identify the moment magento discards the information, it seems kind of random.
Here is the code:
$this->_filterSession->setFrequency($frequency);
$frequency = $this->_filterSession->getFrequency();
I tried out different session scopes but the behaviour is the same.
After many attempts I tried to use the PHP-session to store the information, but even this session was discarded from time to time.
I don't know what I'm doing wrong or what could be the reason for this weird behaviour. Does anybody else have a similar problem or an idea whats the reason?
Thanks in advance, Thomas
This usually happens when the browser loses session cookies. You should check if domain name changes during the session when the variables are lost. Or with a different browser. Might be some misbehaving browser plugin. Or some Magento extension. Many Mageno 2 extensions currently are poorly written.
I had a similar problem using PHP. I had set session.referer_check
. So, when a user was coming from an external page, the session was lost. If this is your problem, simply ini_set('session.referer_check', '');
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With