【问题标题】:Unable to create custom collection of products via Shopify API post无法通过 Shopify API 帖子创建自定义产品集合
【发布时间】:2012-07-15 21:09:28
【问题描述】:

我正在尝试使用 Sandeep Shetty 的 shopify.php 创建自定义产品集合。 我已经能够进行其他功能性 API 调用 - 显示产品和购物车等。但我无法使用产品 ID 的“已知良好”列表创建自定义集合。 这是我的代码:

$charge = array
    (
        "custom_collection"=>array
        (
            "title"=>"ThisTest",
            "collects"=>array(
                "product_id"=>96525818,
                "product_id"=>96393246
            )
        )
    );
    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

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

}

我收到以下错误。

ShopifyApiException Object

( [信息:受保护] => 数组 ( [方法] => POST [路径] => /admin/custom_collections.json [参数] => 数组 ( [custom_collection] => 数组 ( [标题] => 托德测试 [收集] => 数组 ( [product_id] => 96393246 )

                    )

            )

        [response_headers] => Array
            (
                [http_status_message] => Internal Server Error
                [http_status_code] => 500
                [server] => nginx
                [date] => Mon, 16 Jul 2012 23:23:45 GMT
                [content-type] => application/json; charset=utf-8
                [transfer-encoding] => chunked
                [connection] => keep-alive
                [status] => 500 Internal Server Error
                [x-shopify-shop-api-call-limit] => 18/500
                [http_x_shopify_shop_api_call_limit] => 18/500
                [cache-control] => no-cache
                [x-request-id] => f22337df8773ff4fa2f9f384ca21f133
                [x-ua-compatible] => IE=Edge,chrome=1
                [set-cookie] => _secure_session_id=50f46da87f21f8a1b458baaf8e97a30a; path=/; secure; HttpOnly
                [x-runtime] => 0.307888
            )

        [response] => Array
            (
                [errors] => Error
            )

    )

[message:protected] => Internal Server Error
[string:Exception:private] => 
[code:protected] => 500
[file:protected] => /home/lolsmg/www/shopify_pinterest/shopify.php
[line:protected] => 32
[trace:Exception:private] => Array
    (
        [0] => Array
            (
                [file] => /home/lolsmg/www/shopify_pinterest/pintrest_ui.php
                [line] => 65
                [function] => {closure}
                [args] => Array
                    (
                        [0] => POST
                        [1] => /admin/custom_collections.json
                        [2] => Array
                            (
                                [custom_collection] => Array
                                    (
                                        [title] => ToddTest
                                        [collects] => Array
                                            (
                                                [product_id] => 96393246
                                            )

                                    )

                            )

                        [3] => Array
                            (
                                [http_status_message] => Internal Server Error
                                [http_status_code] => 500
                                [server] => nginx
                                [date] => Mon, 16 Jul 2012 23:23:45 GMT
                                [content-type] => application/json; charset=utf-8
                                [transfer-encoding] => chunked
                                [connection] => keep-alive
                                [status] => 500 Internal Server Error
                                [x-shopify-shop-api-call-limit] => 18/500
                                [http_x_shopify_shop_api_call_limit] => 18/500
                                [cache-control] => no-cache
                                [x-request-id] => f22337df8773ff4fa2f9f384ca21f133
                                [x-ua-compatible] => IE=Edge,chrome=1
                                [set-cookie] => _secure_session_id=50f46da87f21f8a1b458baaf8e97a30a; path=/; secure; HttpOnly
                                [x-runtime] => 0.307888
                            )

                    )

            )

    )

[previous:Exception:private] => 

) 我正在使用 shopfiy 提供的示例代码,但并没有走得太远。感谢您的帮助。

【问题讨论】:

    标签: php shopify


    【解决方案1】:

    检查日志,看起来“collects”属性实际上并未作为您在 $charge 变量中指定的数组发送。查找 request_id f22337df8773ff4fa2f9f384ca21f133 后,这是您发送的请求:

    {"custom_collection"=>{"title"=>"ToddTest", "collects"=>{"product_id"=>96393246}}}
    

    请求应该看起来像这样才能工作:

    {"custom_collection"=>{"title"=>"ToddTest", "collects"=>[{"product_id"=>96393246}]}}
    

    注意collects 是一个数组。

    【讨论】:

    • 对于那些仍在寻找这个问题的答案的人来说,这就是最终为我工作的方法:"custom_collection": { "title": "frontpagelist", "collects": [ {"product_id":0000000}, {"product_id":0000000}, {"product_id":0000000}, {"product_id":0000000} ] } }
    猜你喜欢
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多