Im使用插件CakePHP使呼叫獲得某些訂單。我可以打電話給某些領域的所有訂單,但我想知道如何才能打電話來獲得具有特定名稱或訂單號的訂單?以下是致電Shopify的來源。它已經通過身份驗證和一切:Shopify API通過名稱或order_number獲取訂單
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}:[email protected]{$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
的URL .json
後,試圖獲得訂單#1001,但它帶回一個空數組。
然後我嘗試?order_number = 1001但它帶給我每一個訂單以及1001 D:這真是令人困惑,任何人都可以幫助我嗎?
在此先感謝。
如果你必須手動逃脫#在您的查詢字符串,這意味着當時的api調用是通過原始輸入。真正的修復應該在你的HttpRequest類中,它應該是url編碼查詢參數傳入它。http://php.net/manual/en/function.http-build-query.php – txyoji
實際上,編碼#的編號會使我們的商店使用前綴作爲訂單名稱的前綴,其他編號可能會在訂單編號上有其他前綴。 http的工作會更多,因爲我不是每次都會在ShopfyAPI的域上發送名稱來進行調用。 –
我明白name =#000000是格式。我說的是,如果你必須手動轉義一個值(使用%23而不是#),這意味着你的查詢字符串中有一個保留字符(空格,#?&)的任何值都不會被編碼正確。在 - > call()方法中解決這個編碼問題意味着您不必擔心「$ fields」數據中的特殊字符。 http_build_query()可以爲你處理這個細節。 – txyoji