echo66 Posted February 15, 2013 Share Posted February 15, 2013 Greetings, forum. I'm having a weird issue with the class PSWebServiceLibrary, when getting the product options. I have these two functions: function get_product_option($option_id) { try { $webService = new PrestaShopWebservice(prestashop_base_url, prestashop_api_product_options_key, false); $opt['resource'] = 'product_options'; $opt['id'] = $option_id; $xml = $webService->get($opt); $error = $xml->xpath('//error'); if (count($error)<1) { $option = $xml->product_option; return $option->asXML(); } else { return $error->asXML(); } } catch (PrestaShopWebserviceException $ex) { return $ex; } } function get_combination_labels($combination_id) { try { $webService = new PrestaShopWebservice(prestashop_base_url, prestashop_api_combinations_key, false); $lang_code = 7; $opt['resource'] = 'combinations'; $opt['id'] = $combination_id; $xml = $webService->get($opt); $error = $xml->xpath('//error'); if (count($error)<1) { $product_option_values = $xml->combination->associations->product_option_values; $res = ""; $res .= "<combination id='$combination_id'>\n"; foreach ($product_option_values->product_option_value as $value_reference) { $value_id = "{$value_reference->id}"; $value = get_product_option_value($value_id); $value = new SimpleXMLElement($value); $value = $value->xpath('//product_option_value'); $value = $value[0]; $value_label = $value->xpath("//name/language[@id=$lang_code]"); $value_label = (string) $value_label[0]; $option_id = (int)$value->id_attribute_group; $option = get_product_option($option_id); var_dump($option); $option = new SimpleXMLElement($option); $option_label = $option->xpath("//name/language[@id=$lang_code]"); $option_label = (string) $option_label[0]; $res .= "<product_option id='$option_id'>\n"; $res .= "<name>$option_label</name>\n"; $res .= "<value id='$value_id'>$value_label</value>\n"; $res .= "</product_option>\n"; } $res .= "</combination>"; return $res; } else { return $error->asXML(); } } catch (PrestaShopWebserviceException $ex) { return $ex; } } when i use the 1st one, for example, for the Disk Space (id:28) option, in the demo content that comes with prestashop, there is no problems. BUT, when i use the 2nd function, i get this error: object(PrestaShopWebserviceException)#8 (8) { ["message":protected]=> string(733) "HTTP XML response is not parsable : array ( 0 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 32, 'message' => 'Namespace prefix xlink for href on id_attribute_group is not defined ', 'file' => '', 'line' => 3, )), 1 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 31, 'message' => 'Namespace prefix xlink for href on language is not defined ', 'file' => '', 'line' => 6, )), 2 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 72, 'message' => 'Namespace prefix xlink for href on language is not defined ', 'file' => '', 'line' => 6, )), )" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(59) "/var/www/chamilo-1.9.2/main/inc/lib/PSWebServiceLibrary.php" ["line":protected]=> int(219) ["trace":"Exception":private]=> array(4) { [0]=> array(6) { ["file"]=> string(59) "/var/www/chamilo-1.9.2/main/inc/lib/PSWebServiceLibrary.php" ["line"]=> int(301) ["function"]=> string(8) "parseXML" ["class"]=> string(20) "PrestaShopWebservice" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(3) { ["status_code"]=> int(200) ["response"]=> string(2170) "<?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product_option> <id><![CDATA[1]]></id> <is_color_group><![CDATA[0]]></is_color_group> <group_type><![CDATA[select]]></group_type> <position><![CDATA[0]]></position> <name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></name> <public_name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></public_name> <associations> <product_option_values node_type="product_option_value"> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/1"> <id><![CDATA[1]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/2"> <id><![CDATA[2]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/8"> <id><![CDATA[8]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/9"> <id><![CDATA[9]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/12"> <id><![CDATA[12]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/13"> <id><![CDATA[13]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/15"> <id><![CDATA[15]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/16"> <id><![CDATA[16]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/17"> <id><![CDATA[17]]></id> </product_option_value> </product_option_values> </associations> </product_option> </prestashop> " ["header"]=> string(336) "HTTP/1.1 200 OK Date: Fri, 15 Feb 2013 01:04:58 GMT Server: Apache/2.2.22 (Ubuntu) Vary: Host,Accept-Encoding X-Powered-By: PrestaShop Webservice Access-Time: 1360890298 PSWS-Version: 1.5.3.1 Execution-Time: 0.068 Content-Sha1: ec7ae5b91425d6ae46c04828cc84aa05b16a3203 Content-Length: 2170 Content-Type: text/xml;charset=utf-8" } } } [1]=> array(6) { ["file"]=> string(54) "/var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php" ["line"]=> int(332) ["function"]=> string(3) "get" ["class"]=> string(20) "PrestaShopWebservice" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(2) { ["resource"]=> string(15) "product_options" ["id"]=> int(1) } } } [2]=> array(4) { ["file"]=> string(54) "/var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php" ["line"]=> int(288) ["function"]=> string(18) "get_product_option" ["args"]=> array(1) { [0]=> int(1) } } [3]=> array(4) { ["file"]=> string(52) "/var/www/chamilo-1.9.2/main/auth/shop_controller.php" ["line"]=> int(7) ["function"]=> string(22) "get_combination_labels" ["args"]=> array(1) { [0]=> &int(27) } } } ["previous":"Exception":private]=> NULL ["xdebug_message"]=> string(1397) " PrestaShopWebserviceException: HTTP XML response is not parsable : array ( 0 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 32, 'message' => 'Namespace prefix xlink for href on id_attribute_group is not defined ', 'file' => '', 'line' => 3, )), 1 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 31, 'message' => 'Namespace prefix xlink for href on language is not defined ', 'file' => '', 'line' => 6, )), 2 => LibXMLError::__set_state(array( 'level' => 2, 'code' => 201, 'column' => 72, 'message' => 'Namespace prefix xlink for href on language is not defined ', 'file' => '', 'line' => 6, )), ) in /var/www/chamilo-1.9.2/main/inc/lib/PSWebServiceLibrary.php on line 219 Call Stack: 0.0195 635656 1. {main}() /var/www/chamilo-1.9.2/main/auth/shop_controller.php:0 0.1617 3077448 2. get_combination_labels() /var/www/chamilo-1.9.2/main/auth/shop_controller.php:7 1.8083 3088296 3. get_product_option() /var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php:288 1.8084 3090656 4. PrestaShopWebservice->get() /var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php:332 1.9343 3100536 5. PrestaShopWebservice->parseXML() /var/www/chamilo-1.9.2/main/inc/lib/PSWebServiceLibrary.php:301 " } Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php on line 290 Exception: String could not be parsed as XML in /var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php on line 290 Call Stack: 0.0195 635656 1. {main}() /var/www/chamilo-1.9.2/main/auth/shop_controller.php:0 0.1617 3077448 2. get_combination_labels() /var/www/chamilo-1.9.2/main/auth/shop_controller.php:7 1.9773 3106456 3. SimpleXMLElement->__construct() /var/www/chamilo-1.9.2/main/inc/lib/shop_functions.php:290 Really, what the heck is wrong...? The "response" index contains the response body and, as far as i can see, there are no issues, neither in the code or the responses. This is the response for the first function: <product_option> <id><![CDATA[1]]></id> <is_color_group><![CDATA[0]]></is_color_group> <group_type><![CDATA[select]]></group_type> <position><![CDATA[0]]></position> <name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></name> <public_name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></public_name> <associations> <product_option_values node_type="product_option_value"> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/1"> <id><![CDATA[1]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/2"> <id><![CDATA[2]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/8"> <id><![CDATA[8]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/9"> <id><![CDATA[9]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/12"> <id><![CDATA[12]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/13"> <id><![CDATA[13]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/15"> <id><![CDATA[15]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/16"> <id><![CDATA[16]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/17"> <id><![CDATA[17]]></id> </product_option_value> </product_option_values> </associations> </product_option> and this is the response of the second function, that i get when i var dump the exception thrown within the call to get_product_option: <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product_option> <id><![CDATA[1]]></id> <is_color_group><![CDATA[0]]></is_color_group> <group_type><![CDATA[select]]></group_type> <position><![CDATA[0]]></position> <name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></name> <public_name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[Disk space]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[Disk space]]></language></public_name> <associations> <product_option_values node_type="product_option_value"> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/1"> <id><![CDATA[1]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/2"> <id><![CDATA[2]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/8"> <id><![CDATA[8]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/9"> <id><![CDATA[9]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/12"> <id><![CDATA[12]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/13"> <id><![CDATA[13]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/15"> <id><![CDATA[15]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/16"> <id><![CDATA[16]]></id> </product_option_value> <product_option_value xlink:href="http://localhost/prestashop/api/product_option_values/17"> <id><![CDATA[17]]></id> </product_option_value> </product_option_values> </associations> </product_option> </prestashop> the prestashop root element was, as you can see in the code of the 1st function, removed. Link to comment Share on other sites More sharing options...
echo66 Posted February 15, 2013 Author Share Posted February 15, 2013 oooohhhhhhh, waaaaait. The problem was about me taking the xmlns:xlink attribute declaration. Such a fool, god damn it. In order to use a namespace, i have to declare it. Damn noob ... Solved and closed 1 Link to comment Share on other sites More sharing options...
echo66 Posted February 15, 2013 Author Share Posted February 15, 2013 Seems that my impression was wrong or incomplete, about the error, because i'm still getting the same thing, even if i return the entire xml i got from the server, without removing the root node... Help...please? Link to comment Share on other sites More sharing options...
echo66 Posted February 17, 2013 Author Share Posted February 17, 2013 So, actually, i narrowed the potential issue to the parseXML function, in the PSWebService class. When i'm fetching the product option values, in the get_combination_labels function, i start to get errors after the first iteration, in the cycle. The errors are the same i posted...This time, it seems that its not my fault because, when i dump the response body, inside the parseXML function, i get the correct xml, for both requests, BUT, for some reason, i'm getting errors in the second response: <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product_option_value> <id><![CDATA[14]]></id> <id_attribute_group xlink:href="http://localhost/prestashop/api/product_options/2"><![CDATA[2]]></id_attribute_group> <color><![CDATA[#000000]]></color> <position><![CDATA[5]]></position> <name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[black]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[black]]></language></name> </product_option_value> </prestashop> array(0) { } <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product_option_value> <id><![CDATA[15]]></id> <id_attribute_group xlink:href="http://localhost/prestashop/api/product_options/1"><![CDATA[1]]></id_attribute_group> <color/> <position><![CDATA[6]]></position> <name><language id="1" xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[8GB]]></language><language id="7" xlink:href="http://localhost/prestashop/api/languages/7"><![CDATA[8GB]]></language></name> </product_option_value> </prestashop> array(3) { [0]=> object(LibXMLError)#10 (6) { ["level"]=> int(2) ["code"]=> int(201) ["column"]=> int(32) ["message"]=> string(69) "Namespace prefix xlink for href on id_attribute_group is not defined " ["file"]=> string(0) "" ["line"]=> int(3) } [1]=> object(LibXMLError)#14 (6) { ["level"]=> int(2) ["code"]=> int(201) ["column"]=> int(31) ["message"]=> string(59) "Namespace prefix xlink for href on language is not defined " ["file"]=> string(0) "" ["line"]=> int(6) } [2]=> object(LibXMLError)#13 (6) { ["level"]=> int(2) ["code"]=> int(201) ["column"]=> int(74) ["message"]=> string(59) "Namespace prefix xlink for href on language is not defined " ["file"]=> string(0) "" ["line"]=> int(6) } } Just compare both responses. Can you guys find any error, with your own eyes??? Because i can't... Link to comment Share on other sites More sharing options...
echo66 Posted February 17, 2013 Author Share Posted February 17, 2013 For now, i managed to avoid that error by requesting multiple option values in one request function get_product_option_values($value_ids) { try { $webService = new PrestaShopWebservice(prestashop_base_url, prestashop_api_product_option_values_key, false); $opt['resource'] = 'product_option_values'; $ids = "["; foreach ($value_ids as $id) { $ids .= "$id|"; } $ids .= "]"; $opt['filter[id]'] = $ids; $opt['display'] = 'full'; $xml = $webService->get($opt); $error = $xml->xpath('//error'); $values_arr = array(); if (count($error)<1) { foreach ($xml->product_option_values->product_option_value as $value) { $value_id = (int)$value->id; $values_arr[$value_id] = $value; } return $values_arr; } else { return $error->asXML(); } } catch (PrestaShopWebserviceException $ex) { return $ex; } } But that isn't an excuse to let this problem pass unnoticed. Why is it happening???? Link to comment Share on other sites More sharing options...
echo66 Posted February 17, 2013 Author Share Posted February 17, 2013 Is this issue so difficult to solve????? Because no one seems to answer, not even to say hello. This problem with the namespace errors seems to happend every time i make several requests, within a cycle. For every resource (as it seems), this problem exists. Link to comment Share on other sites More sharing options...
dandumit Posted February 16, 2014 Share Posted February 16, 2014 Hi, How did you made it work ? BR Daniel Link to comment Share on other sites More sharing options...
Prestacampus Posted February 17, 2015 Share Posted February 17, 2015 looks one should avoid to make several xml request in the same file. i have no pb creating a product on PS1.6 but in PS1.4 it's not trivial you are ok as long as you do not make more than 2 requests in the same file. sadly PS1.4 is bound to disappear don't expect much support even on this forum. Link to comment Share on other sites More sharing options...
Recommended Posts