【问题标题】:How to retrieve customer email after creating order - Laravel & Shopify创建订单后如何检索客户电子邮件 - Laravel & Shopify
【发布时间】:2018-11-06 22:37:59
【问题描述】:

当我创建一个订单时,我的 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,
 }
}

【问题讨论】:

    标签: php laravel shopify


    【解决方案1】:

    你可以使用:

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

    【讨论】:

      【解决方案2】:

      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;
      

      【讨论】:

        猜你喜欢
        • 2022-11-25
        • 1970-01-01
        • 1970-01-01
        • 2018-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-18
        • 1970-01-01
        相关资源
        最近更新 更多