Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Not sure if this is the best area to ask this, but I was wondering if I have guest checkout option enabled and many customers utilise it, how can I sign them up as a proper account on my store. I think it would be more of a convenience for the user in case they want to view their order history.
I am using customerCreate to sign-up for an account, but I had wrongly assumed if I signed up using the same email as a guest it would just "enable" it.
Is there a way to enable a guest email as a normal account?
I'm not sure exactly what you're asking but in my experience orders are tied to email addresses. So if a person created 3 different guest checkouts using the same email, then they create an account later using the exact same email address, the previous 3 orders will show when they're logged in.
The reverse is also true. If they have an account but checkout as a guest, as long as the email is the same it will show in their account.
Yea that's what I assumed, but with the customerCreate it just returns a null value when I sign-up using an email I used for a guest order. I try to sign in and it doesn't work.
I wonder if it has something to do with activating accounts. But I wish the api would return an error or something to tell me why the account wasn't created.
Yeah that's likely it. customerCreate starts the creation flow by sending an email (and returns the message, via customerUserErrors: "We have sent an email to YOUR@EMAIL.COM, please click the link included to verify your email address.", until they verify they won't be able to login via the email/password from customerCreate.
It is verified immediately. With an email being sent saying so. Just need to figure how a guest email will be sent something.
Kind of want to follow-up on this because it is still unclear how the flow works. I'll go through my findings with the scenarios.
1. User creates an account never placing a guest order previously.
Here, it is a brand new account using customerCreate. As stated in the documentation, "if the mutation is successful, then a welcome email is sent to the customer with the information that their account has been activated." This happens, and a customer object is returned after calling the mutation. The account is activated automatically.
2. User creates an account with a guest order existing for that email
We run customerCreate for an existing email, however this time, customer is NULL and doesn't return customerUserErrors stating that an email has been sent. The activation email is sent though. Here I guess I can just assume when customer is null that the activation email is sent, but not sure if this is intended.
Moreover, the activation form, I'm using the shopify theme ( not headless ) requires a password to activate. So why does customerCreate require a password? I would understand if the user had to repeat and confirm their password, but customCreate password can be different from the Activation password.
I can make this flow work as long as I can distinguish activation by email from automatically activated accounts.
*note that these guest orders were created manually in the admin, so not sure if this is what is affecting it.
3 User create an account that exists
If the account was previously made, customerCreate returns customer NULL. I believe we should be getting the customer object or at least a customerUserErrors that the customer has already been created?
Sorry really stuck on this one. Pretty much can't deploy account creation without reconciling the customerCreate not returning the activation email response message. customerCreate for both immediate activation and email activation are identical. I can hack it by trying to get an AccessToken afterwards and if I can't login it isn't activated.
I went and tested a few of these to make sure I was getting the result. These were tested on API v2022-04:
For #1 we both had the same result.
#2 returned the customer as null and and a message in customerUserErrors that said: "We have sent an email to test@email.com, please click the link included to verify your email address." Which to me is the ideal behaviour.
Moreover, the activation form, I'm using the shopify theme ( not headless ) requires a password to activate. So why does customerCreate require a password? I would understand if the user had to repeat and confirm their password, but customCreate password can be different from the Activation password.
The weirdness here is likely partially a result of using both a theme and the Storefront API at the same time. customerCreate is usually the first step in a headless flow and that doesn't require any email confirmation, unless the account already exists.
For #3 I get the customer as null and an error message saying the email is already in use. You wouldn't want the customer object here because then anyone can fetch a customers details (addresses and order history) by trying to create an account with their email which would be a huge security issue.
I guess this is to say on my test everything seems to be working as I'd hope/expect. Maybe using customerGenerateAccountActivationUrl from the Admin API might be a better option for you if the Storefront API isn't getting the responses you'd expect? What API version are you using?