Jump to content

Manipulation of session variables in prestashop 1.7


Recommended Posts

Hello:

Post here you code so we can help you. You can use cookies without problem:

Context::getContext()->cookie->your_var = 'some value';

Regards

Share this post


Link to post
Share on other sites
  • 1 year later...

There is better way to do so in 1.7.x versions.

You make a function in the respective controller

private function _getSession()
{
	return \PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance()->get('session');
}

And then where you need it, first you assign using

$this->_getSession()->set('yourVariableName', $wanted_value);

then where you need to get the value

$choice = $this->_getSession()->get('yourVariableName');


Checked (and working) in 1.7.6.3 (latest at the moment of composing this message) either for front or admin module controllers.

Tried to make it working for the main module class but with no success for the moment.

Share this post


Link to post
Share on other sites
  • 2 months later...

As long as you have got the value in the variable then you make

$this->context->smarty->assign(
	array(
		...
		'choice' => $choice,
		...
	)
);

in the controller (where ... means other variables obviously).

Happy coding and happy Easter (if you are Orthodox).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More