cancel
Showing results for 
Search instead for 
Did you mean: 

How to store value in session in magento 2

How to store value in session in magento 2

Example: I have 2 observer classes.
1- category.php
2- product.php
I want to store the category.php data in a session variable, like $_SESSION['category']= $data; and call that session in product.php class.

2 REPLIES 2

Re: How to store value in session in magento 2

Hello @rababfzepcc1fc 

 

Please refer the below URL for the solution:

https://stackoverflow.com/questions/34170544/magento-2-0-set-session-variable

 

Thank you.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: How to store value in session in magento 2

when I try to unset the session variable by using 

$block->getCatalogSession()->unsProductId();

 that unset method unset the overall session and my site stop working. 

What I want is: I need to get the session value and insert it into the database after that unset that session value.