Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Customer order-related fields such as orders_count, total_spent and last_order_id are out-of-date

Customer order-related fields such as orders_count, total_spent and last_order_id are out-of-date

DanAtBonify
Shopify Partner
59 4 44

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 Steps

  1. Create a new customer.
  2. Create a new order and attach to the customer.
  3. Check /admin/customers/[id].json
    1. orders_count is 0 (should be 1)
    2. total_spent is 0 (should be order total)
    3. last_order_id is null
    4. last_order_name is null
  4. Create another order for the customer
    1. 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.

Reply 1 (1)

JAS_Technology
Shopify Partner
91 0 67

Thanks for reporting this. I'm just chiming in to say I'm experiencing the same behavior. Even when trying to force an update, the value is still zero,. 

 

Kindred Retail · Customers · Jonathan Schwartz · Shopify 2023-08-17 at 10.18.01 AM.jpg

Happy to hear about your crazy ideas.