Ubercart Ajax Cart (Authcache)

Contrib type: 
Module
Status: 
Initial upload
Moderation: 
Not ready for moderation

Downloads

Compatibility: 
Ubercart 2.x

=======================
Summary
=======================

This is a wrapper for the Ubercart Ajax Cart block, for use with the Authcache module.
Using this module you can have full page caching for authenticated users while still
providing them with a dynamic cart block.

WARNING: MAKE SURE YOU READ THE INSTALLATION INSTRUCTIONS!

============
Requirements
============

The following modules are required.

Ubercart:
http://drupal.org/project/ubercart

Authcache:
http://drupal.org/project/authcache

Ubercart Ajax Cart (optional):
http://drupal.org/project/uc_ajax_cart
Note: This has not been tested with the 2.x version.

============
Installation
============

1) Install and enable like any other module.
2) If you do not already have a authcache_custom.php in your authcache/ajax
folder, copy the authcache_custom.php from this module's folder into your
authcache/ajax folder.
-- OR --
If you already have a authcache_custom.php in your authcache/ajax folder,
edit that file and add the contents of this module's authcache_custom.php
to it.
3) Visit Site Configuration -> Blocks. Disable the "Ubercart ajax shopping
cart" block and enable the "Ubercart ajax shopping cart (Authcache) block.

=============
Configuration
=============

This module uses exactly the same configuration settings as the "Ubercart
ajax shopping cart" block.

======
Author
======

Author/maintainer:
Adam Overlock (adamo)
http://drupal.org/user/220401
http://adamo.org

This project has been sponsored by:
Lie-Nielsen Toolworks
Makers of heirloom quality tools.
http://www.lie-nielsen.com

This module is based on the Authcache Example module included with the
Authcache module, developed and maintained by Jonah Ellison.
http://drupal.org/project/authcache

PreviewAttachmentSize
uc_ajax_cart_authcache.zip4.32 KB
adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Re: Ubercart Ajax Cart (Authcache)

Argh, looks like I didn't get the file attached last time. It's there now.

Also, currently you must apply a patch to Authcache before this module will work (otherwise the JSON it returns will get corrupted): http://drupal.org/node/603700#comment-2180122

Finally, in this version of the module anonymous users will be served a dynamic cart as well. You must have Authcache set up to handle caching for anonymous users or you will end up with cart contents getting cached for anonymous users. Consider this experimental alpha code.

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Future plans: * Support for

Future plans:
* Invalidate browser cache of AJAX block when cart is updated via cart page.
* Support for standard UC Cart.
* Show "Loading..." with spinner when waiting for AJAX request to complete.
* Serve static cart to anonymous users if standard caching (not Authcache) is enabled for anon users.
* Degrade gracefully when Javascript is not enabled.

Riki's picture
Offline
Joined: 01/10/2009
Juice: 196
Re: Ubercart Ajax Cart (Authcache)

I doubt this would work with the module "Boost" but could it be?

- Riki Babington
www.eat3d.com
Feed Your Brain!

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Re: Re: Ubercart Ajax Cart (Authcache)

I've heard talk that Boost and Authcache can be used simultaneously, and if that's the case, then this should work with Boost assuming you are also using Authcache. I don't use Boost so I can't say. This module requires Authcache though. Authcache does support Cache Router which can do file based caching (and more), which as I understand it is what Boost does.

Riki's picture
Offline
Joined: 01/10/2009
Juice: 196
Re: Re: Re: Ubercart Ajax Cart (Authcache)

Thanks for the response, Ill do some more testing with what you suggested.

- Riki Babington
www.eat3d.com
Feed Your Brain!

douglas.a.hatch's picture
Offline
Joined: 07/31/2009
Juice: 64
Not working for me

Neat module--I've been looking for something like this for a long time. Unfortunately, I installed this module and applied the patch, but it doesn't seem to work for me. When the user clicks the 'add-to-cart' button, it just hangs. No ajax updates are made to the cart. It appears that in some cases the product is getting added to the cart (i.e. I click on Checkout and the product is there). Other times, the product doesn't get added. I've got a sandbox set up where you can see what I mean:

Chunky Bling Sandbox

Just click on the ADD TO BAG button and you'll see what I mean. Any suggestions are appreciated. Thanks!

asak@drupal.org's picture
Offline
Joined: 10/23/2008
Juice: 67
Thanks for the hard work!

I do seem to have an issue with this module - after adding to cart, the wrong cart shows up, including the wrong items. If i refresh the page, the correct cart is shown.

