Prestashop 1.6 session / cookie with smarty

In my prestashop, a user (who is not a client or an administrator) can create a “side” account (this is not a prestashop account) to do something special on the site.

I created everything for this, but when the user connects, I cannot store data during the session.

I am looking for a way to save data, and the only thing I see is a smarty cookie. Great, but I can’t control the lifetime of this cookie. And I need this cookie to die when the user closes the browser.

So, I tried to complete the session, but I cannot get it to work, and I have not seen a way to make a cookie that does not last.

Does anyone have an idea to make a session like data or to handle the duration of a cookie?

thank

+4
source share
4 answers

You can use class CookieCore

//to write
$cookie = new Cookie('my_cookie'); //make your own cookie
$cookie->setExpire(time() + 20 * 60); // 20 minutes for example
$cookie->variable_name = 'hello';
$cookie->write();

//to read
$cookie = new Cookie('my_cookie');
echo $cookie->variable_name;
//hello
+6
source

I will add a UnLoCo message.

For people who are looking for cookies that die at the end of the session, just put

$cookie->setExpire(0);

NB, a cookie will die only when the browser is completely closed (I have an extension that allows the browser to open, so I, although there was an error)

And last, if you want to kill the cookie yourself

$cookie = new Cookie('my_cookie');
$cookie->variable_name = null;
$cookie->write();
+3
source

Prestashop 1.6.1.x

http://vblanch.com/get-the-contact-email-in-prestashop-shop-name-and-set-values-in-cookies/

cookie:

$this->context->cookie->__set('name_of_your_key', $your_value);

smarty (.tpl):

{$cookie->name_of_your_key}

PHP ( ):

$this->context->cookie->name_of_your_key

:

$context = Context::getContext();
$context->cookie->name_of_your_key;
0

SESSION Prestashop $_SESSION['VIEW'] .

0

All Articles