Skip to content

Query the orders related to a customer? #94

Open
@Darpan-laravel

Description

@Darpan-laravel

Hi, I was trying to query orders related to a specific customer. But what I have found is that, in order fields received through order api, in the billing section under it, there is an email field under billing which matches with the email field of the customer fields received through customer api and THIS IS THE ONLY LINK. There is a 'customer_id' field in the order params but most of the times it is 0 (I believe 0 is for guests in WooCommerce?). [Moreover, the billing field you get is in the format (in order api),
[
{
"id": 7337, //order_id
"billing": {
"email": "cuccagna@gmail.com",
},
}
]

So, I am trying the below query on the basis of the results I got,
(I am using the data received through api directly, not saving those in database)

$customeremail = $request->email;
$order_of_the_customer = order:where('to->billing->email', $customeremail)->get();
Or,
$order_of_the_customer = order::whereJsonContains('to', [['billing' => ['email' => $customeremail ]]])->get();

But NONE OF THESE WORKS!!. Can someone help me? Seems like no queries using where condition is working.. (even simple queries, it always results in all the results (which is 10 per page)) (only order::find($id) works efficiently)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions