Wednesday 2 June 2021

Put Cookie in prestashop 1.5 and 1.6

 Today I will show you how can you simple set and get your custom cookie variable.

It is useful when you want to keep locally on user’s PC some settings.

Setting cookie

$this->context->cookie->__set('your_cookie_name', 'your cookie value');
$this->context->cookie->write();

Getting cookie

$this->context->cookie->__get('your_cookie_name');

Check if cookie exists

$this->context->cookie->__isset('your_cookie_name');

Deleting cookie

$this->context->cookie->__unset('your_cookie_name');

Final words

Remember – if you don’t have access to $this->context, you can replace it with Context::getContext().

That’s all – as simple as that!


Reference Tutorial

https://prestacraft.com/tutorials/

No comments:

Post a Comment