-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with order queries for users who have never logged in #1237
Comments
Hey @cdfwebsolutions Just before we dig into this. Can I check that in your example:
The variable Remember that when querying for a user it will only return active users unless you specify otherwise. For example:
|
Yes, |
We have noticed in outputting the raw query generated by |
Ah, I think I follow now @cdfwebsolutions. So what is likely happening here is that this user doesn't have a customer record as they have never logged in/ordered (a "customer" is only created when an ordered is placed or a cart saved. As a temporary solution in your code you can wrap your query in:
This will check to see if they have a customer record. This can be a stop-gap until we rework the |
Thanks, yes, that does fix things for now :) Just for clarity, does a customer record get created on first login or just when a cart is saved or order placed? We have some users with 0 orders (who show up correctly), but perhaps they started the order process and saved a cart. |
@cdfwebsolutions it is when a cart is saved. Having said all that, I have just pushed an update that makes sure all users have a customer record no matter if they have ordered or not. So this should not be an issue in the future. This will be included in the next release. |
Description
Filtering orders by user fails if the user has never logged in and has no associated orders. Instead of returning no results, the query returns all orders. This is a problem when we attempt to check if a user has any orders and the user has never logged in.
This behavior can be seen in both an order query using the user parameter (per https://docs.craftcms.com/commerce/v2/dev/element-queries/order-queries.html#users) and on the Customer Info tab (which is blank instead of displaying the usual "No orders exist for this user yet." message).
Steps to reproduce
(Assumes we already have a number of Commerce orders in the CMS.)
The above outputs the total # of orders in the CMS. If we change '999' to a user's ID that has logged in but has no orders, it returns 0. And, if we set the user ID to a user with orders, the correct # of orders is retrieved. (Likewise, using .all() returns all orders.)
Additional info
The text was updated successfully, but these errors were encountered: