Thanks for this module! I'm testing for the issue where the ubercart cart block can't show dynamic changes (hide if empty) to anonymous users with page caching on. It works as expected with block, css + js caching enabled, but does not work with page cache set to "Normal", only when that is set to "Disabled". Any combination including page caching results in the cart block always showing, but without it's contents, just it's header + a link to the cart. By the description, it seems it's expected to work with page caching (first setting on performance page) set to "Normal". I'm trying to determine if this is this a bug or something unique to my installation.
Comments
Comment #1
maximpodorov commentedUnfortunately, Ubercart must be patched for this (I plan to provide the patch to Ubercart maintainers). Cart block must know whether page caching is turned on. For now, it performs this check (line 406 of uc_cart.module):
$cachable = !$user->uid && variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED;You can add the following line:
if ((module_exists('ajaxblocks')) && (ajaxblocks_in_ajax_handler())) $cachable = FALSE;Hope it'll help.
Comment #2
echoz commentedGreat, thanks, I'll test this tonight and report back. Is this new line to be added directly after that line 406, or after the following 2 lines in the existing if clause, just before the next if on line 412.
Comment #3
echoz commentedAdding that line directly after line 406 (quoted above) made no difference, in that I can enable any caching on the performance page except page caching, and I can do the same with Ajax Blocks uninstalled.
I can't tell if enabling just block caching makes a difference since I'm testing locally, but that's what I primarily want cached, and for anonymous users, so I'm going to test that on the live site when updated.
Comment #4
maximpodorov commentedWith the following fragment of uc_cart.module:
and normal caching mode and block caching everything works as expected for me. Did you set the setting 'Load block via AJAX' to 'yes' for the cart block?
Checking $_SERVER['REQUEST_METHOD'] == 'POST' is not quite correct, but you can use it now.
Comment #5
echoz commentedNope, same result. With page cache set to normal, empty cart is visible for anon user with cart block's setting checked "Hide block if cart is empty". I'm going to just use block caching, and watch for your progress successfully patching uc_cart.module.
Comment #6
miraclegr commentedI'm having the same problem. Although I have other blocks working fine (a mini cart block showing only the cart total), the cart block is not showing anything for the anonymous.
Page cache set to normal, block caching enabled and cart block setting for "Load block via AJAX" set to YES.
I've also tried to use the cache excludes module to exclude all ajax* urls, but with no luck again.
Finally I've also tried to use this module with boost, but then it doesn't seem to do anything of its magick. The blocks are been displayed (and cached) directly on the page. Is it compatible with boost?
*** EDIT ***
The first issue seems to be corrected after some custom javascript incompatibility has been corrected.
And just figured out how to make this work with boost.
On Boost settings page, the "Boost - Static page cache:" must be on "(Not Recommended) Set Boost & Core (if enabled) cache for each page".
Comment #7
maximpodorov commented@miraclegr, could you clarify your situation? Do you use unpatched (by patch in comment #4) Ubercart?
If you need just simple cart block, I can suggest http://drupal.org/project/uc_microcart module which works fine with ajaxblocks.
And, as much more complicated solution, http://drupal.org/project/uc_ajax_cart may be used. It really loads cart block via ajax when anonymous caching is on (you don't need ajaxblocks for this). I have working example here: http://www.igrushkispb.ru
I didn't try ajaxblocks with Boost. Do you think it's actual combination, and the solution should be documented in README of ajaxblocks?
Comment #8
miraclegr commentedI'm using patched version of ubercart. Haven't tried it without the patch though to be honest.
The problem I had was not with the modules I use, but some custom javascript that has been fixed now.
We have a microcart (custom code in block) and a normal cart block that displays when the user hovers on microcart. So they can see the contents of the cart without going to a different page.
The ajax cart was not chosen because, while it provides a nice working solution, I didn't want the Add to cart button to work with ajax. The reason is that some usability tests that we've done, showed us that the users (most of them) got confused with all these messages or didn't noticed them at all. They ended up adding more than once the product in the cart or just got frustrated and left.
Overall, because we use the ajaxblock for the microcart block, it is much better from the performance perspective to have all ajax blocks loaded with one call.
So the only workaround for us was to have the microcart and cart block loaded with ajax for anonymous users and keep the original add to cart functionality.
As for the Boost module, I can confirm that with the settings described earlier, it works fine. If you don't enable the core caching, the ajaxblocks module don't work at all.
I also have the authcache module installed, so new customers that complete the checkout process, get logged in and still get cached content (but without the ajax blocks this time).
I think that the part that needs to be in documentation is the settings you need (for different scenarios) so that users can get to work as expected very quickly.
Hope this helps
Thanks for the good work
Comment #9
maximpodorov commented@echoz, sorry, I didn't understand your situation.
Ajax Blocks can't work when "Hide block if cart is empty" is checked. If some block's content is empty, there will be no attempt to load it's context via AJAX afterwards. It's Drupal core (block.module) that makes this:
So, no further processing is possible for empty blocks.
Comment #10
andyf commented@maximpodorov I used your code snippet in #1 and it fixed my problem. Did you ever submit it to the UC maintainers?
Comment #11
maximpodorov commented@AndyF
No, the problem is more deep. I need some time to prepare a patch for Ubercart which will make it work without Ajaxblocks module (see #911052: Solution for AJAX loading of the cart).
Comment #12
andyf commentedUnderstood, thanks.
Comment #13
jose reyero commentedJust in case anyone wants the ubercart shopping cart with ajaxblocks, you can use this (real dirty) trick on top of the patch above.
1. Create a block template that just prints the block content for the shoping cart:
block-uc_cart-0.tpl.php
2. Tweak the theming functions for the shopping cart so they print the full block and some non printable stuff when the cart is empty:
Have fun!
Comment #14
seagle commentedOutstanding, suggestion #1 worked for me in D7, Ubercart 7.x-3.0-beta3, although the line # was different. I placed it after line #342 (in uc_cart.module)as follows:
Thank yo so much Max!