Customer Order History Empty after 4.9 upgrade

Saturday, September 30, 2023 1:46:35 AM
  • Posted: Wednesday, July 14, 2021 4:43 PM
  • 32
Customers are reporting an empty Orders list after upgrading to v4.9. Stepping through the GetOrderQueryHandler with a debugger reveals that the query is filtering orders by StoreId and OwnerId. None of the orders created before the upgrade have an OwnerId. What's the right way to fix this?

  • Posted: Wednesday, July 14, 2021 5:06 PM
  • 32
A little more digging reveals the following:


            if (!request.Customer.IsOwner())
                query.CustomerId = request.Customer.Id;
                query.OwnerId = request.Customer.Id;


        public static bool IsOwner(this Customer customer)
            return string.IsNullOrEmpty(customer.OwnerId);

If I am reading this right, anytime customer.OwnerId is null/empty, we are setting GetOrderQuery.OwnerId to customer.Id. If it's not empty, we are setting GetOrderQuery.CustomerId to customer.Id. All of my customers have a null OwnerId, so this handler will never filter orders by CustomerId. Is this backward?
  • Posted: Wednesday, July 14, 2021 5:50 PM
  • Team
  • 135

OwnerId is used when you have subaccounts.
What was your previous version?

  • Posted: Wednesday, July 14, 2021 5:52 PM
  • 32
Previous version was 4.5.
  • Posted: Wednesday, July 14, 2021 6:00 PM
  • 32
I think I understand.  A null Customer.OwnerId indicates that the customer is not a subaccount (not owned by another customer). It looks like new Orders are created with an OwnerId (the CustomerId, unless the customer is a subaccount owned by another Customer). Should I just update the orders collection and copy Order.CustomerId to Order.OrderId?
  • Posted: Wednesday, July 14, 2021 6:32 PM
  • Team
  • 135
It looks like is a problem with upgrade. We should update all orders and set OwnerId as CustomerId.
If you have access to the database you can run this script:

        {"$set": {"OwnerId": "$CustomerId"}}

(before please make sure that you backup your database)

Btw, in few days we will publish fixed version.
Thanks for reporting!

  • Posted: Wednesday, July 14, 2021 6:34 PM
  • 32
Perfect! Thanks again for the help, Krzysztof!
back to top