Hi,
I've installed authcache following the steps described here: Tutorial: Commerce Kickstart 2 and Authcache 2.
I've also followed this and removed tokens for commerce_cart_add_to_cart_form_*, and restricted this only to unprivileged authenticated users.
Everything seems to work fine for anonymous users, but caching for authenticated users on pages with forms (add to cart forms with ajax) don't work. If the add to cart form token is not removed, there's no caching. If it is removed, the page is cached but add to cart works only for the initial user (the user that generated the page cache). I.e, if user_A accessed a certain page and then user_B, user_A will be able to add to the cart but user_B won't.
Any idea what might cause this?
Thanks,
Dana
Comment | File | Size | Author |
---|---|---|---|
#18 | interdiff.txt | 687 bytes | znerol |
#18 | ajax_add_to_cart_works-2475503-18.patch | 9.08 KB | znerol |
#18 | ajax_add_to_cart_works-2475503-18-TEST-ONLY.patch | 7.23 KB | znerol |
#17 | ajax_add_to_cart_works-2475503-17-TEST-ONLY.patch | 7.16 KB | znerol |
#17 | ajax_add_to_cart_works-2475503-17.patch | 9.01 KB | znerol |
Comments
Comment #1
znerol CreditAttribution: znerol commentedThanks for the report. Did you also install and configure the Cache Object API module? Since beta3 this is required to make Ajax forms work for authenticated users.
I realize that the documentation is lacking in this regard.
Comment #2
gdana CreditAttribution: gdana commentedNot before posting this but after working with the authcache debugger at some point a message about cache object appeared so yes, I installed it and it looks like it solved the issue (need to test it a little more to be sure).
You really should add this step to the documentation, this is such a great module... :)
Another small question: if add to cart is an Ajax form, am I right that there's no need to add it to the list of forms of which tokens should be removed as it is cached any way?
Thanks again,
Dana
Comment #3
znerol CreditAttribution: znerol commentedForm Tokens are used to prevent CSRF attacks. As of version beta4 it is not necessary anymore to remove the form token from the add to cart form, due to #2352239: Use base form id for tokens in order to minimize ajax requests on repeated forms (e.g. commerce add-to-cart).
Form Build IDs are used to reference form cache entries and are required for Ajax forms.
So those two things are in fact very different.
Comment #4
gdana CreditAttribution: gdana commentedHello again,
OK, I think I understand the difference between tokens and build ids.
However, I'm still encountering serious problems with the add to cart forms. The problem now is different and there is a very strange behaviour when adding to cart by an authenticated user: again, assuming there are two users, user_A and user_B. if user_A created the cached page, and user_B adds to his cart from the same page, the first time user_B adds to his cart, it doesn't perform correctly and the product is added to the cart of user_A. After that, adding to the cart performs as expected for that specific add to cart form (i.e., adding the same product a second time works).
This is the message in the debug window:
Status
Cache Status: "HIT"
Speedup: "104,787% increase"
Page Render Time: "9712.52 ms"
Cache Render Time: "9.26 ms"
Page Age: "51 seconds"
Settings
Cache Class: "DrupalDatabaseCache"
Cache CID: "6a905a2/sunday"
Debug Users: [""]
Cache User: "258"
Cache Backends: "authcache_builtin"
Active Backend: "authcache_builtin"
Authcache Key: "6a905a2"
Key props: {"base_root":"example.com","roles":[2],"ajax":true}
P13n Clients: "Ajax"
Active P13n Clients: "Ajax"
Do you know what could possibly be the problem now?
Thanks a lot, again.
Dana
Comment #5
znerol CreditAttribution: znerol commentedI tried to reproduce this with my Commerce Kickstart + Authcache sandbox to no avail. (Use
./scripts/build.sh /path/to/destination/directory
to build the distribution).Please check the following things on your setup:
Comment #6
gdana CreditAttribution: gdana commentedIt's 7.36, and no, there are no JavaScript errors when this happens. When adding a product for the first time if the page was cached by another user, the Ajax responds and displays a message that the product was added (and it was, just not to the right user...). After the first addition, it works. So strange.
Regarding reporoducing the problem - I'm sorry, I should have pointed out that It's not Commerce Kickstart. It's a Drupal Commerce website that's been working properly for almost 2 years, except for the fact that certain pages are extremely slow (views with many products and add to cart forms), which is why we are trying to implement Authcache.
Obviously, this is not tested on the live site. We've installed the latest Drupal distribution (7.36) and imported the entire site, and then followed the steps in the tutorial (with a few small additions):
I really don't know what to think, it worked so well after adding the Cache Object module but then stopped, after some (seemingly) unrelated changes made to the site and the server. Is there some kind of logging I could add that would clarify things a little?
Thanks, your help is very much appreciated.
Comment #7
znerol CreditAttribution: znerol commentedThere was a similar issue some time ago with the comments form: #2307555: Comments intermittently misattributed.
Could you describe a bit how you add-to-cart form is configured? Are there any additional modules involved which might alter/extend that form? Do you use custom line items?
Comment #8
gdana CreditAttribution: gdana commentedHi,
Yes, there are a few modules altering and extending.
The first is Commerce Cart Ajax, and the other is this code (custom module copied from here):
Other than that, we're not using custom line items (assuming you mean this).
Thanks,
Dana
Comment #9
gdana CreditAttribution: gdana commentedOne more thing: correct me if I'm wrong but if I recall the code correctly when this did work, and if I understand your explanation about the form token using the form build id, shouldn't the form html include a token with the build id?
This is the current code:
Comment #10
znerol CreditAttribution: znerol commentedI think this is actually a bug, in fact I believe it is very similar to the one I've linked in #7. It looks like commerce cart does the same thing like the comment module, i.e. store a reference to the user in a
value
field (see commerce_cart_add_to_cart_form()). That gets serialized into the form state on Ajax enabled forms (i.e. form caching is on). That cached form / form state combination will then be duplicated and reused for other users, but theuid
will remain the same.Comment #11
znerol CreditAttribution: znerol commentedAttached is a module which I've extracted from Authcache Comment and adapted to the commerce cart case.
I'll follow up with a proper patch + test cases as soon as time permits.
Comment #12
gdana CreditAttribution: gdana commentedHey,
Great, the first few tests I've done look good and it seems the module solves the issue. Obviously will have to test it a lot more.
Thanks a lot for this and for your fantastic support and very quick responses.
Have a nice weekend...
Dana
Comment #14
znerol CreditAttribution: znerol commentedCommitted an initial skeleton of the new module. This is in order to make the test-bot pull in the new dependencies (commerce). This commit does not yet contain the necessary fix.
Comment #16
znerol CreditAttribution: znerol commentedThe module as a patch. Still needs tests, but they are currently blocked on #2481289: Prevent that cache/Ajax enabled forms with value elements are cached by default.
Comment #17
znerol CreditAttribution: znerol commentedAdd tests.
Comment #18
znerol CreditAttribution: znerol commentedFix test. We need a cardinality > 1 in order to trigger attributes (Ajax) on the add-to-cart form.
Comment #21
znerol CreditAttribution: znerol commentedMany thanks @gdana for taking the time to report this issue.
Comment #22
znerol CreditAttribution: znerol commentedComment #23
gdana CreditAttribution: gdana commentedCan you please explain the exact procedure because the patching fails when installing the initial module (in #11) and then applying the patch.
Thanks,
Dana
Comment #24
znerol CreditAttribution: znerol commentedThe fix is included in the latest
dev
version. Please use that for testing purposes. I'm preparing to release another beta next week.