Search code examples
phpprestashopsmartyprestashop-1.6prestashop-1.7

Con't able to find cookie value in prestashop Context::getContext()->cookie but it is show in $_COOKIE?


I am creating a module in which I use third party Js. That JS create a cookie in browser. At backend I want to read that cookie by the help of prestashop cookie class (Context::getContext()->cookie / $this->context->cookie ) but unable to find that cookie value, If I use php default $_COOKIE it work fine.

Ex: My cookie key is xyz, and value is 123456abc. When I use print_r($_COOKIE) It print [xyz]= "123456abc"

But when I use prestashop Cookie It doesn't print anything.


Solution

  • This is because you are most likely writing to a cookie with different name or different domain/sub-domain.

    The PrestaShop admin cookie name is psAdmin whereas the front-end one is ps-s1.

    Using Google Chrome, press F12 and go to: Applications > Cookies > www.yourstore.com

    You should now see all the different cookie names and values, make sure you are writing in the correct one.

    An alternate solution can be to call your PrestaShop controller file directly from JS (using Ajax) to set the cookie value via PHP.