Support guest checkout when anonymous account creation is enabled

Created on 23 October 2023, about 1 year ago
Updated 31 March 2024, 8 months ago

Problem/Motivation

When an order is placed as a guest (using a checkout flow with "Assign an anonymous order to a pre-existing user" and "Create a new account for an anonymous order" both enabled), the events commerce_license's OrderSubscriber are listening to are fired in an order that seems unexpected. The licenses are created after onAssign is called, so they never have the correct user.

Steps to reproduce

Set breakpoints in commerce_license's OrderSubscriber and check out as a guest. This is the order the listeners are called in:

  1. onAssign (dispatched from Commerce's GuestCheckoutCompletionSubscriber listening to CheckoutEvents::COMPLETION)
  2. onPlace (dispatched as order transition resulting from CheckoutFlowBase::redirectToStep() saving the order)
  3. onPaid (dispatched from OrderStorage::doOrderPreSave())

Proposed resolution

It seems like onAssign should be creating the licenses if they don't exist, just like onPlace/onPaid. It should probably not set the license state to active, specifically so the check in onPlace isn't hit and the licenses get the purchased entity assigned.

✨ Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @karlshea
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    18 pass
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    Well the Gitlab integration is broken so ignore the issue fork.

    Patch attached.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States TomTech

    Hi @KarlShea,

    Thanks for the report for this particular configuration.

    As noted in the read me (and also should be reported in the license dashboard), guest checkout is not supported currently.

    Configure (or create) a checkout flow at admin/commerce/config/checkout-flows

    This flow must set "Guest checkout: Not allowed" for the "Login or continue
    as guest" pane.

    More work would need to be done to support this, including:
    1. Determining what would happen if "Create a new account for an anonymous order" is NOT enabled? (Maybe we allow guest checkout ONLY if this is enabled?)
    2. Updating the dashboard to reflect this change.
    3. Updating the read me to reflect this change.
    4. Determine if there are any other issues that prevented this from being supported previously. (It might be that there aren't any other items to address, other than that listed here + the submitted patch.)

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    I saw the related issue so I thought maybe the dashboard/readme just hadn't been updated, but it seems that wasn't the case!

    Determining what would happen if "Create a new account for an anonymous order" is NOT enabled? (Maybe we allow guest checkout ONLY if this is enabled?)

    I believe it would function the same as it does without the patch, where the license is created but doesn't have a valid user assigned (since onPaid/onPlace aren't doing any checks either before creating the license.

    I'll update the patch with changes to the dashboard/readme.

    Determine if there are any other issues that prevented this from being supported previously. (It might be that there aren't any other items to address, other than that listed here + the submitted patch.)

    I'm testing this with commerce_file and everything seems to work well!

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    18 pass
  • @karlshea opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    18 pass
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    18 pass
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    I created a product variation type that assigns a role and it also worked with guest checkout.

  • πŸ‡©πŸ‡°Denmark ramlev

    Cannot see why we can enable the feature to support anonymous shopping with commerce_license. Every order have an email attached.

    And for my usecase, i want to enable it for anonymous users, and add a token so it's possible pΓ₯ to send an email with the license code. Even though that the user cannot login to it's account.

    Make sense ?

Production build 0.71.5 2024