Looking in FireBug, i see this:

POST http://demo.com/uc_out_of_stock/query 200 OK
GET http://demo.com/?uc_ajax_cart_authcache=null&max_age=3600 200 OK
// And every time i click "add to cart" again i get:
POST http://demo.com/uc_ajax_cart/add/item 200 OK
GET http://demo.com/uc_ajax_cart/message 200 OK
GET http://demo.com/uc_ajax_cart/show         304 Not Modified

The first time the cart is called, using "uc_ajax_cart_authcach", the correct content is showed. when "uc_ajax_cart/show" is called - the wrong content appears. why does it say "304 NOT MODIFIED"? it should realize it has been modified... Eye-wink

The response for "uc_ajax_cart_authcache" looks like:
{"uc_ajax_cart_authcache":"<div id=\"ajaxCartUpdate\"><div id=\"cart-block-contents-ajax\">\n<table class=\"cart-block-items\">\n\t<thead>\n\t\t<tr><th colspan=\"4\">\u05de\u05d5\u05e6\u05e8\u05d9\u05dd<\/th><\/tr>\n\t<\/thead>\n\t<tbody>\n\t\t\t<tr class=\"odd\">\n\t\t\t<td class=\"cart-block-item-qty\">45x<\/td>\n\t\t\t<td class=\"cart-block-...>

While the "uc_ajax_cart/show" response starts like this:

<div id="cart-block-contents-ajax">
<table class="cart-block-items">
<thead>
<tr><th colspan="4"

This is from the bottom of the source:

<!-- Authcache Footer JSON -->
<script language="JavaScript">
var authcacheFooter = { "info": { "page_render": 1232.8, "page_queries": "497 queries @ 134.81 ms (11%)", "cache_render": "-1", "cache_uid": 0, "cache_inc": "memcache.inc", "cache_time": 1259420781, "node_author": "xxx" }, "ajax": { "q": "node/114" } };
</script>

And this is the info from the debugger:

Authcache.infopage_render: "1232.8 ms"
page_queries: "497 queries @ 134.81 ms (11%)"
cache_render: "First_Page_Request"
cache_uid: 0
cache_inc: "memcache.inc"
cache_time: 1259420781
node_author: "xxx"
(page_age): "8 seconds"
Disable caching for this browser session
HTML/JavaScript time: 1923 ms Ajax request not sent.
HTML/JavaScript time: 1946 ms

So i'm thinking (and my knowledge regarding authcache is limited) - could it be that instead of "uc_ajax_cart/show" the script should call "uc_ajax_cart_authcach" again? does it work that way?

Using the "remove" link in the cart has th same output - it changes the cart, but doesn't return the correct display.

I'm puzzled - any insights highly appreciated, thanks !

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Re: Thanks for the hard work!

Which version of uc_ajax_cart are you using? I haven't tested with the 2.x version yet. I believe they were going to be adding this kind of functionality to uc_ajax_cart itself... Not sure what the status of that is or whether or not it will work with this module or if this module will even be necessary if they have done that.

The block contents get cached by the browser. When the cart is updated the browser cache must be invalidated in order for it to get the current contents of the cart. I just got done fixing a bug where the browser cache was not being invalidated if the cart was updated via the cart page (stupid oversight on my part). Adding items to the cart has always worked properly for me though. I'm going to upload a new version shortly where this bug is fixed and I have also added support for the standard uc_cart block.

You say you are seeing the "wrong" cart when adding items though. Are you just not seeing the last item you added, or are you seeing a completely different cart (belonging to another user)? Are you talking about the contents of the cart block, or the contents of the cart page? Adding items has been working properly for me since before I posted this module, and you should never ever see someone else's cart. Let me know what version of uc_ajax_cart you're using. I'll test with the 2.x version when I have time, but so far it has not been tested at all.

The version I will be uploading shortly should work fine with the 1.x version of uc_ajax_cart or with the standard uc_cart block.

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Re: Not working for me

Looking at Firebug on your page, it's getting a 404 error trying to GET "http://chunkybling-sandbox.com/cart/ajax/update". You should be getting a bunch of JSON data back, not a 404. Not sure why that might be happening, but that sounds like more of an issue with the uc_ajax_cart module, or a misconfiguration of the site somewhere. Does the problem go away if you disable this module and just use the standard uc_ajax_cart instead? Which version of uc_ajax_cart are you using?

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
New version uploaded...

I just uploaded a new version.

New in this version:
* Invalidate browser cache of AJAX block when cart is updated via cart page.
* Support for standard UC Cart.

Future plans:
* Serve static cart to anonymous users if standard caching (not Authcache) is enabled for anon users.
* Degrade gracefully when Javascript is not enabled.
* Show "Loading..." with spinner when waiting for AJAX request to complete.
* Support for UC Upsell blocks.

l33roy's picture
Offline
Joined: 10/13/2009
Juice: 28
Very good module, but need working

Hello. I need this module for my 2 sites - nexwave.ru & whole-sale.ru
Hope you finish "Future plans", cos this is important for me.
Maybe you can advise me smth for my sites?
My page loading time is huge now and i need improve this.
Hope you finish this module, so it will be full drupal module Smiling

haggis's picture
Offline
Joined: 02/22/2009
Juice: 27
Re: Ubercart Ajax Cart (Authcache)

Is there any further development on this module? It looks as Ubercart Ajax Cart hasn't implemented this module/feature yet. So I'm trying to use this module (which I like even more since it provides the oldschool cart block).
However it's not working properly.

1st I had to modify the callback function in the .js file:

// Callback function from Ajax request
function _authcache_uc_ajax_cart_authcache(vars) {
  $("#block-uc_ajax_cart_authcache-0 .content").html(vars.content);
}

After some testing I decided to change max_age to 1 since I got the full cart shown after deleting all items from cart. Now the cart gets reloaded on everey page view.

Another problem is, that the block uses space in the sidebar even when it's empty. Maybe a little css can help here. However sometimes the cart block title (with the icon) is visible and sometimes not.

haggis's picture
Offline
Joined: 02/22/2009
Juice: 27
Re: Re: Ubercart Ajax Cart (Authcache)

To avoid visibility and space using of an emtpy cart block I modyfied the js-file. Now it looks like that:

// Callback function from Ajax request
function _authcache_uc_ajax_cart_authcache(vars) {
  $("#block-uc_ajax_cart_authcache-0 .content").html(vars.content);
}

function uc_ajax_cart_authcacheInit() {
  ajaxJson = {
    // The name of the function to call, both for ajax_authcache.php and
    // this file (see function above). The cookie value will change if
    // the user updates their block (used for max_age cache invalidation)
    'uc_ajax_cart_authcache' : $.cookie('uc_ajax_cart_authcache'),

    // Makes browser cache the Ajax response to help reduce server resources
    'max_age' : 1
  }
 
  // Perform independent Authcache ajax request
  Authcache.ajaxRequest(ajaxJson);
  if ($("#block-uc_ajax_cart_authcache-0 .content").html().length < 10) { // 10 because content may have a " &nbsp; " in it.
    var block = $("#block-uc_ajax_cart_authcache-0");
    block.css("display", "none");
    block.css("position", "absolute");
  }
}

jQuery(function() { uc_ajax_cart_authcacheInit(); })

However I've got still problems with the block title. You can reproduce it:

Requirements:
- hide cart if it's empty
- enable authcache for guests

1. empty all your cats
2. flush all caches
3. log out
4. add a product to your cart
-> the block is shown correctly on all pages
5. emtpy your cart
6. add a product again
-> on some pages your cart is displayed correctly on others not. The cart block is missing the <h2 class="title>...</h2> in it. Additionally it looks as there is no uc_cart.css file included.

You can see it when showing the cart even when it's empty: when something is in your cart on some pages you see the "full-cart" icon and on others the "empty-cart" one.

Hope I get some help on this. Thanks!

sittard's picture
Offline
Joined: 11/19/2010
Juice: 14
Minor Tweaks

Thanks for this great module. Attached is a revised version which does not require patching AuthCache (comment #1).

Any chance of releasing this on drupal.org?

AttachmentSize
uc_ajax_cart_authcache.zip 4.29 KB
Gynekolog's picture
Offline
Joined: 11/03/2010
Juice: 14
Re: Minor Tweaks

Title is not clickable now

veshiyi's picture
Offline
Joined: 04/09/2009
Juice: 25
problems =(

When I add the item to my cart, total number of products and the amount ( $ ) has not changed and only when I update (refresh ) page then the number of products increases.
How to make a number of products and the amount changed without reloading the page?

Ubercart 6.x-2.6 + Ubercart ajax cart 6.x-2.0 + authcache + uc_ajax_cart_authcache.zip (03/10/2011 - 05:14)

Pliz?