Issue
When fetching a customer record from either the REST API or the Graph API, the following values will be invalid for customers who have placed an order, but where the customer record itself has not actually been updated:
- orders_count (numberOfOrders)
- total_spent (amountSpent)
- last_order_id (lastOrder)
- last_order_name (lastOrder)
Reproduction Steps1. Create a new customer.
-
Create a new order and attach to the customer.
-
Check /admin/customers/[id].json
- orders_count is 0 (should be 1)
- total_spent is 0 (should be order total)
- last_order_id is null
- last_order_name is null
-
Create another order for the customer
- Note that the customer order-related fields still do not update.
Note: The field values are incorrect in the REST API and the Graph API as well.
Root Cause
The root cause of this issue appears to be that the customer record is cached for a period of time (maybe forever?). Placing an order does not update the customer record or clear the cached data, and so the order-related fields do not appear as updated.
To prove this you can add a tag to the customer (which will trigger the customer to “update”), and now check the customer record. You will see that after updating the customer the orders_count and other fields are correct.
Recommended Fix
Clear the customer record cache whenever an order is placed for that customer.
