Shopify API 按名称或 order_number 获取订单

Shopify API getting order by name or order_number

我正在使用 CakePHP 的插件进行调用以获取某些订单。我可以调用具有特定字段的所有订单,但我想知道如何调用才能获得具有特定名称或 order_number 的订单?这是调用 Shopify 的来源。它已经通过身份验证并且所有内容:

public function call($method, $path, $params=array())
    {
        if (!$this->isAuthorized())
            return;
        $password = $this->is_private_app ? $this->secret : md5($this->secret.$this->ShopifyAuth->token);
        $baseurl = "https://{$this->api_key}:$password@{$this->ShopifyAuth->shop_domain}/";

        $url = $baseurl.ltrim($path, '/');
        $query = in_array($method, array('GET','DELETE')) ? $params : array();
        $payload = in_array($method, array('POST','PUT')) ? stripslashes(json_encode($params)) : array();
    $request_headers = in_array($method, array('POST','PUT')) ? array("Content-Type: application/json; charset=utf-8", 'Expect:') : array();
    $request_headers[] = 'X-Shopify-Access-Token: ' . $this->ShopifyAuth->token;
        list($response_body, $response_headers) = $this->Curl->HttpRequest($method, $url, $query, $payload, $request_headers);
    $this->last_response_headers = $response_headers;
    $response = json_decode($response_body, true);

        if (isset($response['errors']) or ($this->last_response_headers['http_status_code'] >= 400))
            throw new ShopifyApiException($method, $path, $params, $this->last_response_headers, $response);

        return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response;
    }

    private function shopApiCallLimitParam($index)
    {
        if ($this->last_response_headers == null)
        {
            return 0;
        }
        $params = explode('/', $this->last_response_headers['http_x_shopify_shop_api_call_limit']);
        return (int) $params[$index];
    }

...以及调用 GET 的代码:

// I only want the id and title of the collections
            $fields = "fields=name,id,status,financial_status,fulfillment_status,billing_address,customer";
            // get list of collections
            $custom_collections = $this->ShopifyAPI->call('GET', "/admin/orders.json", $fields);
            $this->set('collections', $custom_collections);

我想我错过了可以放置调用条件以获得特定订单的地方。我已经阅读了 API 文档,但似乎无法得到答案。

我尝试将 ?name=%231001 放在 .json 之后的 url 上,以尝试获取订单 #1001,但它返回一个空数组。

然后我尝试了 ?order_number=1001 但它给我带来了每一个订单以及 1001 D:这真令人困惑,谁能帮助我?

提前致谢。

好吧,我发现您实际上可以使用名称或 order_number 来获取订单。它的另一个 属性 由于某种原因未在文档中列出。但是在 URL 中,如果您使用另一种语言,您只需在 GET 中添加 admin/order.json?name=%2310001&status=any 这是为了获取订单 10001 所以只需在 %23 之后添加 order_number。我在 Shopify 大学的一个论坛上看到了这个,我只是在我的代码中实现了这个错误。如果您像我一样使用 CakePhp shopify 插件,我所做的就是在 $field 上添加 ?name=%23".number."&status=any";

我把代码留在这里:

    $this->layout = 'main';

$order_number = "18253";

$fields = "name=%23". $order_number ."&status=any";

$order = $this->ShopifyAPI->call('GET', "/admin/orders.json", $fields);
   if (!empty($order)) {
     $this->set('order', $order);

     } else {
       $this->Session->setFlash('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> No existe el numero de orden ingresado.','default',array('class' => 'alert alert-danger alert-dismissible', 'type' => 'alert'));
     }

希望这对某人有帮助:P