Anonymous User Email deleted

Created on 31 March 2023, about 1 year ago
Updated 15 September 2023, 10 months ago

Problem/Motivation

Our store only serves anonymous users at this point. We use the commerce_checkout_link in conjuction with commerce_abandoned_carts to create non-session dependent link back to their order. I just discovered that when the users clicks the link, it goes to the order review page as expected, but their email address gets erased and thus they can't submit the order.

I tracked it down to this part of the code where the order gets assigned to the current user, in this case an anonymous user.

  $this->orderAssignment->assign($commerce_order, $this->entityTypeManager->getStorage('user')->load($this->currentUser->id()));

in CommerceCheckoutLinkController.php

When i looked at the OrderAssignment.php, i saw that it checks for the current users email and sets that as the order's email value. Well, the anonymous user doesn't have an email address, so the order assignment function overwrites the email address they already input and sets it to null.

So my question is, with an anonymous user, is the order assignment necessary to appropriately generate this link? I don't claim to understand how this all works, but the email being overwritten is unhelpful in my use case.

✨ Feature request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @J.
  • πŸ‡³πŸ‡΄Norway eiriksm Norway

    Well it has to be assigned to be able to continue to check out that order, yes. Does the order assigner need to overwrite the email? I guess not, but that would be an issue for the commerce project :)

    Totally open to looking at a patch for it, where we can compensate for that in this module, if you are able to whip that up? πŸ€“

  • Thank you for clarify that the assigning is necessary. I will be happy to work on a patch and i might post this as an issue on the commerce project as well.

  • Status changed to Needs review about 1 year ago
  • Here's a go at a patch for this.

    I replaced the call to commerce's assign method with modification of it that leaves email untouched in the case of anonymous users. I'm not sure if the OrderAssignEvent is needed in this case, but left it since i'm still new to what all this is doing and don't want to break anything. I did remove the optional $save_order parameter from the original function and defaulted to saving the order because i was unsure how to make it optional in this case.

    I manually tested it for an anonymous and a user with an account. The checkout link worked correctly and the order went through for both.

  • πŸ‡³πŸ‡΄Norway eiriksm Norway

    Thanks for the patch! πŸ€“

    Hm, I would rather use the assigner service directly and you can suggest your change in commerce directly.

    However, I have a different suggestion that would solve your problem. What if you implemented a listener for the order assign event in a custom module? You could just set the customer (and their email) from there?

  • If i implement a listener for the order assign event and do my own setting of customer/email does it skip implementing commerce's?

  • Status changed to Closed: works as designed 10 months ago
  • Thank you for the tips. I implemented your suggestions and have a working solution. Closing this issue now.

Production build 0.69.0 2024