Why is the magento frontend cookie not set

Viewed 2562

I'm running on magento 1.9.2.2 and when using Internet Explorer and Edge browsers I can't add anything to my cart. I click the add to cart button, get redirected to the cart page but then the "Your cart is empty..." message is being displayed. Safari, Chrome, Firefox, all working fine. Is just only when using IE or Edge that I encounter this problem.

After discovering the problem I did some research and found out that only on the problematic browsers Magento is not setting the frontend cookie (that for as far as I know handles the user/frontend session).

I already changed my cookie settings in the backend, changed the cookie lifetime, added a path, changed my domain to with and without a leading dot, but nothing is working so far.

Does anybody know a solution or can tell me why this cookie is not being set in those particular browsers?

Thanks in advance!

2 Answers

So there are a few reasons why this is happening; I know because I'm dealing with something similar at the moment. The reason why you can't add items to the cart is due to the missing frontend cookie(s). The cookie isn't able to be stored on the browsers you mentioned, and most likely all of them here soon, because the samesite attribute needs to be set for the cookie with the secure attribute.

For my issue, I found that we were using an older version than 7.3 for PHP. Therefore, the method to include the cookie, doesn't support the use of samesite. I had to write a piece of JavaScript instead to insert the cookie for the ones I was missing. Something like this:

    document.cookie = urlparamCookie +"=" + callbackURL + ";expires=" + myDate 
                + ";domain=.website.com;path=/;SameSite=None; Secure";

But keep in mind that this doesn't really solve the issue either. The magento 1.9 framework uses a model in PHP to set the cookie as well. So you'll either have to upgrade to php 7.3 or greater, or use a database connection to create a session in the appropriate tables so that the rest of the site functions as it should.

Related