4

Anonymous users are supposed to have access to Commerce cart/checkout by default. In my current project cart remains empty for anonymous users, even if an order is created. When an anonymous user clicks on Add to cart, a new order is correctly created, with the Owned by anonymous status. This is fine, but:

  • While the current product page is reloaded as expected, the rule displaying the default message (Foo was added to your cart) is not fired

  • If I manually go to /cart, I get the Cart is empty message. /checkout returns a 404 error.

  • $_SESSION remains empty (I precise this because of commerce_checkout_access()).

    if (empty($_SESSION['commerce_cart_orders']) || !in_array($order->order_id, $_SESSION['commerce_cart_orders'])) {
      return FALSE;
    }
    

In fact, it seems that in anonymous context, the order cannot be seen.

How do I debug why the cart remains empty, and the order isn't visible to anonymous users?

My config: clean step by step Commerce install, not Kickstart; some custom line items ; Access checkout / View own orders of any type / View any product of any type permissions granted for anonymous.

11
  • did you check permission of check out ?
    – Yuseferi
    Jul 22, 2014 at 10:06
  • Yes Zhilevan, I did, tks. I even tried more exotic permissions with order & products, no way
    – Kojo
    Jul 22, 2014 at 10:08
  • Check your Rules configuration ( admin/config/workflow/rules ) for add to cart etc.. It's possible something there may be the cause. Jul 22, 2014 at 10:29
  • 1
    Just to try and isolate the issue it might be worth disabling some modules. I'd start with any home-grown modules you have, then all the modules you've added since the working backup, and finally any caching modules you might have installed. (Don't forget to clear caches before testing.) Could you confirm if commerce_cart_add_to_cart_form_submit() is actually run, and if so step through it and report back on where things go a bit wrong?!
    – Andy
    Jul 22, 2014 at 10:33
  • @DavidThomas Tks David I already checked, there are few rules, most of them default Commerce rules, and I deactivated all to test & make sure
    – Kojo
    Jul 22, 2014 at 10:57

2 Answers 2

8

Happy end, and stupid lost time : the lone problem was the Anonymous user was accidentally deleted (don't know how) ! I thank all the gentlemen who tried to help me to debug.

The uid 0 must absolutely be there. If you encounter such case, simply insert an empty row in users table via phpmyadmin or run these 2 queries (for D7) :

insert into users (name, pass, mail, theme, signature, language, init, timezone) values ('', '', '', '', '', '', '', '');
update users set uid = 0 where name = '';

Meanwhile, I've read many things about Commerce checkout to make sure I was doing right. I share some clues below in case it could help somebody else.

A common issue for empty cart page (and other Commerce Views issues where user can't see products) is due to Referenced Product Relationship: 2 solutions may work depending on your config :

  • In the View's advanced settings fieldset, disable SQL rewriting.
  • Enable the not-totally-secure View any product of any type permission. This is discussed & patched here. If you have Commons distribution, you’ll have to disable paranoia (disable with Drush only, it's not visible in the module list).

Important permissions to grant (admin/people/permissions) :

  • Anonymous :
    • Checkout => Access checkout
    • Order => Create orders of any type / Create orders
  • Authenticated : same ones, plus
    • Order => View own orders of any type / View own orders

Default behavior in Drupal Commerce :

Anonymous users can add a product to cart, checkout (filling email, name and address), review and complete order. Some documentation to read : Checkout: Anonymous vs. Authenticated and Anonymous Carts and Logged In Users


An a few useful tips and links to enhance default checkout

0

find file docroot/web/sites/all/modules/contrib/commerce/modules/cart/commerce_cart.module

find function commerce_cart_get_provider and force it to load CommerceCartProviderSession class

/**
 * Returns the instantiated cart provider.
 */
function commerce_cart_get_provider($provider = NULL)
{
  ctools_include('plugins');

  if (empty($provider)) {
     $file = DRUPAL_ROOT . '/' . drupal_get_path('module', 'commerce_cart') . "/plugins/cart_provider/CommerceCartProviderSession.class.php";
     require_once($file);
     $class = 'CommerceCartProviderSession';
     return new $class();
    // the following line was not working
    // $provider = variable_get('commerce_cart_provider', COMMERCE_CART_DEFAULT_PROVIDER);
  }

  // Return NULL if the class could not be found.
  if (!$class = ctools_plugin_load_class('commerce_cart', 'cart_provider', $provider, 'class')) {
    return NULL;
  }

  return new $class();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.