Prestashop session and cookies

Today we talk about how to use Prestashop session and cookies. The first thing you must know Prestashop did not use the session it is using the cookie for storing the data So let talk about the cookies. In this tutorial, we focus on set cookies, get cookies, and unset the cookies. So let’s start it.

You can get the cookie variable by following.

in the Controller file.

 $cookieObject = $this->context->cookie;

Other files

 $cookieObject = Context::getContext()->cookie;

Set Cookies

     $context->cookie->__set('simplaedata', 'abc');

To store an array in cookies you need to serialize data. an example is below.

     $array = array('a','b','c');
     $context->cookie->__set('simplaedata', serialize($array));

Get Cookies

    $context->cookie->simplaedata;

UnSet Cookies

   $context->cookie->__unset('simplaedata');

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply

Recent Blogs

Categories