2017-06-12 69 views
0

在這裏,我被困在shopify通過API創建網絡掛接創建使用API​​在shopify

我使用的蛋糕PHP創建公共shopify應用

現在我想創建推車/更新鉤我的應用程序一個網絡掛接這裏使用的API是我的代碼 蛋糕PHP庫:https://github.com/cmcdonaldca/CakePHP-Shopify-Plugin

文件: ShopifyApiComponent.php

CODE:

public function createwebhook($shop_domain, $access_token){ 

    $method = "POST"; 
    $path = "/admin/webhooks.json"; 

    $params = array("webhook" => array("topic"=>"carts/create", 
        "address"=> $this->site_url."users/upUpdateCart", 
        "format"=> "json")); 


    $password = md5($this->secret.$access_token);//If your shopify app is public 
    $baseurl = "https://".$this->api_key.":".$password."@".$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: ' . $access_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)) 
     $body = $response['errors']; 
    else 
     $body = $response_body; 
    /*Debug the output in a text_file*/ 
    $destination = realpath('../../app/webroot/execution_log') . '/'; 
    $fh = fopen($destination."shopify_app.txt",'a') or die("can't open file"); 
    date_default_timezone_set('GMT'); 

    fwrite($fh, "\n\nDATE: ".date("Y-m-d H:i:s")."\n".$body); 
    fclose($fh); 
    /*Debug Code Ends*/ 
    return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response; 
} 

,我調用此函數當我訪問我的應用程序儀表板意味着 控制器:信息 功能:儀表盤

但它不是好像,因爲當我訪問 https://test.myshopify.com/admin/webhooks.json其深藏不露,但 如果工作我我通過管理 - >設置 - >通知創建網絡掛接那麼它在這裏展示上市https://test.myshopify.com/admin/webhooks.json

請讓我知道我們如何使用API​​來創建網絡掛接(蛋糕PHP)

回答

1

Shopify通過webhooks.json顯示webhooks列表,這些是通過shopify管理員手動創建的。如果你想,那麼你需要從其他瀏覽器或專用瀏覽器(其中shopify管理不loged)運行它通過API創建的網絡掛接的列表

你的鏈接將是這樣的 - https://api-key:[email protected]/admin/webhooks.json

注意:替換您的應用程序的api密鑰和密碼,並替換鏈接中的商店名稱,並在新的/私人瀏覽器窗口中嘗試它。

+0

有沒有辦法讓我們在感謝頁面上添加sone腳本 – Chauhan

+0

我認爲你不能在思想頁面中定製任何東西(通過編碼),因爲謝謝你的頁面屬於checkout.shopify。 com域名和shopify不允許修改任何內容。但它的思想......可能有一種方法。 –