Currently in checkout_form(line 334 cart.module) we have:

    /* If this is an anonymous user, check all the products and see if they
     * can be sold to them. If there are products which cannot be sold to an
     * anonymous user then get the user to login or register. */
    if (!$user->uid) {
      foreach ($data->items as $item) {
        if (in_array('registered_user', (array)module_invoke($item->ptype, $item, 'attributes', 'registered_user'))) {
          drupal_set_message(t('Login or <a href="%reg-link">register</a> to continue the checkout process', array('%reg-link' => url('user/register', drupal_get_destination()))));
          drupal_goto('user', drupal_get_destination());
        }
      }
    }

If we want to provide the same functionality of allowing the checkout to be altered at checkout so ec_anon can use the same functionality we need to add another checkoutapi op. Alternatively, we can stick with the "add to cart" approach currently being used by ec_anon and remove this code.

Comments sammys?

Comments

sammys’s picture

Version: 4.7.x-3.x-dev » 4.7.x-3.0-beta1

Versions 3.0+ are meant to move anonymous purchase handling away from other core modules that previously implemented the feature. We wanted to centralize it all to improve maintainability and design. That said, there are still chunks of cruft in the core modules that serve no purpose but to confuse. :)

In this case, I don't believe this code will ever execute because ec_anon attempts to logs the user in on the first checkout screen. I think its safe to remove that chunk of code.

In addition, we need to add/edit code to ec_anon to handle the following:

  • A check is performed ('allowed in cart') for anonymous only products being added to a registered user's cart. This will need to also do a check using email address so that the registered user can't fool the system and put it in an unhappy state if that user then decides to open a full account with that email address already taken.
  • A check is performed ('allowed in cart') for a conflict check to ensure the product being added doesn't conflict with a product already in the cart. E.g you can't add an anonymous only product when you have a registered user only product in the cart already. Perhaps the quickest way to do this is to alter the transaction object (during checkout only) to have regonly_added and anononly_added boolean members.
  • All other products are allowed in the cart and are checked at the first checkout screen where the appropriate interface is displayed.
sime’s picture

bump

neclimdul’s picture

Status: Active » Closed (fixed)

Sorry, this is my fault for not following up. The code is still in cart I believe and not factored out completely but for now its probably fine.

budda’s picture

Is the code 'module_invoke($item->ptype, $item, 'attributes', 'registered_user')' valid? Surely the 2nd paramter in a module invoke should be a string of the hook to call - in this case 'productapi' ?

if (in_array('registered_user', (array)module_invoke($item->ptype, 'productapi', $item, 'attributes', 'registered_user')))