Jump to content

Manipulation of session variables in prestashop 1.7


Recommended Posts

  • 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.

  • Thanks 1
Link to comment
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).

Link to comment
Share on other sites

  • 2 years later...
  • 4 months later...
On 2/8/2020 at 12:26 PM, Kogkalidis said:

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');

 

I'm facing the same problem. the hook i use is fired 3 times. It's not an elegant fix but atleast your solution it's working.

Thanks!

 

Edited by Titi2 (see edit history)
Link to comment
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...