If an user with no cookies try to add a product to cart gets no errors and the product is not added to his cart.
This behavior is documented also in http://www.ubercart.org/issue/1426/warning_disabled_cookies.
Starting from #2946: Login fails and no warning is issued if cookies are not enabled and from the cookie check module, this patch implements a simple control and if the cookies are disabled shows an error message.
Attached are the patchs for both the HEAD and the 2.2 version.

Comments

peximo’s picture

Status: Active » Needs review
StatusFileSize
new1.06 KB
new1.07 KB

ops sorry.

tr’s picture

Status: Needs review » Needs work

The patch doesn't work when the product is added to the cart using a cart link. Try using hook_cart_item() instead of the form validation function.

gapa’s picture

I create this function in my module:

function uc_cookie_check_cart_item($op, &$item) {
  switch ($op) {
    case 'load':
      if (!$_COOKIE) {
        $domain = ini_get('session.cookie_domain') ? ini_get('session.cookie_domain') : $_SERVER['HTTP_HOST'];
        drupal_set_message(t('You should enable cookies.'), 'error',TRUE);
        print theme_status_messages('error');
      }
  }
}

Can anyone tell me how to display empty cart and put this message into cart page. At the moment I only get empty page with this message.

br,
gapa

tr’s picture

Try drupal_goto('cart'); instead of your print theme_status_message('error');

I'm not even sure you need the drupal_goto() - if you just let it exit instead of printing then you should be redirected to the cart page anyway I would think.

gapa’s picture

If I use drupal_goto() I get cart page, but I would also like to display this error message in this cart page. So I would like to combine cart page (empty) and this error message. Can this be done?

br,
Gapa

adamo’s picture

Subscribing.

adamo’s picture

Ultimately I think Ubercart needs to be patched to check for cookies when adding items to a cart, whether that is being done via an add to cart form, or a cart link.

For now on my own site I have worked around this by implementing theme_uc_empty_cart() in my themes template.php. Both the error message and empty cart page will be displayed doing it this way, and the code will only be executed once when the actual cart page is displayed. This is certainly not a good permanent solution but as a temporary fix it works fine for me. My function in template.php looks like this:

function mytheme_uc_empty_cart() {
  // Check for cookies and display error if missing.
  if (!$_COOKIE) {
    $domain = ltrim(ini_get('session.cookie_domain') ? ini_get('session.cookie_domain') : $_SERVER['HTTP_HOST'], '.');
    drupal_set_message(t('It seems your browser does not accept cookies. To be able to shop on this site, you need to accept cookies from the domain @domain.', array('@domain' => $domain)), 'error', FALSE);
  }

  return theme_uc_empty_cart();
}
tr’s picture

Does *Drupal* even work if cookies are disabled? I don't think so, and I recall a long-open issue asking for Drupal to check for cookies and present an informational message if the user didn't have cookies enabled. If my recollection is correct, I think that is the way to go - this should be addressed in Drupal rather than Ubercart.

adamo’s picture

Drupal works without cookies. Nothing that requires a session will work, but anonymous stuff works just fine.

There is an open issue trying to get a cookie check added to Drupal that will display a warning if a user tries to log in without cookies: #2946: Login fails and no warning is issued if cookies are not enabled
It's like 7 years old.

There is also a module for D6 that provides the same functionality as the proposed patch would.
http://drupal.org/project/cookie_check

Both of these things affect login only. I think that's the right way to go, since you don't necessarily want your entire site to be unavailable just because someone has cookies disabled.

Ubercart doesn't require you to log in before you add items to your cart (nor should it). Currently if someone who has cookies disabled tries to add something to their cart, they get taken to an empty cart page. To the average user who doesn't really understand what cookies are it's probably going to look like the site is just plain broken. Even if one of the above solutions is implemented, an anonymous user with cookies disabled who tries to add something to their cart is simply going to get back an empty cart page. Not good, especially since people new to your site are likely to browse around your catalog and see if you have anything they want before they even bother creating an account. I know when I shop around I'll browse a site and add a bunch of stuff to my cart and see what it's all going to cost me, before I bother creating an account on the site. Anonymous users should be able to add stuff to their cart, and if they are unable to because they have cookies disabled, the site should let them know that so they can enable them.

tr’s picture

@adamo: Thanks for looking that up - I knew I had seen it somewhere ...

So it sounds like having Ubercart check for cookies on add-to-cart and display a message if cookies aren't enabled is the right thing to do.

SeanA’s picture

Version: 6.x-2.2 » 6.x-2.4
Status: Needs work » Needs review
StatusFileSize
new683 bytes

Can we put the cookie check in theme_uc_empty_cart() like #7? I'm not understanding why this isn't a good solution, it seems to work just fine. I changed the message somewhat.

tr’s picture

Status: Needs review » Needs work

This sort of check shouldn't be performed in the theme layer. Sites are allowed to (even expected to!) override the theme functions.

tr’s picture

This sort of check shouldn't be performed in the theme layer. Sites are allowed to (even expected to!) override the theme functions.

Rainman’s picture

#7 as presented as a theme override in the template.php, it does work as expected and is a reasonable workaround for now.

hoping to see a proper solution in Ubercart.

tr’s picture

Version: 6.x-2.4 » 7.x-3.x-dev

New features go in to 7.x-3.x first. Please submit a patch if you'd like to see this put into Ubercart.

tr’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Issue summary: View changes