2012-06-10 35 views
2

我正在使用Shopify PHP API。没有变音符号的产品工作正常,并被添加。当我试图发送带有捷克变音符号(ěščřžýáíé)产品,显示错误:Shopify PHP API:支持变音符号

Fatal error: Uncaught exception 'ShopifyApiException' with message 
'Unprocessable Entity' in C:\webdev\www\shopify-api-doporucene\shopify.php on line 32 

ShopifyApiException: Unprocessable Entity in C:\webdev\www\shopify-api-doporucene\shopify.php on line 32 

我在本地主机上使用WAMP。我试过json_encode,但它不起作用。有谁知道我该如何解决这个问题?

我的PHP代码(API密钥从这个例子中删除):

require 'shopify.php'; 

    $shops_myshopify_domain = "hyatt-ryan2200.myshopify.com"; 

    $api_key = ""; 

    $shared_secret = ""; 

    $shops_token = ""; 

    // For regular apps: 
    $shopify = shopify_api_client($shops_myshopify_domain, $shops_token, $api_key, $shared_secret); 

    $newproduct = array 
    ( 
     "product"=>array 
     ( 
      "title"=>"Product title (works fine without diacritics)", 
      "body_html"=>"Super Duper Plan", 
      "vendor"=>"Vendor", 
      "product_type"=>"Test" 
     ) 
    ); 

// All requests accept an optional fourth parameter, that is populated with the response headers. 
$senditem = $shopify('POST', '/admin/products.json', $newproduct, $response_headers); 
+0

您是否尝试修改'title'以在PHP中包含重音字符?我假设您的问题是产品名称来自AJAX操作 - 这可能会破坏您的UTF-8数据。另外检查一下,如果你的PHP文件中包含UTF8字符串,那么它将以UTF-8编码 - 请检查你的编辑器。 – halfer

+0

产品在PHP文件中(参见上面的$ newproduct)。 Ediotor设置为UTF-8。当我用记事本打开它并将它保存到UTF8时,有一些废话通过API发送到eShop:“Testovacu00ed zbou017eu00ed”(originalTestovacízboží“)。 – RadimH

+0

啊,它使用JSON进行服务器到服务器的通信。 'print_r($ newproduct)'并将其输出到浏览器(希望你也有一个UTF-8渲染!)以查看它是否看起来不错。在这个变量上使用'json_encode'实际上有什么区别? – halfer

回答

0

的前提:我从@Sarke的意见开始,所以这个问题将有答案。

您可以尝试

$newproduct = array 
    ( 
     "product"=>array 
     ( 
      "title"=>"Product title (with ot without diacritics)", 
      "body_html"=>"Super Duper Plan", 
      "vendor"=>"Vendor", 
      "product_type"=>"Test" 
     ) 
    ); 

foreach($newproduct["product"] as $k => $v){ 
    $newproduct["product"][$k] = iconv("UTF-8", "ISO-8859-2", $v); 
} 

创建与ISO-8859-2编码值,相干shopify服务器$新品展示阵列。

0

当你使用WAMP,尝试加入或改变php.ini文件是这样的:使用要解决检查终端到终端的

; PHP's default character set is set to empty. 
; http://php.net/default-charset 
default_charset = "utf-8" 

字符集问题,如果每一件事情使用相同的(UTF -8是shopify的情况)。重要:更改后重新加载WAMP。