簡體   English   中英

Shopify:困境創建新的收藏

[英]Shopify: Dilemma creating new Collection

我正在嘗試使用Sandeep Shetty的shopify.php創建一個自定義產品集合。 我已經能夠進行其他功能性API調用-顯示產品和購物車等。但是我無法使用以下代碼創建自定義集合

// For private apps:
$shopify = shopify_api_client(SHOPIFY_DOMAIN, NULL, SHOPIFY_API_KEY, SHOPIFY_API_PASS, true);

$charge = array
    (
        "custom_collection"=>array
        (
            "title"=>"IPods",
            "collects"=>array(
                "product_id"=>99395358,
            )
        )
    );
//        pr(json_encode($charge), 1);
$charge = '{"custom_collection": { "title": "IPods", "collects": [ {"product_id":99395358}, {"product_id":0000000} ] } }';


try
{
    // All requests accept an optional fourth parameter, that is populated with the response headers.
    $my_collect = $shopify('POST', '/admin/custom_collections.json', $charge, $response_headers);

    // API call limit helpers
    echo shopify_calls_made($response_headers); // 2
    echo shopify_calls_left($response_headers); // 298
    echo shopify_call_limit($response_headers); // 300

    pr($my_collect);

}
catch (ShopifyApiException $e) 
{ 
     pr($e);
}
catch (ShopifyCurlException $e)
{            
    echo "doh";
    pr($e);
}

根據上述請求,我得到以下響應,我不確定請求中有什么問題,因為這被認為是錯誤的請求

ShopifyApiException Object
(
[info:protected] => Array
    (
        [method] => POST
        [path] => /admin/custom_collections.json
        [params] => {"custom_collection": { "title": "IPods", "collects": [ {"product_id":99395358}, {"product_id":0000000} ] } }
        [response_headers] => Array
            (
                [http_status_message] => Bad Request
                [http_status_code] => 400
                [server] => nginx
                [date] => Thu, 06 Sep 2012 05:55:36 GMT
                [content-type] => application/json
                [transfer-encoding] => chunked
                [connection] => keep-alive
                [status] => 400 Bad Request
                [x-runtime] => 0.000986
            )

        [response] => Array
            (
                [error] => lexical error: invalid char in json text.
                                "{"custom_collection": { "title": 
                 (right here) ------^

            )

    )

[message:protected] => Bad Request
[string:Exception:private] => 
[code:protected] => 400
[file:protected] => D:\www\jim\shopify\init.php
[line:protected] => 244
[trace:Exception:private] => Array
    (
        [0] => Array
            (
                [file] => D:\www\jim\shopify\index.php
                [line] => 31
                [function] => {closure}
                [args] => Array
                    (
                        [0] => POST
                        [1] => /admin/custom_collections.json
                        [2] => {"custom_collection": { "title": "IPods", "collects": [ {"product_id":99395358}, {"product_id":0000000} ] } }
                        [3] => Array
                            (
                                [http_status_message] => Bad Request
                                [http_status_code] => 400
                                [server] => nginx
                                [date] => Thu, 06 Sep 2012 05:55:36 GMT
                                [content-type] => application/json
                                [transfer-encoding] => chunked
                                [connection] => keep-alive
                                [status] => 400 Bad Request
                                [x-runtime] => 0.000986
                            )

                    )

            )

    )

[previous:Exception:private] => 
)

我知道了

if(count($categories_results) > 0){

    foreach($categories_results as $cat){

            try
            {

                $charge = array
                (
                    "custom_collection"=>array
                    (
                        "title"=>$cat['name'],
                    )
                );

                try
                {

                    $recurring_application_charge = $shopify('POST', '/admin/custom_collections.json', $charge, $response_headers);



                    $shopify_cat_id = $recurring_application_charge['id'];
                    $shopify_cat_data = serialize($recurring_application_charge);
                    $db->update('categories', array( 'shopify_id' => $shopify_cat_id, 'shopify_res' => $shopify_cat_data ), "id=%d", $cat['id']);

                }
                catch (ShopifyApiException $e)
                {
                    pr($e);

                }

            }
            catch (ShopifyApiException $e)
            {
                pr($e);
            }
            catch (ShopifyCurlException $e)
            {
                pr($e);
            }


    } //end of foreach

} //end of IF

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM