3 replies [Last post]
lindenlion's picture
Offline
Joined: 11/12/2008
Juice: 39
Was this information Helpful?

Are you familiar yet with this usability issue that caching and anonymous cart blocks don't play well together?!
http://www.ubercart.org/forum/support/15908/boost_module_and_shopping_ca...

After reading up on it for a while, I realized why it is so difficult: cached pages are static, that's why they can be cached. They are the same for anyone. If you build dynamic pages they are just not static anymore. There is that issue that partial caching is not really a feature of D6, but it's coming in D7 (I'm thinking of Pressflow)! Doesn't help Ubercart users though.

There is one solution which takes the Ubercart Ajax Cart Block, but that is not satisfactory for me. Firstly, because it doesn't play well with the Out Of Stock module, and secondly it doesn't make sense to me to make an ajax call on every page for the cart contents, as it is kinda just like sending two pages on every request of which one is even dynamic! Not acceptable to me, because I want true caching!

So at first it seems there is no real solution, and anonymous are left with a secretive cart block (which might say something like: please login to see your cart contents on every page). I'd rather have no cart block than a cart block that doesn't give the user any useful information...

But then I suddenly had an idea. All that I need is for anonymous users to see how many items they have in their cart, even if they are on a cached page. So all I need really is a cart counter, not a detailed inside view.

I'd really like to use Boost caching and this is the single piece of information that I don't want to be static (it's less bytes than a txt message!). I would actually love to have static boost-cached pages that simply grab the number of items in the anonymous user's cart from an individual mini-cache that is user-specific, stored in their browser, along with their identifier: a cookie!

Cookies can hold up to 4000 characters, so I'd imagine that somewhere in a cookie that drupal and/or ubercart is using, there would be some room for an additional 100 characters somewhere, right? What I am assuming is that boost-cached pages could potentially print a cookie-stored value in the pages they serve... Do you think I am wrong, please teach me, I want to learn more about cookies!

Then, in addition to boost-cached pages being able to read a cookie-stored value, this cookie would need to be written and updated somehow, like everytime a user adds something to the cart, the cart contents should be re-counted and re-set. The same is true when the cart contents get updated or even emptied. And Expiration should of course be equal to the anonymous cart content session in the database.

Does this sound like something you could do? I would be happy to pay you for it! Please post a quote of how much you'd like to get for it. You can get as many free hugs as you'd like on top of that! A contrib module for this would be grand! But I also don't mind to hack in the Ubercart code...

Kind Regards, Michael

mikeytown2's picture
Offline
Joined: 03/19/2010
Juice: 6
Re: Anonymous Cart Counter compatible with Boost (cookie?!)

Cookies can be accessed and set via javascript. So what I recommend doing is having a cookie store the product ID and the number of products. You would then have a javascript catalog that holds every product; containing product id, link to product page, description, and price; or what ever needs to be displayed in the cart for that product when viewing it. If you want zero drupal server interaction up until checkout then you need to pre-compute a lot of info and place it into the catalog OR have a folder that contains the javascript info for each product; have it get generated on access like imagecache. Have it flushed when that product is updated.

In short it can be done. I've never used ubercart before so I've had no reason to create a system like this. But if your wondering if this is possible, the answer is yes.

lindenlion's picture
Offline
Joined: 11/12/2008
Juice: 39
hmm

Hey thanks Mike !

That's actually much more complex solution than I imagined. Two concerns:
1) I do actually want to have server interaction before checkout, for adding products to carts, and making sure they are in stock etc... but once I have added something to my cart I still want to be able to browse around the shop on cached pages without being disconnected from my cart content status (total number of items, and total amount).
2) I want it to work even for users that have javascript disabled.

So I imagine, all the calculations when adding a product are done by drupal/ubercart, and the detailed cart contents for anonymous users are still in the database.

Additionally, every time the user interacts with his cart, the cookie cart counter is overwritten, regardless of whether javascript is enabled or not.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: hmm

The main issue is really "regardless of whether javascript is enabled or not." There's no way you can get around the javascript issue. It's been discussed at length both here and on drupal.org:

http://drupal.org/node/463602
http://drupal.org/node/886148
http://drupal.org/node/378266

In every instance, whenever there is a solution proposed, it always comes back to using Javascript - that's the only way you can still have any "dynamic" events happening on static cached pages when using Boost.

--
Help directly fund development: Donate via PayPal!