from /admin/build/block/configure/uc_cart/0

Block is still visible if cart is empty. If this option is checked, the cart block should not load if empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plousia’s picture

Yeah, I'm running into this issue too. I got called in to fix this problem in a site which is running this version of Ubercart. Even though the "hide block if cart is empty" option is checked, when you go to the cart settings in store configuration (admin/store/settings/cart), it says "Cart block is shown when empty." The empty block is not shown to logged-in users, only to anonymous users.

Island Usurper’s picture

Status: Active » Needs review
FileSize
736 bytes

The Cart settings overview is just using the wrong variable name for the cart visibility message. That's easily fixed with the attached patch.

Do you have page caching turned on? That's the only way I can find that keeps the block visible when the setting is turned on. I kind of feel like that's the way it should work since the whole point of caching is to serve the same content to as many people as possible.

Island Usurper’s picture

Status: Needs review » Postponed (maintainer needs more info)

I committed the patch, since it's just a display issue.

butler360’s picture

So there's no way to make this work with page caching enabled?

keva’s picture

What does the patch fix?

Using Drupal 6.11 and RC2 with the patch, and the cart block still shows up for anonymous users.

These are checked in the block settings:

X Hide block if cart is empty.
X Display the shopping cart icon in the block title.
(no role specific visibility settings are checked).

escoles’s picture

I believe that this and http://drupal.org/node/377798 are almost duplicates.

I see the behavior described here, and on the site I'm concerned with the issues seems to be clearly w/ page caching. Turn off normal mode page caching, and the block will behave as expected.

Note that normal mode page caching seems to be sufficient. Neither block caching nor aggressive mode page caching are required to trigger this block visibility issue.

I would argue that this calls at least for clearer documentation on the Performance page of the compatibility issue. Currently, the warning states that uc_cart is not compatible with aggressive caching, when normal caching is sufficient.

josi123’s picture

Version: 6.x-2.0-rc2 » 6.x-2.2

I also can't get the "hide block if cart is empty" option working. Normal caching enabled. Anonymous users always sees empty cart.
I think normal caching is what most sites uses so why is this still a bug? Do we just stop using the cart block?

Island Usurper’s picture

Did you turn on that setting after you enabled page caching? Your users are probably still seeing the cached page.

josi123’s picture

#8 Yes. But the issue remains even after clearing all caches. Is there any way to get this thing working?

mautumn’s picture

Subscribing

JennySmith’s picture

I, too, am experiencing this bug with normal caching set.

Could this be fixed with some PHP code in the block configuration? I couldn't begin to write it myself, but perhaps there's a way to control the behavior of the block outside the ubercart code.

mr.andrey’s picture

subscribing... experiencing the same behavior

babbage’s picture

Same problem; definitely a bug.

Sounds like the argument is being made that the empty cart should be shown to people as it means cached pages can be shown to as many people as possible. That doesn't make any logical sense at all since a page without an empty Ubercart cart is obviously at least as easy to cache as a page that has an empty one.

mrandy’s picture

same here as well.

butler360’s picture

Nice spam from nan-dini. I'm setting the title back to what it was.

babbage’s picture

Status: Postponed (maintainer needs more info) » Active
jpstokes’s picture

I'm also experiencing the same problem. I found that when you disable caching all together it works as expected. So it definitely has something to do with the caching. Hopefully the maintainer comes out with a fix for this.

johnflower’s picture

I'm in the same boat. Hide the block if the cart is empty, PLEASE!

echoz’s picture

+1 for being able to hide cart if empty for anonymous users, with page caching on.

jpstokes’s picture

Title: Shopping cart block settings > Hide block if cart is empty. » Hide block if cart is empty.
petey318’s picture

Subscribing

toddgee’s picture

subscribing on a Summer day in Spring. Nature's April Fools Day joke on Chicago.

Fienix’s picture

Subscribing

marcushenningsen’s picture

I can confirm that disabling caching makes it work.

Marcus

jsenich’s picture

Me too. Works if caching is disabled. Does anybody have a quick fix for this?

josi123’s picture

No fix after all this time... too bad, one of the reasons why I removed ubercart module

royerd’s picture

Surely this will get fixed . . . ?

We don't want anonymous users seeing an empty shopping cart. We want the anon user to be treated just like the authenticated user: if the cart is empty, hide it; if the cart has items, show it. Otherwise, what's the point of "hide shopping cart if empty"?

Dan

TR’s picture

We want the anon user to be treated just like the authenticated user ...

... which is the fundamental problem, because DRUPAL page caching does NOT treat anonymous users the same as authenticated users. If you want to treat anonymous users the same as authenticated users in DRUPAL you need to turn off page caching. Period. Page caching is done only for anonymous users (pages presented to authenticated users are not cached) and with page caching on DRUPAL treats all anonymous users as if they were one, and will show them all the exact same page.

royerd’s picture

Ah, I see. Makes sense.

freixas’s picture

