israelmekomou@gmail. Posted December 4, 2018 Share Posted December 4, 2018 Hi, I'm new in prestashop and i am creating a module that manage the shipping cost depending on the shippind day chosed by the customer and i want to save the date in a session variable. I've tried using cookies but i dont realy know if i use it wrongly but it's not working. Link to comment Share on other sites More sharing options...
Rolige Posted December 4, 2018 Share Posted December 4, 2018 Hello: Post here you code so we can help you. You can use cookies without problem: Context::getContext()->cookie->your_var = 'some value'; Regards Link to comment Share on other sites More sharing options...
Kogkalidis Posted February 8, 2020 Share Posted February 8, 2020 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. 1 Link to comment Share on other sites More sharing options...
Weeby Posted April 17, 2020 Share Posted April 17, 2020 Hi @tapanda.gr What about if I need to use $choice in tpl ? Thanks. Link to comment Share on other sites More sharing options...
Kogkalidis Posted April 17, 2020 Share Posted April 17, 2020 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 More sharing options...
arvistar Posted January 5, 2023 Share Posted January 5, 2023 $this->_getSession()->unset('yourVariableName'); Is this method good? Is there some other way to disable sessions? Link to comment Share on other sites More sharing options...
arvistar Posted January 5, 2023 Share Posted January 5, 2023 "unset" doesn't work. Correct solution: "remove" $this->_getSession()->remove('yourVariableName'); Link to comment Share on other sites More sharing options...
joonsmith Posted January 5, 2023 Share Posted January 5, 2023 Same. I'm new here as well thus focusing on sportsurge Link to comment Share on other sites More sharing options...
Titi2 Posted May 19, 2023 Share Posted May 19, 2023 (edited) 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 May 19, 2023 by Titi2 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now