There is an annoying bug in Ubercart that causes the anonymous user to see an empty shopping cart. It does not respect the configs in UC (ie "Cart is hidden when empty", see first attachment) and the cart cannot be tweaked for custom visibility in the block settings without a lot of custom PHP. I have to call this a bug since checking the settings in UC configs should produce the result it's advertising, and it does not.

It's been more than a year since this very tiny, very successful patch was pitched for the uc_cart.module and it still hasn't made it. It was part of the original thread but then apparently lost focus in a monster thread of mixed issues.

I've attached an updated patch for uc_cart.module in UC 6.x-2.4. Anyone looking for this fix in the future should know that there are only five characters added to make your annoying empty cart block disappear for your anonymous users.

No matter what your version, if you have this line of code in your uc_cart.module file:

$cachable = !$user->uid && variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED;

Then you can change it to:
$cachable = !$user->uid && variable_get('block_cache', CACHE_DISABLED) != CACHE_DISABLED;

That's a 'block_cache" instead of a "cache".

Here is the new patch, updated and reposted, free and clear of the other issues mixed up in that thread. The original patch was found here.

CommentFileSizeAuthor
uc_cart.module.patch551 bytesseaneffel
Picture 1.png10.31 KBseaneffel

Comments

torgospizza’s picture

To clarify, this seems to be an issue not related to "an empty cart" being shown to anonymous users at the cart page (http://example.com/cart). That is another issue; your patch seems to address only the cart block issue.

916Designs’s picture

Cart block is still showing to anonymous users after applying this patch, clearing browser cache/cookies and flushing all Drupal caches.

Applied patch to latest 6.x-2.x dev release. Also think the title of this bug report and text should clearly state "block".

It seems like this patch addresses the definition of whether or not the block is currently cachable (by looking at block rather than page cache settings). It does not address the case of showing or not showing the shopping cart block based on if the cart is empty or not empty.

seaneffel’s picture

Title: Empty shopping cart visible to anonymous users » Empty shopping cart block visible to anonymous users

Remember that there is a setting within the Cart module UI that allows the user to set the block to "Hide block if cart is empty." When that box is checked, an empty cart continues to display for anonymous users. You can disagree that this patch doesn't address the issue, but I'll maintain that it has done more for 10 of my sites than this other long winded issue has.

See the setting on your own site:
http://www.yoursite.com/admin/build/block/configure/uc_cart/0

Fixed the title as requested.

torgospizza’s picture

Right, I'm just saying there is a difference between an "empty cart" and an "empty cart block". If the block shows as empty when there are actually items in the cart, that's one thing. But if the cart never gets any products placed into it, that's closer to the other issue I was referring to.

For example I don't use a cart block on our site, so this issue doesn't apply to me as it's for the block and not the cart. That was the distinction I was trying to make. Thanks for editing the title :)

haggins’s picture

After this patch the cart is still displayed when block caching is enabled. With block caching disabled everything is fine.

biscuit.tech’s picture

Same as #5, works with block caching disabled.

tr’s picture

Status: Needs review » Needs work

@seaneffel: I really don't think it's been too helpful to separate out this issue from the context of the original #377798: Cart block always starts a session. It has been pointed out several times in that thread that 1) page caching is a *Drupal* mechanism applied to pages viewed by anonymous users, and the only way to ensure that different anonymous users see different page content is to turn off page caching or to implement some Ajax scheme where part of the page is loaded dynamically rather than from the cache, and 2) block caching has little effect when page caching is turned on because the cached blocks are used only to build the page that will be cached - once the page is cached the block cache is no longer used.

The *context* of that other thread is just as important for your "very tiny" patch as it is for all the other problems that arise from Drupal's caching mechanism. Ignoring that context means all this stuff is going to have to be repeated and rehashed here in another thread.

No patch to this issue can be considered tested until you've tested with multiple anonymous users accessing your site simultaneously from separate computers (or separate browsers, so they don't share a session). It's easy to "fix" an issue like this in a way that breaks something else and reinstates the "ghost cart" bug. Likewise, a test that fails to mention how caching was configured is useless.

Regardless, several people have now reported that the patch in this issue doesn't do what it's supposed to, so I'm moving this back to "needs work".

kruser’s picture

subscribing

j_byrd’s picture

subscribing

tuwebo’s picture

subscribing

longwave’s picture

Status: Needs work » Closed (duplicate)

This is not the right approach, and just masks the problem. Let's deal with this in #449122: Hide block if cart is empty. instead.

seaneffel’s picture

That other thread has been open for 1.5 years with no improvement. It would be nice if it were resolved but it can't seem to decide what the issue really is. At least this thread gives some site admins a patch that lets them put Ubercart to use.

Just saying.

tr’s picture

Version: 7.x-3.0-rc2 » 6.x-2.4
Status: Active » Closed (duplicate)

Resetting status.

sammyframson’s picture

Patch worked perfectly for me... I did have to disable block caching but for my project, it is a small site and this is the only real block being utilized. Thanks @seaneffel.