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 anon. user clicks on Add to cart, a new order is correctly created, with status Shopping cart, Owned by anonymous. This is fine, BUT:

  • While the current product page is reloaded as expected, the rule displaying default message "Foo was added to your cart" is not fired
  • If I manually go to /cart url, Cart is empty. And /checkout url returns 404.

  • $_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...

So the question is :

  • How to debug why does cart remains empty / order is not visible for anonymous users ?

Thanks for your help.

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...


EDIT : I'm currently checking intermediate dev backups, and the fact is just after adding COMMERCE to my project, the checkout process was fluid for anon : cart/checkout/review/complete.

  • did you check permission of check out ? – Yusef Mohamadi Jul 22 '14 at 10:06
  • Yes Zhilevan, I did, tks. I even tried more exotic permissions with order & products, no way – Kojo Jul 22 '14 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. – David Thomas Jul 22 '14 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 '14 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 '14 at 10:57
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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