首页 > 解决方案 > 创建订单后如何检索客户电子邮件 - Laravel & Shopify

问题描述

当我创建订单时,我的 web-hook 会向我的控制器返回一个响应,下面是我如何检索订单的详细信息

控制器

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,
 }
}

标签: phplaravelshopify

解决方案


您可以使用:

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

推荐阅读