Jump to content

[PS8.1.3] Token is cached in homepage: add to cart AJAX don't work


Recommended Posts

Hello everybody :D
I encountered an awkward problem!
Scenario:

  1. I enter to homepage of my shop (https://www.grelaparfum.it/) in incognito mode. I have several products in home page: new products block, featured products block etc. I try to add to cart any product and it is added to cart (via ajax). Works like a charme.
  2. At this moment, I login into my site. Return in home page... and all "add to cart buttons" stop working. I don't have any console errors or any errors in general. Simply, I click on button and after 2/3 seconds, the button clicked (went in disabled state) comes back to normal. As i never clicked it. And nothing happen. 
  3. I go to an any category page, click on add to cart and it works.
  4. At this point, I clear the cache: the buttons in home page work again. 

 

So, after several code inspections, i noticed that while in category page the "add_to_cart_url" had a token, in homepage the buttons had a different token (i got output both $token and $static_token). 
If i use the token used by buttons in category page in home page add to cart button, it works. When i clear cache, tokens in homepage come update... and works.

 

Is the "add_to_cart_url" in cache maybe? And this happens with native and custom modules. How can prevent caching of add_to_cart_url?


[EDIT] Another awkward fact is that on the developer site (a subdomain), the problem is not happens. I copy from dev subdomain to main domain. Did I forget to do something? 












 

Edited by MadMar (see edit history)
Link to comment
Share on other sites

I apologize:

Linux #1 SMP PREEMPT_DYNAMIC Debian 6.1.67-1 (2023-12-12) x86_64
Server software version: nginx/1.24.0
PHP version: 8.2.14
MySQL version: 10.11.4-MariaDB-1~deb12u1
PrestaShop version: 8.1.3

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...