Как получить электронную почту клиента после создания заказа — Laravel & amp; Shopify

Когда я создаю заказ, мой веб-хук возвращает ответ моему контроллеру, и ниже показано, как я получаю детали заказа

контроллер

public function getOrderDetails()
{
// get the content of request body
$order = $request->getContent();
$order = json_decode($order, true);
$order_id = $order['number'];
$order_total = $order['total_price'];

$customer_email = $order['customer.email'];


}

Как и в моем контроллере, я могу получить order_id, order_total но я не могу получить электронную почту клиента, который разместил заказ.

Что не так в моем коде?

Так выглядит ответ от Shopify

отклик

{
"id": 820982911946154508,
"email": "jon@doe.ca",
"closed_at": null,
"created_at": "2018-10-26T13:55:26-04:00",
"updated_at": "2018-10-26T13:55:26-04:00",
"number": 234,
"note": null,
"customer": {
"id": 115310627314723954,
"email": "john@test.com",
"accepts_marketing": false,
"created_at": null,
}
}

1

Решение

Ты можешь использовать:

$customer_email = $order['customer']['email'];
3

Другие решения

1) Ваши данные JSON имеют ошибку. Вы должны удалить запятую (,) перед}

2) ниже код работает правильно

$order='{
"id": 820982911946154508,
"email": "jon@doe.ca",
"closed_at": null,
"created_at": "2018-10-26T13:55:26-04:00",
"updated_at": "2018-10-26T13:55:26-04:00",
"number": 234,
"note": null,
"customer": {
"id": 115310627314723954,
"email": "john@test.com",
"accepts_marketing": false,
"created_at": null
}
}';

// get the content of request body
$order = json_decode($order, true);
$order_id = $order['number'];
$order_total = $order['total_price'];

$customer_email = $order['customer']['email'];
echo $customer_email;
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector