我正在尝试使用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] =>
)
答案 0 :(得分:0)
我得到了它的工作
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