It seems as though this bug should be closed—as far as I can tell, there is no bug (as explained by TR in #31).

If page caching is enabled, the block content is different. It always says "View your cart" regardless of whether the cart is empty or not. This is a appears to be a deliberate design decision since it's the best you can do with page caching enabled.

As TR said, if you want anonymous users to view the cart just like authorized users, turn off page caching.

In my case, I have redundant "View cart" and "Checkout" buttons on every page, so I added the following PHP code to the "Page specific visibility settings":

return user_is_logged_in();

If you are not logged in, the block will not display. You will need to use the redundant "View cart" or "Checkout" buttons. If you are logged in and the cart is empty, the block will not display. If you have items in your cart, it will.

butler360’s picture

Has anyone tried this?: http://drupal.org/project/ajaxblocks

I might when I get some time later.

mikesir87’s picture

Not sure if this anyone wants to use it, but this works as well... paste this into the block display settings, using the PHP option...

<?php
  if (uc_cart_get_total_qty() == 0) return false;
  return true;
?>
escoles’s picture

To be clear, the only way this is not a bug is if the block feature is designed explicitly to work this way.

Put another way: Unless the documentation clearly states that this block does not honor block caching, then this is a bug.

If the block does not honor block caching, and that's not documented, this is a bug.

johnflower’s picture

*bump*

Starminder’s picture

subscribe
#35 works great, except you have to refresh the page to make the cart visible.

torgosPizza’s picture

Have you tried the patch available here? #886148: Empty shopping cart block visible to anonymous users

allanp’s picture

Has anyone been able to hide an empty cart for anonymous users without disabling normal caching?

interestingaftermath’s picture

Has anyone been able to hide an empty cart for anonymous users without disabling normal caching?

subscribing because I would also like to know an answer.

torgosPizza’s picture

Have either of you tried the patch I linked to in #39?

To clarify, that patch seems to work with Block caching disabled, but it appears to still work without disabling the regular caching. I don't believe there's any workaround, at this time, to show the right block with block caching enabled, unless you're using Ajaxify Regions or some other method of showing the cart block via Ajax.

allanp’s picture

@torgosPizza: Finally able to get the patch you referenced in #39 to work.
Thank you for pointing out the other thread.

torgosPizza’s picture

@allanp: Glad to hear it! Did you have to do anything special to get it to work? Please let us know, so others in the thread can benefit :)

longwave’s picture

So, what can we do to fix this? There seem to be two options:

  • Hide the block for anonymous users if caching is enabled.
  • Document the fact the block is not hidden if caching is enabled.

The first one changes existing behaviour, which may not be required for all sites. But the second means the option actually does what it says... comments welcome, and whichever one gains consensus I will try to roll a patch for.

TR’s picture

A third option would be to make the cart block content always load via Ajax, to avoid the caching issue altogether? If "hide block if empty" were checked, the script making the Ajax request would hide the block based on the server's response.

longwave’s picture

Possible approach to the anonymous cache issue: http://drupal.org/node/875152

jnettik’s picture

Subscribe

jlancaster’s picture

Same problem. Since this used to work, this seems more like a bug to me!

BTW, mikesir87's code above works for hiding it in the block display settings.

haggins’s picture

subscribing

Gaperville’s picture

Version: 6.x-2.2 » 7.x-3.0-rc2
Assigned: Unassigned »

Patch didn't work using D7.8 w/ Uber 7.x3.0-rc2.

Weird how this issue is still going on after all these years!

Cache is disabled too. After clearing the cache i get an error message form the patch of:

Parse error: syntax error, unexpected T_IS_IDENTICAL in /sites/all/modules/ubercart/uc_attribute/uc_attribute.admin.inc on line 1354

TR’s picture

Version: 7.x-3.0-rc2 » 6.x-2.x-dev
Assigned: » Unassigned

Of course the patch didn't work with UC 7.x-3.x, this is a Drupal 6 issue and patch.

butler360’s picture

Uh...

Anyways, he did not close the issue, just returned it to how it was before you changed it. No one knows the solution, otherwise this would be marked as fixed.

I would recommend against language and behavior like that unless you want to be banned.

longwave’s picture

Gaperville's abusive comments aside, this should be fixed in 7.x-3.x-dev by #1285818: Remove uc_cart_exit() and cache-safe cart block - unfortunately the same approach does not apply in Drupal 6, so this issue remains open.

Gaperville’s picture

Yes Sir!!!! Thanks for the Love and Support!

longwave’s picture

Status: Active » Needs review

Attached patch adds help text as follows to the checkbox, explaining the current behaviour:

This does not apply to anonymous users if page caching is enabled, as the same cached page will be served to all anonymous users whether or not they have items in their cart.

I think this is the only way to solve this without an Ajax cart. When page caching is enabled, Drupal serves the same page to all anonymous users whether or not they have items in their cart. For consistency we should show the same "Click to show cart contents" block here, otherwise the block may randomly appear and disappear between pages, depending on if the first viewer of the page has items in their cart or not. There is no way around this with page caching enabled.

longwave’s picture

longwave’s picture

Status: Needs review » Fixed

Committed #59. As explained above I don't see any other option here except an Ajax cart.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.