2

I need to get orders data directly from the database. I have got all orders (about 18,000) since January 2020. I need to do a join to customer_entity however, I realized that about 300 records were missing.

By investigating further, I found out that the customer_id value is null for most of the records. Some records do have a customer_id column set but shipping address id fields are null. These latter occur for orders in processing status.

Most curious is the null value in the customer_id column of some orders, even in orders in complete status.

For the query, I need to join the customer's table so it is not an option to get all data from the sales_order table.

Any help? Thanks

Jaime

1
  • You can also get the customer from email saved in the quote table corresponding to the order. Please check if you have that corresponding to the order having null ids in order table. Aug 16 at 10:33
0

Check whether Guest Orders are enabled for your store. Guest orders usually won't have customer Id set in order table.

0

customer_id have foreign key. Technically, customers can be deleted. While customer deletion, all his orders sets customer_id to NULL.
You can check column customer_is_guest in sales_order to determine guest orders. You can use customer_email as alternative ID.

0

Why don't you join sales_order_address - one time for address_type="shipping" and one more join with address_type="billing"?

You can pull all customer information from there, regardless whether customer was signed in or this was a guest order.

Alternatively, you can take joined information from sales_order_grid table.

0

There are 2 reason of this things.

  1. The Order which you are refer is the Guest User Order.

  2. The Order which you are refer, those customer are delete from the system.

So, no required to perform any join query, because if data is available then it on the same table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.